1111
1212namespace PhpCsFixerCustomFixers \Fixer ;
1313
14+ use PhpCsFixer \Fixer \DeprecatedFixerInterface ;
15+ use PhpCsFixer \Fixer \PhpUnit \PhpUnitDataProviderReturnTypeFixer ;
1416use PhpCsFixer \FixerDefinition \CodeSample ;
1517use PhpCsFixer \FixerDefinition \FixerDefinition ;
1618use PhpCsFixer \FixerDefinition \FixerDefinitionInterface ;
17- use PhpCsFixer \Indicator \PhpUnitTestCaseIndicator ;
18- use PhpCsFixer \Tokenizer \Analyzer \FunctionsAnalyzer ;
19- use PhpCsFixer \Tokenizer \CT ;
20- use PhpCsFixer \Tokenizer \Token ;
2119use PhpCsFixer \Tokenizer \Tokens ;
22- use PhpCsFixerCustomFixers \Analyzer \DataProviderAnalyzer ;
2320
24- final class DataProviderReturnTypeFixer extends AbstractFixer
21+ /**
22+ * @deprecated
23+ */
24+ final class DataProviderReturnTypeFixer extends AbstractFixer implements DeprecatedFixerInterface
2525{
26+ private PhpUnitDataProviderReturnTypeFixer $ phpUnitDataProviderReturnTypeFixer ;
27+
28+ public function __construct ()
29+ {
30+ $ this ->phpUnitDataProviderReturnTypeFixer = new PhpUnitDataProviderReturnTypeFixer ();
31+ }
32+
2633 public function getDefinition (): FixerDefinitionInterface
2734 {
2835 return new FixerDefinition (
29- ' The types returned by data providers must be `iterable`. ' ,
36+ $ this -> phpUnitDataProviderReturnTypeFixer -> getDefinition ()-> getSummary () ,
3037 [
3138 new CodeSample (
3239 '<?php
@@ -50,57 +57,29 @@ public function provideSomethingCases(): array {}
5057 */
5158 public function getPriority (): int
5259 {
53- return 0 ;
60+ return $ this -> phpUnitDataProviderReturnTypeFixer -> getPriority () ;
5461 }
5562
5663 public function isCandidate (Tokens $ tokens ): bool
5764 {
58- return $ tokens -> isAllTokenKindsFound ([\ T_CLASS , \ T_DOC_COMMENT , \ T_EXTENDS , \ T_FUNCTION , \ T_STRING ] );
65+ return $ this -> phpUnitDataProviderReturnTypeFixer -> isCandidate ( $ tokens );
5966 }
6067
6168 public function isRisky (): bool
6269 {
63- return true ;
70+ return $ this -> phpUnitDataProviderReturnTypeFixer -> isRisky () ;
6471 }
6572
6673 public function fix (\SplFileInfo $ file , Tokens $ tokens ): void
6774 {
68- $ phpUnitTestCaseIndicator = new PhpUnitTestCaseIndicator ();
69-
70- /** @var array<int> $indices */
71- foreach ($ phpUnitTestCaseIndicator ->findPhpUnitClasses ($ tokens ) as $ indices ) {
72- $ this ->fixReturnTypes ($ tokens , $ indices [0 ], $ indices [1 ]);
73- }
75+ $ this ->phpUnitDataProviderReturnTypeFixer ->fix ($ file , $ tokens );
7476 }
7577
76- private function fixReturnTypes (Tokens $ tokens , int $ startIndex , int $ endIndex ): void
78+ /**
79+ * @return array<string>
80+ */
81+ public function getSuccessorsNames (): array
7782 {
78- $ dataProviderAnalyzer = new DataProviderAnalyzer ();
79- $ functionsAnalyzer = new FunctionsAnalyzer ();
80-
81- foreach (\array_reverse ($ dataProviderAnalyzer ->getDataProviders ($ tokens , $ startIndex , $ endIndex )) as $ dataProviderAnalysis ) {
82- $ typeAnalysis = $ functionsAnalyzer ->getFunctionReturnType ($ tokens , $ dataProviderAnalysis ->getNameIndex ());
83-
84- if ($ typeAnalysis === null ) {
85- $ argumentsStart = $ tokens ->getNextTokenOfKind ($ dataProviderAnalysis ->getNameIndex (), ['( ' ]);
86- \assert (\is_int ($ argumentsStart ));
87- $ argumentsEnd = $ tokens ->findBlockEnd (Tokens::BLOCK_TYPE_PARENTHESIS_BRACE , $ argumentsStart );
88- $ tokens ->insertAt (
89- $ argumentsEnd + 1 ,
90- [
91- new Token ([CT ::T_TYPE_COLON , ': ' ]),
92- new Token ([\T_WHITESPACE , ' ' ]),
93- new Token ([\T_STRING , 'iterable ' ]),
94- ],
95- );
96- continue ;
97- }
98-
99- if ($ typeAnalysis ->getName () !== 'iterable ' ) {
100- $ startIndex = $ tokens ->getNextMeaningfulToken ($ typeAnalysis ->getStartIndex () - 1 );
101- \assert (\is_int ($ startIndex ));
102- $ tokens ->overrideRange ($ startIndex , $ typeAnalysis ->getEndIndex (), [new Token ([\T_STRING , 'iterable ' ])]);
103- }
104- }
83+ return [$ this ->phpUnitDataProviderReturnTypeFixer ->getName ()];
10584 }
10685}
0 commit comments