1313
1414namespace PhpCsFixerCustomFixers \Fixer ;
1515
16+ use PhpCsFixer \Fixer \DeprecatedFixerInterface ;
1617use PhpCsFixer \FixerDefinition \CodeSample ;
1718use PhpCsFixer \FixerDefinition \FixerDefinition ;
1819use PhpCsFixer \FixerDefinition \FixerDefinitionInterface ;
19- use PhpCsFixer \Tokenizer \Analyzer \ArgumentsAnalyzer ;
20- use PhpCsFixer \Tokenizer \Analyzer \FunctionsAnalyzer ;
21- use PhpCsFixer \Tokenizer \Token ;
2220use PhpCsFixer \Tokenizer \Tokens ;
2321
24- final class NoUselessSprintfFixer extends AbstractFixer
22+ /**
23+ * @deprecated
24+ */
25+ final class NoUselessSprintfFixer extends AbstractFixer implements DeprecatedFixerInterface
2526{
27+ /** @var \PhpCsFixer\Fixer\FunctionNotation\NoUselessSprintfFixer */
28+ private $ fixer ;
29+
30+ public function __construct ()
31+ {
32+ $ this ->fixer = new \PhpCsFixer \Fixer \FunctionNotation \NoUselessSprintfFixer ();
33+ }
34+
2635 public function getDefinition (): FixerDefinitionInterface
2736 {
2837 return new FixerDefinition (
@@ -35,79 +44,29 @@ public function getDefinition(): FixerDefinitionInterface
3544
3645 public function getPriority (): int
3746 {
38- return 0 ;
47+ return $ this -> fixer -> getPriority () ;
3948 }
4049
4150 public function isCandidate (Tokens $ tokens ): bool
4251 {
43- return $ tokens -> isTokenKindFound ( T_STRING );
52+ return $ this -> fixer -> isCandidate ( $ tokens );
4453 }
4554
4655 public function isRisky (): bool
4756 {
48- return true ;
57+ return $ this -> fixer -> isRisky () ;
4958 }
5059
5160 public function fix (\SplFileInfo $ file , Tokens $ tokens ): void
5261 {
53- $ argumentsAnalyzer = new ArgumentsAnalyzer ();
54- $ functionsAnalyzer = new FunctionsAnalyzer ();
55-
56- for ($ index = $ tokens ->count () - 1 ; $ index > 0 ; $ index --) {
57- /** @var Token $token */
58- $ token = $ tokens [$ index ];
59-
60- if (!$ token ->equals ([T_STRING , 'sprintf ' ], false )) {
61- continue ;
62- }
63-
64- if (!$ functionsAnalyzer ->isGlobalFunctionCall ($ tokens , $ index )) {
65- continue ;
66- }
67-
68- /** @var int $openParenthesisIndex */
69- $ openParenthesisIndex = $ tokens ->getNextTokenOfKind ($ index , ['( ' ]);
70-
71- $ closeParenthesisIndex = $ tokens ->findBlockEnd (Tokens::BLOCK_TYPE_PARENTHESIS_BRACE , $ openParenthesisIndex );
72-
73- if ($ argumentsAnalyzer ->countArguments ($ tokens , $ openParenthesisIndex , $ closeParenthesisIndex ) !== 1 ) {
74- continue ;
75- }
76-
77- /** @var int $afterOpenParenthesisIndex */
78- $ afterOpenParenthesisIndex = $ tokens ->getNextMeaningfulToken ($ openParenthesisIndex );
79-
80- /** @var Token $afterOpenParenthesisToken */
81- $ afterOpenParenthesisToken = $ tokens [$ afterOpenParenthesisIndex ];
82-
83- if ($ afterOpenParenthesisToken ->isGivenKind (T_ELLIPSIS )) {
84- continue ;
85- }
86-
87- /** @var int $prevIndex */
88- $ prevIndex = $ tokens ->getPrevMeaningfulToken ($ index );
89-
90- /** @var Token $prevToken */
91- $ prevToken = $ tokens [$ prevIndex ];
92-
93- if ($ prevToken ->isGivenKind (T_NS_SEPARATOR )) {
94- $ this ->removeTokenAndSiblingWhitespace ($ tokens , $ prevIndex , 1 );
95- }
96- $ this ->removeTokenAndSiblingWhitespace ($ tokens , $ index , 1 );
97- $ this ->removeTokenAndSiblingWhitespace ($ tokens , $ openParenthesisIndex , 1 );
98- $ this ->removeTokenAndSiblingWhitespace ($ tokens , $ closeParenthesisIndex , -1 );
99- }
62+ $ this ->fixer ->fix ($ file , $ tokens );
10063 }
10164
102- private function removeTokenAndSiblingWhitespace (Tokens $ tokens , int $ index , int $ direction ): void
65+ /**
66+ * @return string[]
67+ */
68+ public function getSuccessorsNames (): array
10369 {
104- $ tokens ->clearAt ($ index );
105-
106- /** @var Token $siblingToken */
107- $ siblingToken = $ tokens [$ index + $ direction ];
108-
109- if ($ siblingToken ->isWhitespace ()) {
110- $ tokens ->clearAt ($ index + $ direction );
111- }
70+ return [$ this ->fixer ->getName ()];
11271 }
11372}
0 commit comments