Skip to content

Commit ec9776e

Browse files
authored
NoUselessCommentFixer - fix for anonymous classes (#1105)
1 parent 973fc24 commit ec9776e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/Fixer/NoUselessCommentFixer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ private static function getNewContent(Tokens $tokens, int $index): string
101101
$classyNameIndex = $tokens->getNextMeaningfulToken($nextIndex);
102102
\assert(\is_int($classyNameIndex));
103103

104+
if (!$tokens[$classyNameIndex]->isGivenKind(\T_STRING)) {
105+
return $content;
106+
}
107+
104108
$content = Preg::replace(
105109
\sprintf('~
106110
\\R?

tests/Fixer/NoUselessCommentFixerTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,5 +464,11 @@ class Bar {}
464464
// foo
465465
',
466466
];
467+
468+
yield [
469+
'<?php
470+
$a = new /** ( */ class () {};
471+
',
472+
];
467473
}
468474
}

0 commit comments

Comments
 (0)