14
14
15
15
namespace PhpCsFixer \Fixer \ArrayNotation ;
16
16
17
- use PhpCsFixer \AbstractFixer ;
17
+ use PhpCsFixer \AbstractProxyFixer ;
18
+ use PhpCsFixer \Fixer \Basic \NoTrailingCommaInSinglelineFixer ;
19
+ use PhpCsFixer \Fixer \DeprecatedFixerInterface ;
18
20
use PhpCsFixer \FixerDefinition \CodeSample ;
19
21
use PhpCsFixer \FixerDefinition \FixerDefinition ;
20
22
use PhpCsFixer \FixerDefinition \FixerDefinitionInterface ;
21
- use PhpCsFixer \Tokenizer \CT ;
22
- use PhpCsFixer \Tokenizer \Tokens ;
23
- use PhpCsFixer \Tokenizer \TokensAnalyzer ;
24
23
25
24
/**
25
+ * @deprecated
26
+ *
26
27
* @author Dariusz Rumiński <[email protected] >
27
28
* @author Sebastiaan Stok <[email protected] >
28
29
*/
29
- final class NoTrailingCommaInSinglelineArrayFixer extends AbstractFixer
30
+ final class NoTrailingCommaInSinglelineArrayFixer extends AbstractProxyFixer implements DeprecatedFixerInterface
30
31
{
31
32
/**
32
33
* {@inheritdoc}
@@ -42,48 +43,19 @@ public function getDefinition(): FixerDefinitionInterface
42
43
/**
43
44
* {@inheritdoc}
44
45
*/
45
- public function isCandidate ( Tokens $ tokens ): bool
46
+ public function getSuccessorsNames ( ): array
46
47
{
47
- return $ tokens -> isAnyTokenKindsFound ([ T_ARRAY , CT :: T_ARRAY_SQUARE_BRACE_OPEN ] );
48
+ return array_keys ( $ this -> proxyFixers );
48
49
}
49
50
50
51
/**
51
52
* {@inheritdoc}
52
53
*/
53
- protected function applyFix (\SplFileInfo $ file , Tokens $ tokens ): void
54
- {
55
- $ tokensAnalyzer = new TokensAnalyzer ($ tokens );
56
-
57
- for ($ index = 0 , $ c = $ tokens ->count (); $ index < $ c ; ++$ index ) {
58
- if ($ tokensAnalyzer ->isArray ($ index )) {
59
- $ this ->fixArray ($ tokens , $ index );
60
- }
61
- }
62
- }
63
-
64
- private function fixArray (Tokens $ tokens , int $ index ): void
54
+ protected function createProxyFixers (): array
65
55
{
66
- $ tokensAnalyzer = new TokensAnalyzer ($ tokens );
67
-
68
- if ($ tokensAnalyzer ->isArrayMultiLine ($ index )) {
69
- return ;
70
- }
71
-
72
- $ startIndex = $ index ;
73
-
74
- if ($ tokens [$ startIndex ]->isGivenKind (T_ARRAY )) {
75
- $ startIndex = $ tokens ->getNextTokenOfKind ($ startIndex , ['( ' ]);
76
- $ endIndex = $ tokens ->findBlockEnd (Tokens::BLOCK_TYPE_PARENTHESIS_BRACE , $ startIndex );
77
- } else {
78
- $ endIndex = $ tokens ->findBlockEnd (Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE , $ startIndex );
79
- }
80
-
81
- $ beforeEndIndex = $ tokens ->getPrevMeaningfulToken ($ endIndex );
82
- $ beforeEndToken = $ tokens [$ beforeEndIndex ];
56
+ $ fixer = new NoTrailingCommaInSinglelineFixer ();
57
+ $ fixer ->configure (['elements ' => ['array ' ]]);
83
58
84
- if ($ beforeEndToken ->equals (', ' )) {
85
- $ tokens ->removeTrailingWhitespace ($ beforeEndIndex );
86
- $ tokens ->clearAt ($ beforeEndIndex );
87
- }
59
+ return [$ fixer ];
88
60
}
89
61
}
0 commit comments