44
55namespace PhpCsFixerCustomFixers \Fixer ;
66
7+ use PhpCsFixer \Fixer \DeprecatedFixerInterface ;
78use PhpCsFixer \FixerDefinition \CodeSample ;
89use PhpCsFixer \FixerDefinition \FixerDefinition ;
9- use PhpCsFixer \Preg ;
10- use PhpCsFixer \Tokenizer \Token ;
1110use PhpCsFixer \Tokenizer \Tokens ;
1211
13- final class NoUselessClassCommentFixer extends AbstractFixer
12+ /**
13+ * @deprecated use NoUselessCommentFixer instead
14+ */
15+ final class NoUselessClassCommentFixer extends AbstractFixer implements DeprecatedFixerInterface
1416{
17+ /** @var NoUselessCommentFixer */
18+ private $ fixer ;
19+
20+ public function __construct ()
21+ {
22+ $ this ->fixer = new NoUselessCommentFixer ();
23+ }
24+
1525 public function getDefinition (): FixerDefinition
1626 {
1727 return new FixerDefinition (
@@ -28,48 +38,29 @@ class FooBar {}
2838
2939 public function isCandidate (Tokens $ tokens ): bool
3040 {
31- return $ tokens -> isAnyTokenKindsFound ([ T_COMMENT , T_DOC_COMMENT ] );
41+ return $ this -> fixer -> isCandidate ( $ tokens );
3242 }
3343
3444 public function isRisky (): bool
3545 {
36- return false ;
46+ return $ this -> fixer -> isRisky () ;
3747 }
3848
3949 public function fix (\SplFileInfo $ file , Tokens $ tokens ): void
4050 {
41- foreach ($ tokens as $ index => $ token ) {
42- if (!$ token ->isGivenKind ([T_COMMENT , T_DOC_COMMENT ])) {
43- continue ;
44- }
45-
46- if (\strpos ($ token ->getContent (), 'Class ' ) === false ) {
47- continue ;
48- }
49-
50- $ nextIndex = $ tokens ->getNextMeaningfulToken ($ index );
51- if ($ nextIndex === null || !$ tokens [$ nextIndex ]->isGivenKind ([T_ABSTRACT , T_CLASS , T_FINAL ])) {
52- continue ;
53- }
54-
55- $ newContent = Preg::replace (
56- '/(\*)?\h*\bClass\h+[A-Za-z0-1 \\\\_]+\.?(\h*\R\h*|\h*$)/i ' ,
57- '' ,
58- $ token ->getContent ()
59- );
60-
61- if ($ newContent === $ token ->getContent ()) {
62- continue ;
63- }
64-
65- $ tokens [$ index ] = new Token ([$ token ->getId (), $ newContent ]);
66- }
51+ $ this ->fixer ->fix ($ file , $ tokens );
6752 }
6853
6954 public function getPriority (): int
7055 {
71- // must be run before NoEmptyPhpdocFixer, NoEmptyCommentFixer
72- // PhpdocSeparationFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer and PhpdocTrimFixer
73- return 6 ;
56+ return $ this ->fixer ->getPriority ();
57+ }
58+
59+ /**
60+ * @return string[]
61+ */
62+ public function getSuccessorsNames (): array
63+ {
64+ return [(new \ReflectionObject ($ this ->fixer ))->getShortName ()];
7465 }
7566}
0 commit comments