Browse Source

PhpdocLineSpanFixer - do not crash on trait imports

SpacePossum 3 years ago
parent
commit
d60ff679f7

+ 5 - 0
src/Fixer/Phpdoc/PhpdocLineSpanFixer.php

@@ -102,6 +102,11 @@ final class PhpdocLineSpanFixer extends AbstractFixer implements WhitespacesAwar
             }
 
             $type = $element['type'];
+
+            if (!isset($this->configuration[$type])) {
+                continue;
+            }
+
             $docIndex = $this->getDocBlockIndex($tokens, $index);
             $doc = new DocBlock($tokens[$docIndex]->getContent());
 

+ 11 - 1
tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php

@@ -473,11 +473,16 @@ class Foo
                     'const' => null,
                 ],
             ],
-            'It can handle constants with visibility' => [
+            'It can handle constants with visibility, does not crash on trait imports' => [
                 '<?php
+trait Bar
+{}
 
 class Foo
 {
+    /** whatever */
+    use Bar;
+
     /**
      *
      */
@@ -487,9 +492,14 @@ class Foo
     private $foo;
 }',
                 '<?php
+trait Bar
+{}
 
 class Foo
 {
+    /** whatever */
+    use Bar;
+
     /**  */
     public const FOO = "foobar";