|
4 | 4 |
|
5 | 5 | namespace PhpCsFixerCustomFixers\Fixer; |
6 | 6 |
|
7 | | -use PhpCsFixer\FixerDefinition\CodeSample; |
| 7 | +use PhpCsFixer\Fixer\DeprecatedFixerInterface; |
8 | 8 | use PhpCsFixer\FixerDefinition\FixerDefinition; |
9 | | -use PhpCsFixer\Preg; |
10 | | -use PhpCsFixer\Tokenizer\Token; |
11 | 9 | use PhpCsFixer\Tokenizer\Tokens; |
12 | 10 |
|
13 | | -final class PhpdocVarAnnotationCorrectOrderFixer extends AbstractFixer implements DeprecatingFixerInterface |
| 11 | +/** |
| 12 | + * @deprecated use "phpdoc_var_annotation_correct_order" instead |
| 13 | + */ |
| 14 | +final class PhpdocVarAnnotationCorrectOrderFixer extends AbstractFixer implements DeprecatedFixerInterface |
14 | 15 | { |
| 16 | + /** @var \PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer */ |
| 17 | + private $fixer; |
| 18 | + |
| 19 | + public function __construct() |
| 20 | + { |
| 21 | + $this->fixer = new \PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer(); |
| 22 | + } |
| 23 | + |
15 | 24 | public function getDefinition(): FixerDefinition |
16 | 25 | { |
17 | | - return new FixerDefinition( |
18 | | - '`@var` annotation must have type and name in the correct order.', |
19 | | - [new CodeSample('<?php |
20 | | -/** @var $foo int */ |
21 | | -$foo = 2 + 2; |
22 | | -')] |
23 | | - ); |
| 26 | + return $this->fixer->getDefinition(); |
24 | 27 | } |
25 | 28 |
|
26 | 29 | public function isCandidate(Tokens $tokens): bool |
27 | 30 | { |
28 | | - return $tokens->isTokenKindFound(T_DOC_COMMENT); |
| 31 | + return $this->fixer->isCandidate($tokens); |
29 | 32 | } |
30 | 33 |
|
31 | 34 | public function isRisky(): bool |
32 | 35 | { |
33 | | - return false; |
| 36 | + return $this->fixer->isRisky(); |
34 | 37 | } |
35 | 38 |
|
36 | 39 | public function fix(\SplFileInfo $file, Tokens $tokens): void |
37 | 40 | { |
38 | | - foreach ($tokens as $index => $token) { |
39 | | - if (!$token->isGivenKind(T_DOC_COMMENT)) { |
40 | | - continue; |
41 | | - } |
42 | | - |
43 | | - if (\stripos($token->getContent(), '@var') === false) { |
44 | | - continue; |
45 | | - } |
46 | | - |
47 | | - $newContent = Preg::replace( |
48 | | - '/(@var\s*)(\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)(\s+)([^\$](?:[^<\s]|<[^>]*>)*)(\s|\*)/i', |
49 | | - '$1$4$3$2$5', |
50 | | - $token->getContent() |
51 | | - ); |
52 | | - |
53 | | - if ($newContent === $token->getContent()) { |
54 | | - continue; |
55 | | - } |
56 | | - |
57 | | - $tokens[$index] = new Token([$token->getId(), $newContent]); |
58 | | - } |
| 41 | + $this->fixer->fix($file, $tokens); |
59 | 42 | } |
60 | 43 |
|
61 | 44 | public function getPriority(): int |
62 | 45 | { |
63 | | - // must be before PhpdocNoIncorrectVarAnnotationFixer |
64 | | - return 7; |
| 46 | + return $this->fixer->getPriority(); |
65 | 47 | } |
66 | 48 |
|
67 | | - public function getPullRequestId(): int |
| 49 | + /** |
| 50 | + * @return string[] |
| 51 | + */ |
| 52 | + public function getSuccessorsNames(): array |
68 | 53 | { |
69 | | - return 3881; |
| 54 | + return [$this->fixer->getName()]; |
70 | 55 | } |
71 | 56 | } |
0 commit comments