Skip to content

Commit

Permalink
PhpdocLineSpanFixer - do not crash on trait imports
Browse files Browse the repository at this point in the history
  • Loading branch information
SpacePossum committed Sep 28, 2021
1 parent c1a4a91 commit d60ff67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Fixer/Phpdoc/PhpdocLineSpanFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void
}

$type = $element['type'];

if (!isset($this->configuration[$type])) {
continue;
}

$docIndex = $this->getDocBlockIndex($tokens, $index);
$doc = new DocBlock($tokens[$docIndex]->getContent());

Expand Down
12 changes: 11 additions & 1 deletion tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/**
*
*/
Expand All @@ -487,9 +492,14 @@ class Foo
private $foo;
}',
'<?php
trait Bar
{}
class Foo
{
/** whatever */
use Bar;
/** */
public const FOO = "foobar";
Expand Down

0 comments on commit d60ff67

Please sign in to comment.