From 1aea0fd06fc87b1f53d5549933343f51e4e921dd Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Thu, 5 Aug 2021 14:06:08 +0200 Subject: [PATCH 01/80] BracesFixer - handle alternative short foreach with if --- src/Fixer/Basic/BracesFixer.php | 6 +++--- tests/Fixer/Basic/BracesFixerTest.php | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index 82c4fd4c2cd..312d6a6bec0 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -659,9 +659,9 @@ private function fixMissingControlBraces(Tokens $tokens): void continue; } - // do not add for short 'if' followed by alternative loop, - // for example: if ($a) while ($b): ? > X < ?php endwhile; ? > - if ($tokenAfterParenthesis->isGivenKind([T_FOR, T_FOREACH, T_SWITCH, T_WHILE])) { + // do not add for 'short if' followed by alternative loop, for example: if ($a) while ($b): ? > X < ?php endwhile; ? > + // or 'short if' after an alternative loop, for example: foreach ($arr as $index => $item) if ($item): + if ($tokenAfterParenthesis->isGivenKind([T_FOR, T_FOREACH, T_SWITCH, T_WHILE, T_IF])) { $tokenAfterParenthesisBlockEnd = $tokens->findBlockEnd( // go to ')' Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextMeaningfulToken($nextAfterParenthesisEndIndex) diff --git a/tests/Fixer/Basic/BracesFixerTest.php b/tests/Fixer/Basic/BracesFixerTest.php index fe0ef98e16c..3e9b21848b0 100644 --- a/tests/Fixer/Basic/BracesFixerTest.php +++ b/tests/Fixer/Basic/BracesFixerTest.php @@ -789,6 +789,12 @@ public function bar() { ', ], + [ + ' + $item) if ($item): ?> + +', + ], ]; } From 36186298da03a97935cd50c3718c96c0154af470 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Fri, 13 Aug 2021 17:22:25 +0200 Subject: [PATCH 02/80] AttributeTransformerTest - add more tests --- .../Transformer/AttributeTransformerTest.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/tests/Tokenizer/Transformer/AttributeTransformerTest.php b/tests/Tokenizer/Transformer/AttributeTransformerTest.php index 190d16d55c1..a60507e6ead 100644 --- a/tests/Tokenizer/Transformer/AttributeTransformerTest.php +++ b/tests/Tokenizer/Transformer/AttributeTransformerTest.php @@ -63,6 +63,113 @@ public function provideProcessCases() 16 => CT::T_ATTRIBUTE_CLOSE, ], ]; + + yield [ + ' "The email {{ value }} is not a valid email."])] + private $email; + }', + [ + 21 => CT::T_ATTRIBUTE_CLOSE, + 36 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; + + yield [ + '>9+foo(a)+foo((bool)$b))] // gets removed from AST when >= 7.0 +#[IgnoreRedeclaration] // throws no error when already declared, removes the redeclared thing +function intdiv(int $numerator, int $divisor) { +} + +#[ +Attr1("foo"),Attr2("bar"), +] + +#[PhpAttribute(self::IS_REPEATABLE)] +class Route +{ +} +', + [ + 5 => CT::T_ATTRIBUTE_CLOSE, + 35 => CT::T_ATTRIBUTE_CLOSE, + 41 => CT::T_ATTRIBUTE_CLOSE, + 76 => CT::T_ATTRIBUTE_CLOSE, + 85 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; + + yield [ + ' 1; +', + [ + 3 => CT::T_ATTRIBUTE_CLOSE, + 22 => CT::T_ATTRIBUTE_CLOSE, + 37 => CT::T_ATTRIBUTE_CLOSE, + 47 => CT::T_ATTRIBUTE_CLOSE, + 67 => CT::T_ATTRIBUTE_CLOSE, + 84 => CT::T_ATTRIBUTE_CLOSE, + 101 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; + + yield [ + ' "The email \'{{ value }}\' is not a valid email."])] + private $email; + + #[\Doctrine\ORM\ManyToMany( + targetEntity: User::class, + joinColumn: "group_id", + inverseJoinColumn: "user_id", + cascade: array("persist", "remove") + )] + #[Assert\Valid] + #[JMSSerializer\XmlList(inline: true, entry: "user")] + public $users; +} +', + [ + 15 => CT::T_ATTRIBUTE_CLOSE, + 40 => CT::T_ATTRIBUTE_CLOSE, + 61 => CT::T_ATTRIBUTE_CLOSE, + 76 => CT::T_ATTRIBUTE_CLOSE, + 124 => CT::T_ATTRIBUTE_CLOSE, + 130 => CT::T_ATTRIBUTE_CLOSE, + 148 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; } /** From 4d84a839b7d1c7cc10cdc240c7dc7550e2ba487f Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Fri, 13 Aug 2021 18:51:23 +0200 Subject: [PATCH 03/80] ClassDefinitionFixer - PSR12 for anonymous class --- doc/rules/class_notation/class_definition.rst | 23 ++++++++ .../ClassNotation/ClassDefinitionFixer.php | 58 ++++++++++++++----- .../ClassDefinitionFixerTest.php | 20 ++++++- 3 files changed, 85 insertions(+), 16 deletions(-) diff --git a/doc/rules/class_notation/class_definition.rst b/doc/rules/class_notation/class_definition.rst index f9a50bdd67f..a436af6daf4 100644 --- a/doc/rules/class_notation/class_definition.rst +++ b/doc/rules/class_notation/class_definition.rst @@ -35,6 +35,16 @@ Allowed types: ``bool`` Default value: ``false`` +``space_before_parenthesis`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Whether there should be a single space after the parenthesis of anonymous class +(PSR12) or not. + +Allowed types: ``bool`` + +Default value: ``false`` + Examples -------- @@ -130,6 +140,19 @@ With configuration: ``['multi_line_extends_each_single_line' => true]``. + FooBarBaz {} +Example #6 +~~~~~~~~~~ + +With configuration: ``['space_before_parenthesis' => true]``. + +.. code-block:: diff + + --- Original + +++ New + true] ), + new CodeSample( + ' true] + ), ] ); } @@ -149,6 +155,10 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->setAllowedTypes(['bool']) ->setDefault(false) ->getOption(), + (new FixerOptionBuilder('space_before_parenthesis', 'Whether there should be a single space after the parenthesis of anonymous class (PSR12) or not.')) + ->setAllowedTypes(['bool']) + ->setDefault(false) + ->getOption(), ]); } @@ -182,6 +192,7 @@ private function fixClassyDefinition(Tokens $tokens, int $classyIndex): void // PSR12: anonymous class curly brace on same line if not multi line implements. $classDefInfo['open'] = $this->fixClassyDefinitionOpenSpacing($tokens, $classDefInfo); + if ($classDefInfo['implements']) { $end = $classDefInfo['implements']['start']; } elseif ($classDefInfo['extends']) { @@ -191,11 +202,7 @@ private function fixClassyDefinition(Tokens $tokens, int $classyIndex): void } // 4.1 The extends and implements keywords MUST be declared on the same line as the class name. - $this->makeClassyDefinitionSingleLine( - $tokens, - $classDefInfo['anonymousClass'] ? $tokens->getPrevMeaningfulToken($classyIndex) : $classDefInfo['start'], - $end - ); + $this->makeClassyDefinitionSingleLine($tokens, $classDefInfo['start'], $end); } private function fixClassyDefinitionExtends(Tokens $tokens, int $classOpenIndex, array $classExtendsInfo): array @@ -249,6 +256,7 @@ private function fixClassyDefinitionOpenSpacing(Tokens $tokens, array $classDefI } $openIndex = $tokens->getNextTokenOfKind($classDefInfo['classy'], ['{']); + if (' ' !== $spacing && false !== strpos($tokens[$openIndex - 1]->getContent(), "\n")) { return $openIndex; } @@ -269,9 +277,6 @@ private function fixClassyDefinitionOpenSpacing(Tokens $tokens, array $classDefI private function getClassyDefinitionInfo(Tokens $tokens, int $classyIndex): array { $openIndex = $tokens->getNextTokenOfKind($classyIndex, ['{']); - $prev = $tokens->getPrevMeaningfulToken($classyIndex); - $startIndex = $tokens[$prev]->isGivenKind([T_FINAL, T_ABSTRACT]) ? $prev : $classyIndex; - $extends = false; $implements = false; $anonymousClass = false; @@ -288,6 +293,13 @@ private function getClassyDefinitionInfo(Tokens $tokens, int $classyIndex): arra } } + if ($anonymousClass) { + $startIndex = $tokens->getPrevMeaningfulToken($classyIndex); // go to "new" for anonymous class + } else { + $prev = $tokens->getPrevMeaningfulToken($classyIndex); + $startIndex = $tokens[$prev]->isGivenKind([T_FINAL, T_ABSTRACT]) ? $prev : $classyIndex; + } + return [ 'start' => $startIndex, 'classy' => $classyIndex, @@ -304,6 +316,7 @@ private function getClassyInheritanceInfo(Tokens $tokens, int $startIndex, strin ++$startIndex; $endIndex = $tokens->getNextTokenOfKind($startIndex, ['{', [T_IMPLEMENTS], [T_EXTENDS]]); $endIndex = $tokens[$endIndex]->equals('{') ? $tokens->getPrevNonWhitespace($endIndex) : $endIndex; + for ($i = $startIndex; $i < $endIndex; ++$i) { if ($tokens[$i]->equals(',')) { ++$implementsInfo[$label]; @@ -323,13 +336,12 @@ private function makeClassyDefinitionSingleLine(Tokens $tokens, int $startIndex, { for ($i = $endIndex; $i >= $startIndex; --$i) { if ($tokens[$i]->isWhitespace()) { - $prevNonWhite = $tokens->getPrevNonWhitespace($i); - $nextNonWhite = $tokens->getNextNonWhitespace($i); + if ($tokens[$i - 1]->isComment() || $tokens[$i + 1]->isComment()) { + $content = $tokens[$i - 1]->getContent(); - if ($tokens[$prevNonWhite]->isComment() || $tokens[$nextNonWhite]->isComment()) { - $content = $tokens[$prevNonWhite]->getContent(); if (!('#' === $content || '//' === substr($content, 0, 2))) { - $content = $tokens[$nextNonWhite]->getContent(); + $content = $tokens[$i + 1]->getContent(); + if (!('#' === $content || '//' === substr($content, 0, 2))) { $tokens[$i] = new Token([T_WHITESPACE, ' ']); } @@ -338,7 +350,17 @@ private function makeClassyDefinitionSingleLine(Tokens $tokens, int $startIndex, continue; } - if (!$tokens[$i - 1]->equals(',') && $tokens[$i + 1]->equalsAny([',', '(', ')']) || $tokens[$i - 1]->equals('(')) { + if ($tokens[$i - 1]->isGivenKind(T_CLASS) && $tokens[$i + 1]->equals('(')) { + if (true === $this->configuration['space_before_parenthesis']) { + $tokens[$i] = new Token([T_WHITESPACE, ' ']); + } else { + $tokens->clearAt($i); + } + + continue; + } + + if (!$tokens[$i - 1]->equals(',') && $tokens[$i + 1]->equalsAny([',', ')']) || $tokens[$i - 1]->equals('(')) { $tokens->clearAt($i); continue; @@ -355,6 +377,12 @@ private function makeClassyDefinitionSingleLine(Tokens $tokens, int $startIndex, continue; } + if ($this->configuration['space_before_parenthesis'] && $tokens[$i]->isGivenKind(T_CLASS) && !$tokens[$i + 1]->isWhitespace()) { + $tokens->insertAt($i + 1, new Token([T_WHITESPACE, ' '])); + + continue; + } + if (!$tokens[$i]->isComment()) { continue; } @@ -374,6 +402,7 @@ private function makeClassyInheritancePartMultiLine(Tokens $tokens, int $startIn for ($i = $endIndex; $i > $startIndex; --$i) { $previousInterfaceImplementingIndex = $tokens->getPrevTokenOfKind($i, [',', [T_IMPLEMENTS], [T_EXTENDS]]); $breakAtIndex = $tokens->getNextMeaningfulToken($previousInterfaceImplementingIndex); + // make the part of a ',' or 'implements' single line $this->makeClassyDefinitionSingleLine( $tokens, @@ -383,6 +412,7 @@ private function makeClassyInheritancePartMultiLine(Tokens $tokens, int $startIn // make sure the part is on its own line $isOnOwnLine = false; + for ($j = $breakAtIndex; $j > $previousInterfaceImplementingIndex; --$j) { if (false !== strpos($tokens[$j]->getContent(), "\n")) { $isOnOwnLine = true; diff --git a/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php b/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php index bba88c55b57..aca68353197 100644 --- a/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php +++ b/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php @@ -28,12 +28,13 @@ */ final class ClassDefinitionFixerTest extends AbstractFixerTestCase { - public function testConfigureDefaultToNull(): void + public function testConfigureDefaultToFalse(): void { $defaultConfig = [ 'multi_line_extends_each_single_line' => false, 'single_item_single_line' => false, 'single_line' => false, + 'space_before_parenthesis' => false, ]; $fixer = new ClassDefinitionFixer(); @@ -117,7 +118,7 @@ public function testInvalidConfigurationKey(): void { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches( - '/^\[class_definition\] Invalid configuration: The option "a" does not exist\. Defined options are: "multi_line_extends_each_single_line", "single_item_single_line", "single_line"\.$/' + '/^\[class_definition\] Invalid configuration: The option "a" does not exist\. Defined options are: "multi_line_extends_each_single_line", "single_item_single_line", "single_line", "space_before_parenthesis"\.$/' ); $fixer = new ClassDefinitionFixer(); @@ -279,6 +280,16 @@ class# ' [ + ' true], + ], + 'space_before_parenthesis 2' => [ + ' true], + ], ]; } @@ -822,6 +833,11 @@ private function provideClassyExtendingCases(string $classy) private function provideClassyImplementsCases() { return [ + [ + ' Date: Fri, 27 Aug 2021 13:19:24 +0200 Subject: [PATCH 04/80] Remove references to PHP 7.0 in tests --- tests/Fixer/Alias/ArrayPushFixerTest.php | 1 - tests/Fixer/Basic/BracesFixerTest.php | 17 ----- .../Basic/NonPrintableCharacterFixerTest.php | 1 - .../LowercaseStaticReferenceFixerTest.php | 15 ----- ...FunctionTypeDeclarationCasingFixerTest.php | 33 ---------- .../ClassDefinitionFixerTest.php | 2 - .../ClassNotation/FinalClassFixerTest.php | 18 ------ .../FinalInternalClassFixerTest.php | 1 - ...lPublicMethodForAbstractClassFixerTest.php | 18 ------ .../NoNullPropertyInitializationFixerTest.php | 15 ----- .../NoUnneededFinalMethodFixerTest.php | 15 ----- .../OrderedInterfacesFixerTest.php | 15 ----- .../ProtectedToPrivateFixerTest.php | 18 ------ .../ClassNotation/SelfAccessorFixerTest.php | 15 ----- .../NativeConstantInvocationFixerTest.php | 16 ----- .../NoSuperfluousElseifFixerTest.php | 15 ----- .../NoUnneededControlParenthesesFixerTest.php | 16 ----- .../CombineNestedDirnameFixerTest.php | 1 - .../FunctionDeclarationFixerTest.php | 17 ----- .../FunctionTypehintSpaceFixerTest.php | 15 ----- .../LambdaNotUsedImportFixerTest.php | 15 ----- .../PhpdocToPropertyTypeFixerTest.php | 22 ------- .../PhpdocToReturnTypeFixerTest.php | 1 - .../ReturnTypeDeclarationFixerTest.php | 1 - .../FullyQualifiedStrictTypesFixerTest.php | 2 - .../Import/GlobalNamespaceImportFixerTest.php | 16 ----- tests/Fixer/Import/GroupImportFixerTest.php | 1 - .../SingleImportPerStatementFixerTest.php | 18 ------ .../SingleLineAfterImportsFixerTest.php | 15 ----- .../ClassKeywordRemoveFixerTest.php | 15 ----- .../CombineConsecutiveIssetsFixerTest.php | 3 - .../ExplicitIndirectVariableFixerTest.php | 1 - .../NoUnsetOnPropertyFixerTest.php | 12 ---- .../SingleSpaceAfterConstructFixerTest.php | 62 ------------------- .../TernaryToNullCoalescingFixerTest.php | 1 - ...nitDedicateAssertInternalTypeFixerTest.php | 15 ----- ...UnitTestCaseStaticMethodCallsFixerTest.php | 3 - ...pdocAddMissingParamAnnotationFixerTest.php | 17 ----- .../PhpdocNoUselessInheritdocFixerTest.php | 15 ----- .../PhpdocReturnSelfReferenceFixerTest.php | 3 - .../Phpdoc/PhpdocVarWithoutNameFixerTest.php | 15 ----- .../ReturnAssignmentFixerTest.php | 15 ----- .../Strict/DeclareStrictTypesFixerTest.php | 2 - .../BlankLineBeforeStatementFixerTest.php | 1 - .../Analyzer/FunctionsAnalyzerTest.php | 15 ----- tests/Tokenizer/TokensAnalyzerTest.php | 51 --------------- tests/Tokenizer/TokensTest.php | 15 ----- .../NamedArgumentTransformerTest.php | 12 ---- .../Transformer/TypeColonTransformerTest.php | 1 - .../Transformer/UseTransformerTest.php | 25 -------- 50 files changed, 654 deletions(-) diff --git a/tests/Fixer/Alias/ArrayPushFixerTest.php b/tests/Fixer/Alias/ArrayPushFixerTest.php index e88533e3f13..690f07cad3e 100644 --- a/tests/Fixer/Alias/ArrayPushFixerTest.php +++ b/tests/Fixer/Alias/ArrayPushFixerTest.php @@ -27,7 +27,6 @@ final class ArrayPushFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases - * @requires PHP 7.0 */ public function testFix(string $expected, ?string $input = null): void { diff --git a/tests/Fixer/Basic/BracesFixerTest.php b/tests/Fixer/Basic/BracesFixerTest.php index 3e9b21848b0..7be3597eee8 100644 --- a/tests/Fixer/Basic/BracesFixerTest.php +++ b/tests/Fixer/Basic/BracesFixerTest.php @@ -2966,23 +2966,6 @@ public function provideFixCommentBeforeBraceCases() ?>', ], - ]; - } - - /** - * @dataProvider provideFixCommentBeforeBrace70Cases - * @requires PHP 7.0 - */ - public function testFixCommentBeforeBrace70(string $expected, ?string $input = null, array $configuration = []): void - { - $this->fixer->configure($configuration); - - $this->doTest($expected, $input); - } - - public function provideFixCommentBeforeBrace70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest($expected); - } - - public function provideFixPre70Cases() - { - return [ - ['doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ ' $config * * @dataProvider provideAnonymousClassesCases - * - * @requires PHP 7.0 */ public function testFixingAnonymousClasses(string $expected, string $input, array $config = []): void { diff --git a/tests/Fixer/ClassNotation/FinalClassFixerTest.php b/tests/Fixer/ClassNotation/FinalClassFixerTest.php index 57fa19ad84f..f0517011d19 100644 --- a/tests/Fixer/ClassNotation/FinalClassFixerTest.php +++ b/tests/Fixer/ClassNotation/FinalClassFixerTest.php @@ -72,24 +72,6 @@ public function provideFixCases() 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ ['doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ 'anonymous-class' => [ sprintf( 'doTest($expected, $input); - } - - public function providePhp70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function providePhp70Cases() - { - return [ 'anonymous-class-inside' => [ 'doTest($expected, $input); - } - - public function provideFixAlpha70Cases() - { - return [ 'nested anonymous classes' => [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - $attributesAndMethodsOriginal = $this->getAttributesAndMethods(true); - $attributesAndMethodsFixed = $this->getAttributesAndMethods(false); - - return [ 'anonymous-class-inside' => [ "doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70WithDefaultConfigurationCases(): array - { - return [ ['doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'fixerTest($expected, $input, $fixStatement); } - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null, ?string $fixStatement = null): void - { - $this->fixerTest($expected, $input, $fixStatement); - } - public function provideFixCases() { return [ @@ -429,12 +420,6 @@ function foo() { $a = (yield $x); } function foo() { $a = (yield($x)); } ', ], - ]; - } - - public function provideFix70Cases() - { - return [ [ 'getSubject() ?? $obj2); @@ -445,7 +430,6 @@ public function provideFix70Cases() /** * @dataProvider provideFixYieldFromCases - * @requires PHP 7.0 */ public function testFixYieldFrom(string $expected, ?string $input = null): void { diff --git a/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php b/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php index 1e34c93f28c..49d28c87946 100644 --- a/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php +++ b/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php @@ -27,7 +27,6 @@ final class CombineNestedDirnameFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases - * @requires PHP 7.0 */ public function testFix(string $expected, ?string $input = null): void { diff --git a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php index f5b09d7acae..b6e3482e178 100644 --- a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php +++ b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php @@ -354,23 +354,6 @@ function foo() /* bar */ ', self::$configurationClosureSpacingNone, ], - ]; - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function test70(string $expected, ?string $input = null, array $configuration = []): void - { - $this->fixer->configure($configuration); - - $this->doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [''], diff --git a/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php b/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php index 1a432af32f3..055737a6ee0 100644 --- a/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php +++ b/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php @@ -183,21 +183,6 @@ public function provideFixCases() 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [''], ]; diff --git a/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php b/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php index e45b0fd8863..ff631e4ae5f 100644 --- a/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php +++ b/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php @@ -103,21 +103,6 @@ public function provideFixCases() $f = function() use ($a) { return function() use ($a) { return function() use ($a) { return function() use ($a) { }; }; }; }; ', ], - ]; - } - - /** - * @requires PHP 7.0 - * @dataProvider providePhp70Cases - */ - public function testFixPhp70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function providePhp70Cases() - { - return [ 'anonymous class' => [ 'fixer->configure($config); - - $this->doTest($expected, $input); - } - - public function provideFixPhp70Cases() - { - return [ 'anonymous class' => [ 'fixer->configure(['import_functions' => true]); - $this->doTest($expected, $input); - } - - public function provideFixImportFunctions70Cases() - { - return [ 'name already used' => [ <<<'EXPECTED' doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ '= 80000) { diff --git a/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php b/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php index 784a05a670b..23d4e4e4d31 100644 --- a/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php +++ b/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php @@ -360,21 +360,6 @@ class Baz class Baz {} '), ], - ]; - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ "doTest( diff --git a/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php b/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php index 185ac2662e7..c7177446a51 100644 --- a/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php +++ b/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php @@ -27,7 +27,6 @@ final class ExplicitIndirectVariableFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideTestFixCases - * @requires PHP 7.0 */ public function testFix(string $expected, ?string $input = null): void { diff --git a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php index a6c995fd3e8..f76ca9600dc 100644 --- a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php +++ b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php @@ -117,19 +117,7 @@ public function provideFixCases() 'foo{0});', ]; } - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - public function provideFix70Cases() - { yield 'It does not break complex expressions' => [ 'fixer->configure($config); - - $this->doTest($expected, $input); - } - - public function provideFixWithClassPhp70Cases() - { - return [ [ 'fixer->configure([ - 'constructs' => [ - 'extends', - ], - ]); - - $this->doTest($expected, $input); - } - - public function provideFixWithExtendsPhp70Cases() - { - return [ [ 'fixer->configure([ - 'constructs' => [ - 'implements', - ], - ]); - - $this->doTest($expected, $input); - } - - public function provideFixWithImplementsPhp70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ 'anonymous class false positive case' => [ 'doTest( diff --git a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php index f2435560d1b..a8df8754e1f 100644 --- a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php @@ -299,23 +299,6 @@ function hello($string) return $string; }', ], - ]; - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null, array $config = []): void - { - $this->fixer->configure($config ?: ['only_untyped' => false]); - - $this->doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest( diff --git a/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php b/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php index 9386932aee8..3c379da498a 100644 --- a/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php @@ -382,21 +382,6 @@ class Foo class Foo{} /** */', ], - ]; - } - - /** - * @requires PHP 7.0 - * @dataProvider provideFixVar70Cases - */ - public function testFixVar70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFixVar70Cases() - { - return [ 'anonymousClass' => [ <<<'EOF' doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'isGlobalFunctionCall($tokens, $index)); - } - public function provideIsGlobalFunctionCallPhp70Cases() - { yield [ true, ' true], ], - ]; - } - - /** - * @dataProvider provideIsLambda70Cases - * @requires PHP 7.0 - */ - public function testIsLambda70(string $source, array $expected): void - { - $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); - - foreach ($expected as $index => $expectedValue) { - static::assertSame($expectedValue, $tokensAnalyzer->isLambda($index)); - } - } - - public function provideIsLambda70Cases() - { - return [ [ ' false, 5 => false, 8 => false, 10 => false, 13 => false, 15 => false], ], - ]; - } - - /** - * @dataProvider provideIsConstantInvocation70Cases - * @requires PHP 7.0 - */ - public function testIsConstantInvocation70(string $source, array $expected): void - { - $this->doIsConstantInvocationTest($source, $expected); - } - - public function provideIsConstantInvocation70Cases() - { - return [ [ ' false, 8 => false], @@ -1838,23 +1804,6 @@ class AnnotatedClass EOF , ], - ]; - } - - /** - * @dataProvider provideGetImportUseIndexesPHP70Cases - * @requires PHP 7.0 - */ - public function testGetImportUseIndexesPHP70(array $expected, string $input, bool $perNamespace = false): void - { - $tokens = Tokens::fromCode($input); - $tokensAnalyzer = new TokensAnalyzer($tokens); - static::assertSame($expected, $tokensAnalyzer->getImportUseIndexes($perNamespace)); - } - - public function provideGetImportUseIndexesPHP70Cases() - { - return [ [ [1, 22, 41], '', Tokens::BLOCK_TYPE_CURLY_BRACE, 5], [11, ' [' T_USE, ], ], - ]; - } - - /** - * @param array $expectedTokens index => kind - * - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $source, array $expectedTokens = []): void - { - $this->doTest( - $source, - $expectedTokens, - [ - T_USE, - CT::T_USE_LAMBDA, - CT::T_USE_TRAIT, - ] - ); - } - - public function provideFix70Cases() - { - return [ 'nested anonymous classes' => [ ' Date: Sun, 15 Aug 2021 13:55:48 +0200 Subject: [PATCH 05/80] Update UPGRADE-v3.md adding relative links --- CHANGELOG.md | 5 + UPGRADE-v3.md | 4 +- dev-tools/composer.json | 8 +- doc/installation.rst | 2 +- phpstan.neon | 2 +- src/Console/Command/SelfUpdateCommand.php | 2 +- src/Fixer/Basic/BracesFixer.php | 6 +- .../Console/Command/SelfUpdateCommandTest.php | 70 ++++++------ tests/Fixer/Basic/BracesFixerTest.php | 6 + .../Transformer/AttributeTransformerTest.php | 107 ++++++++++++++++++ 10 files changed, 168 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 459aa510544..711540d3dcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -158,6 +158,11 @@ Changelog for v3.0.0 * minor #5657 DX: convert some properties to constants (keradus) * minor #5669 Remove TrailingCommaInMultilineArrayFixer (kubawerlos, keradus) +Changelog for v2.19.2 +--------------------- + +* bug #5881 SelfUpdateCommand - fix link to UPGRADE docs (keradus) + Changelog for v2.19.1 --------------------- diff --git a/UPGRADE-v3.md b/UPGRADE-v3.md index 6ff787919b2..dd27c882d0e 100644 --- a/UPGRADE-v3.md +++ b/UPGRADE-v3.md @@ -157,8 +157,8 @@ Code BC changes - class `Token` is now `final` - class `Tokens` is now `final` -- method `create` of class `Config` has been removed, use the constructor -- method `create` of class `RuleSet` has been removed, use the constructor +- method `create` of class `Config` has been removed, [use the constructor](./doc/config.rst) +- method `create` of class `RuleSet` has been removed, [use the constructor](./doc/custom_rules.rst) ### BC breaks; common internal classes diff --git a/dev-tools/composer.json b/dev-tools/composer.json index dfbda51e5cf..7c4695137a2 100644 --- a/dev-tools/composer.json +++ b/dev-tools/composer.json @@ -1,16 +1,16 @@ { "require": { - "php": "^7.1" + "php": "^7.4" }, "require-dev": { - "ergebnis/composer-normalize": "^2.13", + "ergebnis/composer-normalize": "^2.15.0", "humbug/box": "^3.8", - "jangregor/phpstan-prophecy": "^0.6", + "jangregor/phpstan-prophecy": "^0.8.1", "maglnet/composer-require-checker": "2.0.0", "mi-schi/phpmd-extension": "^4.3", "phpmd/phpmd": "^2.10.2", "phpstan/phpstan": "0.12.92", - "phpstan/phpstan-phpunit": "0.12.20" + "phpstan/phpstan-phpunit": "0.12.21" }, "config": { "optimize-autoloader": true, diff --git a/doc/installation.rst b/doc/installation.rst index 24f194a891f..ccef9468e37 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -29,7 +29,7 @@ or with specified version: .. code-block:: console - $ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.15.8/php-cs-fixer.phar -O php-cs-fixer + $ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.0.1/php-cs-fixer.phar -O php-cs-fixer or with curl: diff --git a/phpstan.neon b/phpstan.neon index 4a496f847f3..5c1c6d3c8d8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ includes: - - dev-tools/vendor/jangregor/phpstan-prophecy/src/extension.neon + - dev-tools/vendor/jangregor/phpstan-prophecy/extension.neon - dev-tools/vendor/phpstan/phpstan/conf/bleedingEdge.neon - dev-tools/vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/src/Console/Command/SelfUpdateCommand.php b/src/Console/Command/SelfUpdateCommand.php index f48946e3956..5b242a71bf0 100644 --- a/src/Console/Command/SelfUpdateCommand.php +++ b/src/Console/Command/SelfUpdateCommand.php @@ -139,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int && true !== $input->getOption('force') ) { $output->writeln(sprintf('A new major version of PHP CS Fixer is available (%s)', $latestVersion)); - $output->writeln(sprintf('Before upgrading please read https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/%s/UPGRADE.md', $latestVersion)); + $output->writeln(sprintf('Before upgrading please read https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/%s/UPGRADE-v%s.md', $latestVersion, $currentMajor + 1)); $output->writeln('If you are ready to upgrade run this command with -f'); $output->writeln('Checking for new minor/patch version...'); diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index 82c4fd4c2cd..312d6a6bec0 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -659,9 +659,9 @@ private function fixMissingControlBraces(Tokens $tokens): void continue; } - // do not add for short 'if' followed by alternative loop, - // for example: if ($a) while ($b): ? > X < ?php endwhile; ? > - if ($tokenAfterParenthesis->isGivenKind([T_FOR, T_FOREACH, T_SWITCH, T_WHILE])) { + // do not add for 'short if' followed by alternative loop, for example: if ($a) while ($b): ? > X < ?php endwhile; ? > + // or 'short if' after an alternative loop, for example: foreach ($arr as $index => $item) if ($item): + if ($tokenAfterParenthesis->isGivenKind([T_FOR, T_FOREACH, T_SWITCH, T_WHILE, T_IF])) { $tokenAfterParenthesisBlockEnd = $tokens->findBlockEnd( // go to ')' Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextMeaningfulToken($nextAfterParenthesisEndIndex) diff --git a/tests/Console/Command/SelfUpdateCommandTest.php b/tests/Console/Command/SelfUpdateCommandTest.php index 3f466a259dc..52c6476ca15 100644 --- a/tests/Console/Command/SelfUpdateCommandTest.php +++ b/tests/Console/Command/SelfUpdateCommandTest.php @@ -46,8 +46,8 @@ protected function setUp(): void file_put_contents($this->getToolPath(), 'Current PHP CS Fixer.'); - file_put_contents("{$this->root->url()}/{$this->getNewMinorVersion()}.phar", 'New minor version of PHP CS Fixer.'); - file_put_contents("{$this->root->url()}/{$this->getNewMajorVersion()}.phar", 'New major version of PHP CS Fixer.'); + file_put_contents("{$this->root->url()}/{$this->getNewMinorReleaseVersion()}.phar", 'New minor version of PHP CS Fixer.'); + file_put_contents("{$this->root->url()}/{$this->getNewMajorReleaseVersion()}.phar", 'New major version of PHP CS Fixer.'); } protected function tearDown(): void @@ -137,7 +137,8 @@ public function testExecute( public function provideExecuteCases() { $currentVersion = Application::VERSION; - $minor = $this->getNewMinorVersion(); + $minorRelease = $this->getNewMinorReleaseVersion(); + $majorRelease = $this->getNewMajorReleaseVersion(); $major = $this->getNewMajorVersion(); $currentContents = 'Current PHP CS Fixer.'; @@ -145,22 +146,22 @@ public function provideExecuteCases() $majorContents = 'New major version of PHP CS Fixer.'; $upToDateDisplay = "\033[32mPHP CS Fixer is already up to date.\033[39m\n"; - $newMinorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minor}\033[39m)\n"; - $newMajorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$major}\033[39m)\n"; + $newMinorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minorRelease}\033[39m)\n"; + $newMajorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$majorRelease}\033[39m)\n"; $majorInfoNoMinorDisplay = << \033[33m{$minor}\033[39m) +\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minorRelease}\033[39m) OUTPUT; @@ -174,28 +175,28 @@ public function provideExecuteCases() [Application::VERSION, Application::VERSION, ['-f' => true], false, $currentContents, $upToDateDisplay], // new minor version available - [$minor, $minor, [], true, $minorContents, $newMinorDisplay], - [$minor, $minor, ['--force' => true], true, $minorContents, $newMinorDisplay], - [$minor, $minor, ['-f' => true], true, $minorContents, $newMinorDisplay], - [$minor, $minor, [], false, $minorContents, $newMinorDisplay], - [$minor, $minor, ['--force' => true], false, $minorContents, $newMinorDisplay], - [$minor, $minor, ['-f' => true], false, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, [], true, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, ['--force' => true], true, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, ['-f' => true], true, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, [], false, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, ['--force' => true], false, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, ['-f' => true], false, $minorContents, $newMinorDisplay], // new major version available - [$major, Application::VERSION, [], true, $currentContents, $majorInfoNoMinorDisplay], - [$major, Application::VERSION, [], false, $currentContents, $majorInfoNoMinorDisplay], - [$major, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay], - [$major, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay], - [$major, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay], - [$major, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay], + [$majorRelease, Application::VERSION, [], true, $currentContents, $majorInfoNoMinorDisplay], + [$majorRelease, Application::VERSION, [], false, $currentContents, $majorInfoNoMinorDisplay], + [$majorRelease, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay], + [$majorRelease, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay], + [$majorRelease, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay], + [$majorRelease, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay], // new minor version and new major version available - [$major, $minor, [], true, $minorContents, $majorInfoNewMinorDisplay], - [$major, $minor, [], false, $minorContents, $majorInfoNewMinorDisplay], - [$major, $minor, ['--force' => true], true, $majorContents, $newMajorDisplay], - [$major, $minor, ['-f' => true], false, $majorContents, $newMajorDisplay], - [$major, $minor, ['--force' => true], true, $majorContents, $newMajorDisplay], - [$major, $minor, ['-f' => true], false, $majorContents, $newMajorDisplay], + [$majorRelease, $minorRelease, [], true, $minorContents, $majorInfoNewMinorDisplay], + [$majorRelease, $minorRelease, [], false, $minorContents, $majorInfoNewMinorDisplay], + [$majorRelease, $minorRelease, ['--force' => true], true, $majorContents, $newMajorDisplay], + [$majorRelease, $minorRelease, ['-f' => true], false, $majorContents, $newMajorDisplay], + [$majorRelease, $minorRelease, ['--force' => true], true, $majorContents, $newMajorDisplay], + [$majorRelease, $minorRelease, ['-f' => true], false, $majorContents, $newMajorDisplay], // weird/unexpected versions ['v0.1.0', 'v0.1.0', [], true, $currentContents, $upToDateDisplay], @@ -236,7 +237,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions( ): void { $versionChecker = $this->prophesize(\PhpCsFixer\Console\SelfUpdate\NewVersionCheckerInterface::class); - $newMajorVersion = $this->getNewMajorVersion(); + $newMajorVersion = $this->getNewMajorReleaseVersion(); $versionChecker->getLatestVersion()->will(function () use ($latestVersionSuccess, $newMajorVersion) { if ($latestVersionSuccess) { return $newMajorVersion; @@ -245,7 +246,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions( throw new \RuntimeException('Foo.'); }); - $newMinorVersion = $this->getNewMinorVersion(); + $newMinorVersion = $this->getNewMinorReleaseVersion(); $versionChecker ->getLatestVersionOfMajor($this->getCurrentMajorVersion()) ->will(function () use ($latestMinorVersionSuccess, $newMinorVersion) { @@ -390,13 +391,18 @@ private function getCurrentMajorVersion() return (int) preg_replace('/^v?(\d+).*$/', '$1', Application::VERSION); } - private function getNewMinorVersion() + private function getNewMinorReleaseVersion() { return "{$this->getCurrentMajorVersion()}.999.0"; } private function getNewMajorVersion() { - return ($this->getCurrentMajorVersion() + 1).'.0.0'; + return $this->getCurrentMajorVersion() + 1; + } + + private function getNewMajorReleaseVersion() + { + return $this->getNewMajorVersion().'.0.0'; } } diff --git a/tests/Fixer/Basic/BracesFixerTest.php b/tests/Fixer/Basic/BracesFixerTest.php index fe0ef98e16c..3e9b21848b0 100644 --- a/tests/Fixer/Basic/BracesFixerTest.php +++ b/tests/Fixer/Basic/BracesFixerTest.php @@ -789,6 +789,12 @@ public function bar() { ', ], + [ + ' + $item) if ($item): ?> + +', + ], ]; } diff --git a/tests/Tokenizer/Transformer/AttributeTransformerTest.php b/tests/Tokenizer/Transformer/AttributeTransformerTest.php index 190d16d55c1..a60507e6ead 100644 --- a/tests/Tokenizer/Transformer/AttributeTransformerTest.php +++ b/tests/Tokenizer/Transformer/AttributeTransformerTest.php @@ -63,6 +63,113 @@ public function provideProcessCases() 16 => CT::T_ATTRIBUTE_CLOSE, ], ]; + + yield [ + ' "The email {{ value }} is not a valid email."])] + private $email; + }', + [ + 21 => CT::T_ATTRIBUTE_CLOSE, + 36 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; + + yield [ + '>9+foo(a)+foo((bool)$b))] // gets removed from AST when >= 7.0 +#[IgnoreRedeclaration] // throws no error when already declared, removes the redeclared thing +function intdiv(int $numerator, int $divisor) { +} + +#[ +Attr1("foo"),Attr2("bar"), +] + +#[PhpAttribute(self::IS_REPEATABLE)] +class Route +{ +} +', + [ + 5 => CT::T_ATTRIBUTE_CLOSE, + 35 => CT::T_ATTRIBUTE_CLOSE, + 41 => CT::T_ATTRIBUTE_CLOSE, + 76 => CT::T_ATTRIBUTE_CLOSE, + 85 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; + + yield [ + ' 1; +', + [ + 3 => CT::T_ATTRIBUTE_CLOSE, + 22 => CT::T_ATTRIBUTE_CLOSE, + 37 => CT::T_ATTRIBUTE_CLOSE, + 47 => CT::T_ATTRIBUTE_CLOSE, + 67 => CT::T_ATTRIBUTE_CLOSE, + 84 => CT::T_ATTRIBUTE_CLOSE, + 101 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; + + yield [ + ' "The email \'{{ value }}\' is not a valid email."])] + private $email; + + #[\Doctrine\ORM\ManyToMany( + targetEntity: User::class, + joinColumn: "group_id", + inverseJoinColumn: "user_id", + cascade: array("persist", "remove") + )] + #[Assert\Valid] + #[JMSSerializer\XmlList(inline: true, entry: "user")] + public $users; +} +', + [ + 15 => CT::T_ATTRIBUTE_CLOSE, + 40 => CT::T_ATTRIBUTE_CLOSE, + 61 => CT::T_ATTRIBUTE_CLOSE, + 76 => CT::T_ATTRIBUTE_CLOSE, + 124 => CT::T_ATTRIBUTE_CLOSE, + 130 => CT::T_ATTRIBUTE_CLOSE, + 148 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; } /** From 1fbab28e394faa0cec2cc0293b777fbba37cafc6 Mon Sep 17 00:00:00 2001 From: Brian Teeman Date: Wed, 18 Aug 2021 19:07:57 +0100 Subject: [PATCH 06/80] Docs: typo --- CHANGELOG.md | 5 + UPGRADE-v3.md | 4 +- dev-tools/composer.json | 8 +- doc/installation.rst | 2 +- doc/usage.rst | 2 +- phpstan.neon | 2 +- src/Console/Command/SelfUpdateCommand.php | 2 +- src/Fixer/Basic/BracesFixer.php | 6 +- .../Console/Command/SelfUpdateCommandTest.php | 70 ++++++------ tests/Fixer/Alias/ArrayPushFixerTest.php | 1 - tests/Fixer/Basic/BracesFixerTest.php | 23 +--- .../Basic/NonPrintableCharacterFixerTest.php | 1 - .../LowercaseStaticReferenceFixerTest.php | 15 --- ...FunctionTypeDeclarationCasingFixerTest.php | 33 ------ .../ClassDefinitionFixerTest.php | 2 - .../ClassNotation/FinalClassFixerTest.php | 18 --- .../FinalInternalClassFixerTest.php | 1 - ...lPublicMethodForAbstractClassFixerTest.php | 18 --- .../NoNullPropertyInitializationFixerTest.php | 15 --- .../NoUnneededFinalMethodFixerTest.php | 15 --- .../OrderedInterfacesFixerTest.php | 15 --- .../ProtectedToPrivateFixerTest.php | 18 --- .../ClassNotation/SelfAccessorFixerTest.php | 15 --- .../NativeConstantInvocationFixerTest.php | 16 --- .../NoSuperfluousElseifFixerTest.php | 15 --- .../NoUnneededControlParenthesesFixerTest.php | 16 --- .../CombineNestedDirnameFixerTest.php | 1 - .../FunctionDeclarationFixerTest.php | 17 --- .../FunctionTypehintSpaceFixerTest.php | 15 --- .../LambdaNotUsedImportFixerTest.php | 15 --- .../PhpdocToPropertyTypeFixerTest.php | 22 ---- .../PhpdocToReturnTypeFixerTest.php | 1 - .../ReturnTypeDeclarationFixerTest.php | 1 - .../FullyQualifiedStrictTypesFixerTest.php | 2 - .../Import/GlobalNamespaceImportFixerTest.php | 16 --- tests/Fixer/Import/GroupImportFixerTest.php | 1 - .../SingleImportPerStatementFixerTest.php | 18 --- .../SingleLineAfterImportsFixerTest.php | 15 --- .../ClassKeywordRemoveFixerTest.php | 15 --- .../CombineConsecutiveIssetsFixerTest.php | 3 - .../ExplicitIndirectVariableFixerTest.php | 1 - .../NoUnsetOnPropertyFixerTest.php | 12 -- .../SingleSpaceAfterConstructFixerTest.php | 62 ---------- .../TernaryToNullCoalescingFixerTest.php | 1 - ...nitDedicateAssertInternalTypeFixerTest.php | 15 --- ...UnitTestCaseStaticMethodCallsFixerTest.php | 3 - ...pdocAddMissingParamAnnotationFixerTest.php | 17 --- .../PhpdocNoUselessInheritdocFixerTest.php | 15 --- .../PhpdocReturnSelfReferenceFixerTest.php | 3 - .../Phpdoc/PhpdocVarWithoutNameFixerTest.php | 15 --- .../ReturnAssignmentFixerTest.php | 15 --- .../Strict/DeclareStrictTypesFixerTest.php | 2 - .../BlankLineBeforeStatementFixerTest.php | 1 - .../Analyzer/FunctionsAnalyzerTest.php | 15 --- tests/Tokenizer/TokensAnalyzerTest.php | 51 --------- tests/Tokenizer/TokensTest.php | 15 --- .../Transformer/AttributeTransformerTest.php | 107 ++++++++++++++++++ .../NamedArgumentTransformerTest.php | 12 -- .../Transformer/TypeColonTransformerTest.php | 1 - .../Transformer/UseTransformerTest.php | 25 ---- 60 files changed, 169 insertions(+), 699 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 459aa510544..711540d3dcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -158,6 +158,11 @@ Changelog for v3.0.0 * minor #5657 DX: convert some properties to constants (keradus) * minor #5669 Remove TrailingCommaInMultilineArrayFixer (kubawerlos, keradus) +Changelog for v2.19.2 +--------------------- + +* bug #5881 SelfUpdateCommand - fix link to UPGRADE docs (keradus) + Changelog for v2.19.1 --------------------- diff --git a/UPGRADE-v3.md b/UPGRADE-v3.md index 6ff787919b2..dd27c882d0e 100644 --- a/UPGRADE-v3.md +++ b/UPGRADE-v3.md @@ -157,8 +157,8 @@ Code BC changes - class `Token` is now `final` - class `Tokens` is now `final` -- method `create` of class `Config` has been removed, use the constructor -- method `create` of class `RuleSet` has been removed, use the constructor +- method `create` of class `Config` has been removed, [use the constructor](./doc/config.rst) +- method `create` of class `RuleSet` has been removed, [use the constructor](./doc/custom_rules.rst) ### BC breaks; common internal classes diff --git a/dev-tools/composer.json b/dev-tools/composer.json index dfbda51e5cf..7c4695137a2 100644 --- a/dev-tools/composer.json +++ b/dev-tools/composer.json @@ -1,16 +1,16 @@ { "require": { - "php": "^7.1" + "php": "^7.4" }, "require-dev": { - "ergebnis/composer-normalize": "^2.13", + "ergebnis/composer-normalize": "^2.15.0", "humbug/box": "^3.8", - "jangregor/phpstan-prophecy": "^0.6", + "jangregor/phpstan-prophecy": "^0.8.1", "maglnet/composer-require-checker": "2.0.0", "mi-schi/phpmd-extension": "^4.3", "phpmd/phpmd": "^2.10.2", "phpstan/phpstan": "0.12.92", - "phpstan/phpstan-phpunit": "0.12.20" + "phpstan/phpstan-phpunit": "0.12.21" }, "config": { "optimize-autoloader": true, diff --git a/doc/installation.rst b/doc/installation.rst index 24f194a891f..ccef9468e37 100644 --- a/doc/installation.rst +++ b/doc/installation.rst @@ -29,7 +29,7 @@ or with specified version: .. code-block:: console - $ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.15.8/php-cs-fixer.phar -O php-cs-fixer + $ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v3.0.1/php-cs-fixer.phar -O php-cs-fixer or with curl: diff --git a/doc/usage.rst b/doc/usage.rst index c369141ab8c..01e4f6da647 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -133,7 +133,7 @@ The ``--config`` option can be used, like in the ``fix`` command, to tell from w $ php php-cs-fixer.phar list-files --config=.php-cs-fixer.dist.php -The output is build in a form that its easy to use in combination with ``xargs`` command in a linux pipe. +The output is built in a form that its easy to use in combination with ``xargs`` command in a linux pipe. This can be useful e.g. in situations where the caching mechanism might not be available (CI, Docker) and distribute fixing across several processes might speedup the process. diff --git a/phpstan.neon b/phpstan.neon index 4a496f847f3..5c1c6d3c8d8 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ includes: - - dev-tools/vendor/jangregor/phpstan-prophecy/src/extension.neon + - dev-tools/vendor/jangregor/phpstan-prophecy/extension.neon - dev-tools/vendor/phpstan/phpstan/conf/bleedingEdge.neon - dev-tools/vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/src/Console/Command/SelfUpdateCommand.php b/src/Console/Command/SelfUpdateCommand.php index f48946e3956..5b242a71bf0 100644 --- a/src/Console/Command/SelfUpdateCommand.php +++ b/src/Console/Command/SelfUpdateCommand.php @@ -139,7 +139,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int && true !== $input->getOption('force') ) { $output->writeln(sprintf('A new major version of PHP CS Fixer is available (%s)', $latestVersion)); - $output->writeln(sprintf('Before upgrading please read https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/%s/UPGRADE.md', $latestVersion)); + $output->writeln(sprintf('Before upgrading please read https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/%s/UPGRADE-v%s.md', $latestVersion, $currentMajor + 1)); $output->writeln('If you are ready to upgrade run this command with -f'); $output->writeln('Checking for new minor/patch version...'); diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index 82c4fd4c2cd..312d6a6bec0 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -659,9 +659,9 @@ private function fixMissingControlBraces(Tokens $tokens): void continue; } - // do not add for short 'if' followed by alternative loop, - // for example: if ($a) while ($b): ? > X < ?php endwhile; ? > - if ($tokenAfterParenthesis->isGivenKind([T_FOR, T_FOREACH, T_SWITCH, T_WHILE])) { + // do not add for 'short if' followed by alternative loop, for example: if ($a) while ($b): ? > X < ?php endwhile; ? > + // or 'short if' after an alternative loop, for example: foreach ($arr as $index => $item) if ($item): + if ($tokenAfterParenthesis->isGivenKind([T_FOR, T_FOREACH, T_SWITCH, T_WHILE, T_IF])) { $tokenAfterParenthesisBlockEnd = $tokens->findBlockEnd( // go to ')' Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextMeaningfulToken($nextAfterParenthesisEndIndex) diff --git a/tests/Console/Command/SelfUpdateCommandTest.php b/tests/Console/Command/SelfUpdateCommandTest.php index 3f466a259dc..52c6476ca15 100644 --- a/tests/Console/Command/SelfUpdateCommandTest.php +++ b/tests/Console/Command/SelfUpdateCommandTest.php @@ -46,8 +46,8 @@ protected function setUp(): void file_put_contents($this->getToolPath(), 'Current PHP CS Fixer.'); - file_put_contents("{$this->root->url()}/{$this->getNewMinorVersion()}.phar", 'New minor version of PHP CS Fixer.'); - file_put_contents("{$this->root->url()}/{$this->getNewMajorVersion()}.phar", 'New major version of PHP CS Fixer.'); + file_put_contents("{$this->root->url()}/{$this->getNewMinorReleaseVersion()}.phar", 'New minor version of PHP CS Fixer.'); + file_put_contents("{$this->root->url()}/{$this->getNewMajorReleaseVersion()}.phar", 'New major version of PHP CS Fixer.'); } protected function tearDown(): void @@ -137,7 +137,8 @@ public function testExecute( public function provideExecuteCases() { $currentVersion = Application::VERSION; - $minor = $this->getNewMinorVersion(); + $minorRelease = $this->getNewMinorReleaseVersion(); + $majorRelease = $this->getNewMajorReleaseVersion(); $major = $this->getNewMajorVersion(); $currentContents = 'Current PHP CS Fixer.'; @@ -145,22 +146,22 @@ public function provideExecuteCases() $majorContents = 'New major version of PHP CS Fixer.'; $upToDateDisplay = "\033[32mPHP CS Fixer is already up to date.\033[39m\n"; - $newMinorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minor}\033[39m)\n"; - $newMajorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$major}\033[39m)\n"; + $newMinorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minorRelease}\033[39m)\n"; + $newMajorDisplay = "\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$majorRelease}\033[39m)\n"; $majorInfoNoMinorDisplay = << \033[33m{$minor}\033[39m) +\033[32mPHP CS Fixer updated\033[39m (\033[33m{$currentVersion}\033[39m -> \033[33m{$minorRelease}\033[39m) OUTPUT; @@ -174,28 +175,28 @@ public function provideExecuteCases() [Application::VERSION, Application::VERSION, ['-f' => true], false, $currentContents, $upToDateDisplay], // new minor version available - [$minor, $minor, [], true, $minorContents, $newMinorDisplay], - [$minor, $minor, ['--force' => true], true, $minorContents, $newMinorDisplay], - [$minor, $minor, ['-f' => true], true, $minorContents, $newMinorDisplay], - [$minor, $minor, [], false, $minorContents, $newMinorDisplay], - [$minor, $minor, ['--force' => true], false, $minorContents, $newMinorDisplay], - [$minor, $minor, ['-f' => true], false, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, [], true, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, ['--force' => true], true, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, ['-f' => true], true, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, [], false, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, ['--force' => true], false, $minorContents, $newMinorDisplay], + [$minorRelease, $minorRelease, ['-f' => true], false, $minorContents, $newMinorDisplay], // new major version available - [$major, Application::VERSION, [], true, $currentContents, $majorInfoNoMinorDisplay], - [$major, Application::VERSION, [], false, $currentContents, $majorInfoNoMinorDisplay], - [$major, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay], - [$major, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay], - [$major, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay], - [$major, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay], + [$majorRelease, Application::VERSION, [], true, $currentContents, $majorInfoNoMinorDisplay], + [$majorRelease, Application::VERSION, [], false, $currentContents, $majorInfoNoMinorDisplay], + [$majorRelease, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay], + [$majorRelease, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay], + [$majorRelease, Application::VERSION, ['--force' => true], true, $majorContents, $newMajorDisplay], + [$majorRelease, Application::VERSION, ['-f' => true], false, $majorContents, $newMajorDisplay], // new minor version and new major version available - [$major, $minor, [], true, $minorContents, $majorInfoNewMinorDisplay], - [$major, $minor, [], false, $minorContents, $majorInfoNewMinorDisplay], - [$major, $minor, ['--force' => true], true, $majorContents, $newMajorDisplay], - [$major, $minor, ['-f' => true], false, $majorContents, $newMajorDisplay], - [$major, $minor, ['--force' => true], true, $majorContents, $newMajorDisplay], - [$major, $minor, ['-f' => true], false, $majorContents, $newMajorDisplay], + [$majorRelease, $minorRelease, [], true, $minorContents, $majorInfoNewMinorDisplay], + [$majorRelease, $minorRelease, [], false, $minorContents, $majorInfoNewMinorDisplay], + [$majorRelease, $minorRelease, ['--force' => true], true, $majorContents, $newMajorDisplay], + [$majorRelease, $minorRelease, ['-f' => true], false, $majorContents, $newMajorDisplay], + [$majorRelease, $minorRelease, ['--force' => true], true, $majorContents, $newMajorDisplay], + [$majorRelease, $minorRelease, ['-f' => true], false, $majorContents, $newMajorDisplay], // weird/unexpected versions ['v0.1.0', 'v0.1.0', [], true, $currentContents, $upToDateDisplay], @@ -236,7 +237,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions( ): void { $versionChecker = $this->prophesize(\PhpCsFixer\Console\SelfUpdate\NewVersionCheckerInterface::class); - $newMajorVersion = $this->getNewMajorVersion(); + $newMajorVersion = $this->getNewMajorReleaseVersion(); $versionChecker->getLatestVersion()->will(function () use ($latestVersionSuccess, $newMajorVersion) { if ($latestVersionSuccess) { return $newMajorVersion; @@ -245,7 +246,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions( throw new \RuntimeException('Foo.'); }); - $newMinorVersion = $this->getNewMinorVersion(); + $newMinorVersion = $this->getNewMinorReleaseVersion(); $versionChecker ->getLatestVersionOfMajor($this->getCurrentMajorVersion()) ->will(function () use ($latestMinorVersionSuccess, $newMinorVersion) { @@ -390,13 +391,18 @@ private function getCurrentMajorVersion() return (int) preg_replace('/^v?(\d+).*$/', '$1', Application::VERSION); } - private function getNewMinorVersion() + private function getNewMinorReleaseVersion() { return "{$this->getCurrentMajorVersion()}.999.0"; } private function getNewMajorVersion() { - return ($this->getCurrentMajorVersion() + 1).'.0.0'; + return $this->getCurrentMajorVersion() + 1; + } + + private function getNewMajorReleaseVersion() + { + return $this->getNewMajorVersion().'.0.0'; } } diff --git a/tests/Fixer/Alias/ArrayPushFixerTest.php b/tests/Fixer/Alias/ArrayPushFixerTest.php index e88533e3f13..690f07cad3e 100644 --- a/tests/Fixer/Alias/ArrayPushFixerTest.php +++ b/tests/Fixer/Alias/ArrayPushFixerTest.php @@ -27,7 +27,6 @@ final class ArrayPushFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases - * @requires PHP 7.0 */ public function testFix(string $expected, ?string $input = null): void { diff --git a/tests/Fixer/Basic/BracesFixerTest.php b/tests/Fixer/Basic/BracesFixerTest.php index fe0ef98e16c..7be3597eee8 100644 --- a/tests/Fixer/Basic/BracesFixerTest.php +++ b/tests/Fixer/Basic/BracesFixerTest.php @@ -789,6 +789,12 @@ public function bar() { ', ], + [ + ' + $item) if ($item): ?> + +', + ], ]; } @@ -2960,23 +2966,6 @@ public function provideFixCommentBeforeBraceCases() ?>', ], - ]; - } - - /** - * @dataProvider provideFixCommentBeforeBrace70Cases - * @requires PHP 7.0 - */ - public function testFixCommentBeforeBrace70(string $expected, ?string $input = null, array $configuration = []): void - { - $this->fixer->configure($configuration); - - $this->doTest($expected, $input); - } - - public function provideFixCommentBeforeBrace70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest($expected); - } - - public function provideFixPre70Cases() - { - return [ - ['doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ ' $config * * @dataProvider provideAnonymousClassesCases - * - * @requires PHP 7.0 */ public function testFixingAnonymousClasses(string $expected, string $input, array $config = []): void { diff --git a/tests/Fixer/ClassNotation/FinalClassFixerTest.php b/tests/Fixer/ClassNotation/FinalClassFixerTest.php index 57fa19ad84f..f0517011d19 100644 --- a/tests/Fixer/ClassNotation/FinalClassFixerTest.php +++ b/tests/Fixer/ClassNotation/FinalClassFixerTest.php @@ -72,24 +72,6 @@ public function provideFixCases() 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ ['doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ 'anonymous-class' => [ sprintf( 'doTest($expected, $input); - } - - public function providePhp70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function providePhp70Cases() - { - return [ 'anonymous-class-inside' => [ 'doTest($expected, $input); - } - - public function provideFixAlpha70Cases() - { - return [ 'nested anonymous classes' => [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - $attributesAndMethodsOriginal = $this->getAttributesAndMethods(true); - $attributesAndMethodsFixed = $this->getAttributesAndMethods(false); - - return [ 'anonymous-class-inside' => [ "doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70WithDefaultConfigurationCases(): array - { - return [ ['doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'fixerTest($expected, $input, $fixStatement); } - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null, ?string $fixStatement = null): void - { - $this->fixerTest($expected, $input, $fixStatement); - } - public function provideFixCases() { return [ @@ -429,12 +420,6 @@ function foo() { $a = (yield $x); } function foo() { $a = (yield($x)); } ', ], - ]; - } - - public function provideFix70Cases() - { - return [ [ 'getSubject() ?? $obj2); @@ -445,7 +430,6 @@ public function provideFix70Cases() /** * @dataProvider provideFixYieldFromCases - * @requires PHP 7.0 */ public function testFixYieldFrom(string $expected, ?string $input = null): void { diff --git a/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php b/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php index 1e34c93f28c..49d28c87946 100644 --- a/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php +++ b/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php @@ -27,7 +27,6 @@ final class CombineNestedDirnameFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases - * @requires PHP 7.0 */ public function testFix(string $expected, ?string $input = null): void { diff --git a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php index f5b09d7acae..b6e3482e178 100644 --- a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php +++ b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php @@ -354,23 +354,6 @@ function foo() /* bar */ ', self::$configurationClosureSpacingNone, ], - ]; - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function test70(string $expected, ?string $input = null, array $configuration = []): void - { - $this->fixer->configure($configuration); - - $this->doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [''], diff --git a/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php b/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php index 1a432af32f3..055737a6ee0 100644 --- a/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php +++ b/tests/Fixer/FunctionNotation/FunctionTypehintSpaceFixerTest.php @@ -183,21 +183,6 @@ public function provideFixCases() 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [''], ]; diff --git a/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php b/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php index e45b0fd8863..ff631e4ae5f 100644 --- a/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php +++ b/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php @@ -103,21 +103,6 @@ public function provideFixCases() $f = function() use ($a) { return function() use ($a) { return function() use ($a) { return function() use ($a) { }; }; }; }; ', ], - ]; - } - - /** - * @requires PHP 7.0 - * @dataProvider providePhp70Cases - */ - public function testFixPhp70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function providePhp70Cases() - { - return [ 'anonymous class' => [ 'fixer->configure($config); - - $this->doTest($expected, $input); - } - - public function provideFixPhp70Cases() - { - return [ 'anonymous class' => [ 'fixer->configure(['import_functions' => true]); - $this->doTest($expected, $input); - } - - public function provideFixImportFunctions70Cases() - { - return [ 'name already used' => [ <<<'EXPECTED' doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ '= 80000) { diff --git a/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php b/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php index 784a05a670b..23d4e4e4d31 100644 --- a/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php +++ b/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php @@ -360,21 +360,6 @@ class Baz class Baz {} '), ], - ]; - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ "doTest( diff --git a/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php b/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php index 185ac2662e7..c7177446a51 100644 --- a/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php +++ b/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php @@ -27,7 +27,6 @@ final class ExplicitIndirectVariableFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideTestFixCases - * @requires PHP 7.0 */ public function testFix(string $expected, ?string $input = null): void { diff --git a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php index a6c995fd3e8..f76ca9600dc 100644 --- a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php +++ b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php @@ -117,19 +117,7 @@ public function provideFixCases() 'foo{0});', ]; } - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - public function provideFix70Cases() - { yield 'It does not break complex expressions' => [ 'fixer->configure($config); - - $this->doTest($expected, $input); - } - - public function provideFixWithClassPhp70Cases() - { - return [ [ 'fixer->configure([ - 'constructs' => [ - 'extends', - ], - ]); - - $this->doTest($expected, $input); - } - - public function provideFixWithExtendsPhp70Cases() - { - return [ [ 'fixer->configure([ - 'constructs' => [ - 'implements', - ], - ]); - - $this->doTest($expected, $input); - } - - public function provideFixWithImplementsPhp70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ 'anonymous class false positive case' => [ 'doTest( diff --git a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php index f2435560d1b..a8df8754e1f 100644 --- a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php @@ -299,23 +299,6 @@ function hello($string) return $string; }', ], - ]; - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null, array $config = []): void - { - $this->fixer->configure($config ?: ['only_untyped' => false]); - - $this->doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'doTest( diff --git a/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php b/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php index 9386932aee8..3c379da498a 100644 --- a/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php @@ -382,21 +382,6 @@ class Foo class Foo{} /** */', ], - ]; - } - - /** - * @requires PHP 7.0 - * @dataProvider provideFixVar70Cases - */ - public function testFixVar70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFixVar70Cases() - { - return [ 'anonymousClass' => [ <<<'EOF' doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ [ 'isGlobalFunctionCall($tokens, $index)); - } - public function provideIsGlobalFunctionCallPhp70Cases() - { yield [ true, ' true], ], - ]; - } - - /** - * @dataProvider provideIsLambda70Cases - * @requires PHP 7.0 - */ - public function testIsLambda70(string $source, array $expected): void - { - $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); - - foreach ($expected as $index => $expectedValue) { - static::assertSame($expectedValue, $tokensAnalyzer->isLambda($index)); - } - } - - public function provideIsLambda70Cases() - { - return [ [ ' false, 5 => false, 8 => false, 10 => false, 13 => false, 15 => false], ], - ]; - } - - /** - * @dataProvider provideIsConstantInvocation70Cases - * @requires PHP 7.0 - */ - public function testIsConstantInvocation70(string $source, array $expected): void - { - $this->doIsConstantInvocationTest($source, $expected); - } - - public function provideIsConstantInvocation70Cases() - { - return [ [ ' false, 8 => false], @@ -1838,23 +1804,6 @@ class AnnotatedClass EOF , ], - ]; - } - - /** - * @dataProvider provideGetImportUseIndexesPHP70Cases - * @requires PHP 7.0 - */ - public function testGetImportUseIndexesPHP70(array $expected, string $input, bool $perNamespace = false): void - { - $tokens = Tokens::fromCode($input); - $tokensAnalyzer = new TokensAnalyzer($tokens); - static::assertSame($expected, $tokensAnalyzer->getImportUseIndexes($perNamespace)); - } - - public function provideGetImportUseIndexesPHP70Cases() - { - return [ [ [1, 22, 41], '', Tokens::BLOCK_TYPE_CURLY_BRACE, 5], [11, ' CT::T_ATTRIBUTE_CLOSE, ], ]; + + yield [ + ' "The email {{ value }} is not a valid email."])] + private $email; + }', + [ + 21 => CT::T_ATTRIBUTE_CLOSE, + 36 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; + + yield [ + '>9+foo(a)+foo((bool)$b))] // gets removed from AST when >= 7.0 +#[IgnoreRedeclaration] // throws no error when already declared, removes the redeclared thing +function intdiv(int $numerator, int $divisor) { +} + +#[ +Attr1("foo"),Attr2("bar"), +] + +#[PhpAttribute(self::IS_REPEATABLE)] +class Route +{ +} +', + [ + 5 => CT::T_ATTRIBUTE_CLOSE, + 35 => CT::T_ATTRIBUTE_CLOSE, + 41 => CT::T_ATTRIBUTE_CLOSE, + 76 => CT::T_ATTRIBUTE_CLOSE, + 85 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; + + yield [ + ' 1; +', + [ + 3 => CT::T_ATTRIBUTE_CLOSE, + 22 => CT::T_ATTRIBUTE_CLOSE, + 37 => CT::T_ATTRIBUTE_CLOSE, + 47 => CT::T_ATTRIBUTE_CLOSE, + 67 => CT::T_ATTRIBUTE_CLOSE, + 84 => CT::T_ATTRIBUTE_CLOSE, + 101 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; + + yield [ + ' "The email \'{{ value }}\' is not a valid email."])] + private $email; + + #[\Doctrine\ORM\ManyToMany( + targetEntity: User::class, + joinColumn: "group_id", + inverseJoinColumn: "user_id", + cascade: array("persist", "remove") + )] + #[Assert\Valid] + #[JMSSerializer\XmlList(inline: true, entry: "user")] + public $users; +} +', + [ + 15 => CT::T_ATTRIBUTE_CLOSE, + 40 => CT::T_ATTRIBUTE_CLOSE, + 61 => CT::T_ATTRIBUTE_CLOSE, + 76 => CT::T_ATTRIBUTE_CLOSE, + 124 => CT::T_ATTRIBUTE_CLOSE, + 130 => CT::T_ATTRIBUTE_CLOSE, + 148 => CT::T_ATTRIBUTE_CLOSE, + ], + ]; } /** diff --git a/tests/Tokenizer/Transformer/NamedArgumentTransformerTest.php b/tests/Tokenizer/Transformer/NamedArgumentTransformerTest.php index 4eb7d1121ce..4adb18620da 100644 --- a/tests/Tokenizer/Transformer/NamedArgumentTransformerTest.php +++ b/tests/Tokenizer/Transformer/NamedArgumentTransformerTest.php @@ -133,19 +133,7 @@ public function provideDoNotChangeCases() } ', ]; - } - - /** - * @dataProvider provideDoNotChange70Cases - * @requires PHP 7.0 - */ - public function testDoNotChange70(string $source): void - { - static::assertNotChange($source); - } - public function provideDoNotChange70Cases() - { yield 'return type' => [' T_USE, ], ], - ]; - } - - /** - * @param array $expectedTokens index => kind - * - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $source, array $expectedTokens = []): void - { - $this->doTest( - $source, - $expectedTokens, - [ - T_USE, - CT::T_USE_LAMBDA, - CT::T_USE_TRAIT, - ] - ); - } - - public function provideFix70Cases() - { - return [ 'nested anonymous classes' => [ ' Date: Wed, 4 Aug 2021 23:49:34 +0200 Subject: [PATCH 07/80] PhpdocTagTypeFixer - must not remove inlined tags within other tags --- src/Fixer/Phpdoc/PhpdocTagTypeFixer.php | 20 ++++++----- tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php | 34 +++++++++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php b/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php index 03337745520..9cab7e35e5f 100644 --- a/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php @@ -90,21 +90,23 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void return; } + $regularExpression = sprintf( + '/({?@(?:%s).*?(?:(?=\s\*\/)|(?=\n)}?))/i', + implode('|', array_map( + function (string $tag) { + return preg_quote($tag, '/'); + }, + array_keys($this->configuration['tags']) + )) + ); + foreach ($tokens as $index => $token) { if (!$token->isGivenKind(T_DOC_COMMENT)) { continue; } $parts = Preg::split( - sprintf( - '/({?@(?:%s)(?:}|\h.*?(?:}|(?=\R)|(?=\h+\*\/)))?)/i', - implode('|', array_map( - function (string $tag) { - return preg_quote($tag, '/'); - }, - array_keys($this->configuration['tags']) - )) - ), + $regularExpression, $token->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE diff --git a/tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php index 379be704b77..e1d4d7eb4ca 100644 --- a/tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php @@ -350,6 +350,40 @@ public function provideFixCases() * @return array{0: float, 1: int} */', ], + [ + ' Date: Fri, 20 Aug 2021 23:57:00 +0200 Subject: [PATCH 08/80] DX: use PHP 8.1 polyfill --- composer.json | 3 ++- src/Console/Command/HelpCommand.php | 17 +---------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 2f8600d42da..c665a720217 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "symfony/filesystem": "^4.4.20 || ^5.0", "symfony/finder": "^4.4.20 || ^5.0", "symfony/options-resolver": "^4.4.20 || ^5.0", - "symfony/polyfill-php72": "^1.22", + "symfony/polyfill-php72": "^1.23", + "symfony/polyfill-php81": "^1.23", "symfony/process": "^4.4.20 || ^5.0", "symfony/stopwatch": "^4.4.20 || ^5.0" }, diff --git a/src/Console/Command/HelpCommand.php b/src/Console/Command/HelpCommand.php index 280d8e09aa5..585dc69fb4c 100644 --- a/src/Console/Command/HelpCommand.php +++ b/src/Console/Command/HelpCommand.php @@ -106,7 +106,7 @@ private static function arrayToString(array $value): string return '[]'; } - $isHash = static::isHash($value); + $isHash = !array_is_list($value); $str = '['; foreach ($value as $k => $v) { @@ -122,19 +122,4 @@ private static function arrayToString(array $value): string return substr($str, 0, -2).']'; } - - private static function isHash(array $array): bool - { - $i = 0; - - foreach ($array as $k => $v) { - if ($k !== $i) { - return true; - } - - ++$i; - } - - return false; - } } From bc656ec721be21ff0fb51b129d2676523dd70e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sat, 28 Aug 2021 00:59:42 +0200 Subject: [PATCH 09/80] DX: Use "yield from" in tests --- UPGRADE-v3.md | 4 +-- composer.json | 3 +- doc/usage.rst | 2 +- src/Console/Command/HelpCommand.php | 17 +--------- src/Fixer/Phpdoc/PhpdocTagTypeFixer.php | 20 ++++++----- .../Alias/PowToExponentiationFixerTest.php | 6 +--- .../ModernizeTypesCastingFixerTest.php | 6 +--- .../ClassDefinitionFixerTest.php | 6 +--- .../NoUnneededCurlyBracesFixerTest.php | 6 +--- .../NoUselessElseFixerTest.php | 12 ++----- .../SwitchCaseSemicolonToColonFixerTest.php | 6 +--- .../SwitchCaseSpaceFixerTest.php | 6 +--- .../SwitchContinueToBreakFixerTest.php | 6 +--- .../ControlStructure/YodaStyleFixerTest.php | 6 +--- .../LambdaNotUsedImportFixerTest.php | 6 +--- .../NativeFunctionInvocationFixerTest.php | 6 +--- .../NoSpacesAfterFunctionNameFixerTest.php | 6 +--- .../PhpdocToReturnTypeFixerTest.php | 6 +--- .../CombineConsecutiveUnsetsFixerTest.php | 6 +--- .../ErrorSuppressionFixerTest.php | 6 +--- .../NoUnsetOnPropertyFixerTest.php | 12 ++----- .../Fixer/Operator/NewWithBracesFixerTest.php | 6 +--- .../StandardizeIncrementFixerTest.php | 6 +--- .../TernaryToNullCoalescingFixerTest.php | 6 +--- tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php | 34 +++++++++++++++++++ .../Semicolon/NoEmptyStatementFixerTest.php | 6 +--- .../SemicolonAfterInstructionFixerTest.php | 6 +--- .../Whitespace/NoExtraBlankLinesFixerTest.php | 6 +--- .../NoSpacesAroundOffsetFixerTest.php | 6 +--- .../NoTrailingWhitespaceFixerTest.php | 6 +--- .../Analyzer/FunctionsAnalyzerTest.php | 12 ++----- .../Analyzer/GotoLabelAnalyzerTest.php | 6 +--- tests/Tokenizer/TokenTest.php | 12 ++----- tests/Tokenizer/TokensTest.php | 6 +--- 34 files changed, 83 insertions(+), 189 deletions(-) diff --git a/UPGRADE-v3.md b/UPGRADE-v3.md index 6ff787919b2..dd27c882d0e 100644 --- a/UPGRADE-v3.md +++ b/UPGRADE-v3.md @@ -157,8 +157,8 @@ Code BC changes - class `Token` is now `final` - class `Tokens` is now `final` -- method `create` of class `Config` has been removed, use the constructor -- method `create` of class `RuleSet` has been removed, use the constructor +- method `create` of class `Config` has been removed, [use the constructor](./doc/config.rst) +- method `create` of class `RuleSet` has been removed, [use the constructor](./doc/custom_rules.rst) ### BC breaks; common internal classes diff --git a/composer.json b/composer.json index 2f8600d42da..c665a720217 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "symfony/filesystem": "^4.4.20 || ^5.0", "symfony/finder": "^4.4.20 || ^5.0", "symfony/options-resolver": "^4.4.20 || ^5.0", - "symfony/polyfill-php72": "^1.22", + "symfony/polyfill-php72": "^1.23", + "symfony/polyfill-php81": "^1.23", "symfony/process": "^4.4.20 || ^5.0", "symfony/stopwatch": "^4.4.20 || ^5.0" }, diff --git a/doc/usage.rst b/doc/usage.rst index c369141ab8c..01e4f6da647 100644 --- a/doc/usage.rst +++ b/doc/usage.rst @@ -133,7 +133,7 @@ The ``--config`` option can be used, like in the ``fix`` command, to tell from w $ php php-cs-fixer.phar list-files --config=.php-cs-fixer.dist.php -The output is build in a form that its easy to use in combination with ``xargs`` command in a linux pipe. +The output is built in a form that its easy to use in combination with ``xargs`` command in a linux pipe. This can be useful e.g. in situations where the caching mechanism might not be available (CI, Docker) and distribute fixing across several processes might speedup the process. diff --git a/src/Console/Command/HelpCommand.php b/src/Console/Command/HelpCommand.php index 280d8e09aa5..585dc69fb4c 100644 --- a/src/Console/Command/HelpCommand.php +++ b/src/Console/Command/HelpCommand.php @@ -106,7 +106,7 @@ private static function arrayToString(array $value): string return '[]'; } - $isHash = static::isHash($value); + $isHash = !array_is_list($value); $str = '['; foreach ($value as $k => $v) { @@ -122,19 +122,4 @@ private static function arrayToString(array $value): string return substr($str, 0, -2).']'; } - - private static function isHash(array $array): bool - { - $i = 0; - - foreach ($array as $k => $v) { - if ($k !== $i) { - return true; - } - - ++$i; - } - - return false; - } } diff --git a/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php b/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php index 03337745520..9cab7e35e5f 100644 --- a/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php @@ -90,21 +90,23 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void return; } + $regularExpression = sprintf( + '/({?@(?:%s).*?(?:(?=\s\*\/)|(?=\n)}?))/i', + implode('|', array_map( + function (string $tag) { + return preg_quote($tag, '/'); + }, + array_keys($this->configuration['tags']) + )) + ); + foreach ($tokens as $index => $token) { if (!$token->isGivenKind(T_DOC_COMMENT)) { continue; } $parts = Preg::split( - sprintf( - '/({?@(?:%s)(?:}|\h.*?(?:}|(?=\R)|(?=\h+\*\/)))?)/i', - implode('|', array_map( - function (string $tag) { - return preg_quote($tag, '/'); - }, - array_keys($this->configuration['tags']) - )) - ), + $regularExpression, $token->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE diff --git a/tests/Fixer/Alias/PowToExponentiationFixerTest.php b/tests/Fixer/Alias/PowToExponentiationFixerTest.php index 3ad1da2ef06..785c007a25b 100644 --- a/tests/Fixer/Alias/PowToExponentiationFixerTest.php +++ b/tests/Fixer/Alias/PowToExponentiationFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null): void public function provideFixCases() { - $tests = [ + yield from [ [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ ' [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { $multiLine = true; $code = ' [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield 'no fixes, offset access syntax with curly braces' => [ 'generateCases($expected, $input); - - foreach ($tests as $index => $test) { - yield $index => $test; - } + yield from $this->generateCases($expected, $input); yield [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID >= 80000) { $cases = [ '$bar = $foo1 ?? throw new \Exception($e);', diff --git a/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php b/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php index 4bcdd875f9a..43bd00bef6d 100644 --- a/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php +++ b/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null): void public function provideFixCases() { - $tests = [ + yield from [ [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ ' [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 70000) { yield 'simple case' => [ ' $test) { - yield $index => $test; - } - $template = ' [ '', ], @@ -181,10 +181,6 @@ public function provideDoNotFixCases() ], ]; - foreach ($tests as $index => $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 70100) { yield 'super global, invalid from PHP7.1' => [ '', diff --git a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php index 517c9d9d071..1dd399cf9e9 100644 --- a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php +++ b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php @@ -473,7 +473,7 @@ public function testFixWithConfiguredInclude(string $expected, ?string $input = public function provideFixWithConfiguredIncludeCases() { - $tests = [ + yield from [ 'include set + 1, exclude 1' => [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield 'include @compiler_optimized with strict enabled' => [ ' [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield 'test dynamic by array, curly mix' => [ ' [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield 'report static as self' => [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ '', ], @@ -116,10 +116,6 @@ public function provideFixCases() ], ]; - foreach ($tests as $index => $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ '', diff --git a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php index f76ca9600dc..a775b65b785 100644 --- a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php +++ b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null): void public function provideFixCases() { - $tests = [ + yield from [ 'It replaces an unset on a property with = null' => [ 'bar = null;', 'bar);', @@ -108,10 +108,6 @@ public function provideFixCases() ], ]; - foreach ($tests as $index => $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield 'It does not replace unsets on arrays with special notation' => [ 'foo{0});', @@ -145,7 +141,7 @@ public function testFix73(string $expected, ?string $input = null): void public function provideFix73Cases() { - $tests = [ + yield from [ 'It replaces an unset on a property with = null' => [ 'bar = null;', 'bar,);', @@ -226,10 +222,6 @@ public function provideFix73Cases() ], ]; - foreach ($tests as $index => $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield 'It does not replace unsets on arrays with special notation' => [ 'foo{0},);', diff --git a/tests/Fixer/Operator/NewWithBracesFixerTest.php b/tests/Fixer/Operator/NewWithBracesFixerTest.php index e97373ebc05..a20daf91ca4 100644 --- a/tests/Fixer/Operator/NewWithBracesFixerTest.php +++ b/tests/Fixer/Operator/NewWithBracesFixerTest.php @@ -44,7 +44,7 @@ public function testFix70(string $expected, ?string $input = null): void public function provideFixCases() { - $tests = [ + yield from [ [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ '{$bar};', diff --git a/tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php b/tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php index bd62cfffc24..cf7f758790a 100644 --- a/tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php +++ b/tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null): void public function provideFixCases() { - $tests = [ + yield from [ // Do not fix cases. [' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [' $test) { - yield $index => $test; - } - foreach (['break', 'continue'] as $ops) { yield [ sprintf(' [ '', '', @@ -83,10 +83,6 @@ public function provideFixCases() ], ]; - foreach ($tests as $index => $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ '', diff --git a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php index 20deb0a4786..59e64dc8579 100644 --- a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php +++ b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php @@ -756,7 +756,7 @@ public function testOneOrInLineCases(string $expected, ?string $input = null): v public function provideOneAndInLineCases() { - $tests = [ + yield from [ [ " $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ " $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID >= 80000) { yield [ ' new ArgumentAnalysis( @@ -485,10 +485,6 @@ public function provideFunctionsWithArgumentsCases() ]], ]; - foreach ($tests as $index => $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [' new ArgumentAnalysis( @@ -535,7 +531,7 @@ public function testFunctionArgumentInfoPhp74(string $code, int $methodIndex, ar public function provideFunctionsWithArgumentsPhp74Cases() { - $tests = [ + yield from [ [' null;', 1, []], [' null;', 1, [ '$a' => new ArgumentAnalysis( @@ -617,10 +613,6 @@ public function provideFunctionsWithArgumentsPhp74Cases() ]], ]; - foreach ($tests as $index => $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID < 80000) { yield [' null;', 1, [ '$a' => new ArgumentAnalysis( diff --git a/tests/Tokenizer/Analyzer/GotoLabelAnalyzerTest.php b/tests/Tokenizer/Analyzer/GotoLabelAnalyzerTest.php index ae8ea5bbaae..beb235105ea 100644 --- a/tests/Tokenizer/Analyzer/GotoLabelAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/GotoLabelAnalyzerTest.php @@ -45,7 +45,7 @@ public function testGotoLabelAnalyzerTest(string $source, array $expectedTrue): public function provideIsClassyInvocationCases() { - $tests = [ + yield from [ 'no candidates' => [ ' $test) { - yield $index => $test; - } - if (\PHP_VERSION_ID >= 80000) { yield [ 'getBraceToken(), false], [$this->getForeachToken(), false], [new Token([T_COMMENT, '/* comment */', 1]), true], [new Token([T_DOC_COMMENT, '/** docs */', 1]), true], ]; - foreach ($tests as $index => $test) { - yield $index => $test; - } - // @TODO: drop condition when PHP 8.0+ is required if (\defined('T_ATTRIBUTE')) { yield [new Token([T_ATTRIBUTE, '#[', 1]), false]; @@ -146,7 +142,7 @@ public function testIsObjectOperator(Token $token, bool $isObjectOperator): void public function provideIsObjectOperatorCases() { - $tests = [ + yield from [ [$this->getBraceToken(), false], [$this->getForeachToken(), false], [new Token([T_COMMENT, '/* comment */']), false], @@ -154,10 +150,6 @@ public function provideIsObjectOperatorCases() [new Token([T_OBJECT_OPERATOR, '->']), true], ]; - foreach ($tests as $index => $test) { - yield $index => $test; - } - if (\defined('T_NULLSAFE_OBJECT_OPERATOR')) { yield [new Token([T_NULLSAFE_OBJECT_OPERATOR, '?->']), true]; } diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index a15f44939c6..ab71ce0143b 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -301,7 +301,7 @@ public function provideFindSequenceExceptionCases() { $emptyToken = new Token(''); - $tests = [ + return [ ['Invalid sequence.', []], [ 'Non-meaningful token at position: "0".', @@ -316,10 +316,6 @@ public function provideFindSequenceExceptionCases() ['{', '!', $emptyToken, '}'], ], ]; - - foreach ($tests as $index => $test) { - yield $index => $test; - } } public function testClearRange(): void From 11b988b9d9627f6c34dd9ed7a7985b8a0f5607e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Thu, 12 Aug 2021 21:52:07 +0200 Subject: [PATCH 10/80] CurlyBraceTransformer - fix handling dynamic property with string with variable --- src/Tokenizer/Tokens.php | 2 - .../Transformer/CurlyBraceTransformer.php | 50 +++++++++++++++++-- tests/Tokenizer/TokensTest.php | 1 + .../Transformer/CurlyBraceTransformerTest.php | 9 ++++ 4 files changed, 56 insertions(+), 6 deletions(-) diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index 2873ded078e..f19aae0ba3a 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -1243,8 +1243,6 @@ private function findOppositeBlockEdge(int $type, int $searchIndex, bool $findEn if (0 === $blockLevel) { break; } - - continue; } } diff --git a/src/Tokenizer/Transformer/CurlyBraceTransformer.php b/src/Tokenizer/Transformer/CurlyBraceTransformer.php index e8122f39692..abc4429893d 100644 --- a/src/Tokenizer/Transformer/CurlyBraceTransformer.php +++ b/src/Tokenizer/Transformer/CurlyBraceTransformer.php @@ -131,7 +131,7 @@ private function transformIntoDynamicPropBraces(Tokens $tokens, Token $token, in } $openIndex = $index + 1; - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openIndex); + $closeIndex = $this->naivelyFindCurlyBlockEnd($tokens, $openIndex); $tokens[$openIndex] = new Token([CT::T_DYNAMIC_PROP_BRACE_OPEN, '{']); $tokens[$closeIndex] = new Token([CT::T_DYNAMIC_PROP_BRACE_CLOSE, '}']); @@ -155,7 +155,7 @@ private function transformIntoDynamicVarBraces(Tokens $tokens, Token $token, int return; } - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openIndex); + $closeIndex = $this->naivelyFindCurlyBlockEnd($tokens, $openIndex); $tokens[$openIndex] = new Token([CT::T_DYNAMIC_VAR_BRACE_OPEN, '{']); $tokens[$closeIndex] = new Token([CT::T_DYNAMIC_VAR_BRACE_CLOSE, '}']); @@ -195,7 +195,7 @@ private function transformIntoCurlyIndexBraces(Tokens $tokens, Token $token, int return; } - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $closeIndex = $this->naivelyFindCurlyBlockEnd($tokens, $index); $tokens[$index] = new Token([CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN, '{']); $tokens[$closeIndex] = new Token([CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE, '}']); @@ -213,9 +213,51 @@ private function transformIntoGroupUseBraces(Tokens $tokens, Token $token, int $ return; } - $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $closeIndex = $this->naivelyFindCurlyBlockEnd($tokens, $index); $tokens[$index] = new Token([CT::T_GROUP_IMPORT_BRACE_OPEN, '{']); $tokens[$closeIndex] = new Token([CT::T_GROUP_IMPORT_BRACE_CLOSE, '}']); } + + /** + * We do not want to rely on `$tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index)` here, + * as it relies on block types that are assuming that `}` tokens are already transformed to Custom Tokens that are allowing to distinguish different block types. + * As we are just about to transform `{` and `}` into Custom Tokens by this transformer, thus we need to compare those tokens manually by content without using `Tokens::findBlockEnd`. + */ + private function naivelyFindCurlyBlockEnd(Tokens $tokens, int $startIndex): int + { + if (!$tokens->offsetExists($startIndex)) { + throw new \OutOfBoundsException(sprintf('Unavailable index: "%s".', $startIndex)); + } + + if ('{' !== $tokens[$startIndex]->getContent()) { + throw new \InvalidArgumentException(sprintf('Wrong start index: "%s".', $startIndex)); + } + + $blockLevel = 1; + $endIndex = $tokens->count() - 1; + for ($index = $startIndex + 1; $index !== $endIndex; ++$index) { + $token = $tokens[$index]; + + if ('{' === $token->getContent()) { + ++$blockLevel; + + continue; + } + + if ('}' === $token->getContent()) { + --$blockLevel; + + if (0 === $blockLevel) { + if (!$token->equals('}')) { + throw new \UnexpectedValueException(sprintf('Detected block end for index: "%s" was already transformed into other token type: "%s".', $startIndex, $token->getName())); + } + + return $index; + } + } + } + + throw new \UnexpectedValueException(sprintf('Missing block end for index: "%s".', $startIndex)); + } } diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index ab71ce0143b..b71280377fa 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -693,6 +693,7 @@ public function provideFindBlockEndCases() [4, '', Tokens::BLOCK_TYPE_CURLY_BRACE, 5], [11, '{"set_{$name}"}(42);', Tokens::BLOCK_TYPE_DYNAMIC_PROP_BRACE, 3], [19, ' [' [ + '{"set_{$name}"}(42);', + [ + 3 => CT::T_DYNAMIC_PROP_BRACE_OPEN, + 6 => T_CURLY_OPEN, + 8 => CT::T_CURLY_CLOSE, + 10 => CT::T_DYNAMIC_PROP_BRACE_CLOSE, + ], + ], ]; } From eec2de4405efb7111d42163f383cc900cd744a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Mon, 24 May 2021 20:18:35 +0200 Subject: [PATCH 11/80] Add TypesSpacesFixer --- doc/ruleSets/Symfony.rst | 1 + doc/rules/index.rst | 2 + doc/rules/whitespace/types_spaces.rst | 80 +++++++++++ src/Fixer/Whitespace/TypesSpacesFixer.php | 126 +++++++++++++++++ src/RuleSet/Sets/SymfonySet.php | 1 + .../Fixer/Whitespace/TypesSpacesFixerTest.php | 132 ++++++++++++++++++ tests/Fixtures/Integration/misc/PHP7_1.test | 2 +- tests/Fixtures/Integration/misc/PHP8_0.test | 4 +- 8 files changed, 345 insertions(+), 3 deletions(-) create mode 100644 doc/rules/whitespace/types_spaces.rst create mode 100644 src/Fixer/Whitespace/TypesSpacesFixer.php create mode 100644 tests/Fixer/Whitespace/TypesSpacesFixerTest.php diff --git a/doc/ruleSets/Symfony.rst b/doc/ruleSets/Symfony.rst index ee27a504204..5cfd476feea 100644 --- a/doc/ruleSets/Symfony.rst +++ b/doc/ruleSets/Symfony.rst @@ -119,6 +119,7 @@ Rules - `switch_continue_to_break <./../rules/control_structure/switch_continue_to_break.rst>`_ - `trailing_comma_in_multiline <./../rules/control_structure/trailing_comma_in_multiline.rst>`_ - `trim_array_spaces <./../rules/array_notation/trim_array_spaces.rst>`_ +- `types_spaces <./../rules/whitespace/types_spaces.rst>`_ - `unary_operator_spaces <./../rules/operator/unary_operator_spaces.rst>`_ - `whitespace_after_comma_in_array <./../rules/array_notation/whitespace_after_comma_in_array.rst>`_ - `yoda_style <./../rules/control_structure/yoda_style.rst>`_ diff --git a/doc/rules/index.rst b/doc/rules/index.rst index 823c12d6f11..98e7b0402a5 100644 --- a/doc/rules/index.rst +++ b/doc/rules/index.rst @@ -565,3 +565,5 @@ Whitespace Remove trailing whitespace at the end of blank lines. - `single_blank_line_at_eof <./whitespace/single_blank_line_at_eof.rst>`_ A PHP file without end tag must always end with a single empty line feed. +- `types_spaces <./whitespace/types_spaces.rst>`_ + A single space or none should be around union type operator. diff --git a/doc/rules/whitespace/types_spaces.rst b/doc/rules/whitespace/types_spaces.rst new file mode 100644 index 00000000000..7fc086d345c --- /dev/null +++ b/doc/rules/whitespace/types_spaces.rst @@ -0,0 +1,80 @@ +===================== +Rule ``types_spaces`` +===================== + +A single space or none should be around union type operator. + +Configuration +------------- + +``space`` +~~~~~~~~~ + +spacing to apply around union type operator. + +Allowed values: ``'none'``, ``'single'`` + +Default value: ``'none'`` + +Examples +-------- + +Example #1 +~~~~~~~~~~ + +*Default* configuration. + +.. code-block:: diff + + --- Original + +++ New + 'single']``. + +.. code-block:: diff + + --- Original + +++ New + `_ rule set will enable the ``types_spaces`` rule with the default config. + +@Symfony + Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``types_spaces`` rule with the default config. diff --git a/src/Fixer/Whitespace/TypesSpacesFixer.php b/src/Fixer/Whitespace/TypesSpacesFixer.php new file mode 100644 index 00000000000..b2b18775fd6 --- /dev/null +++ b/src/Fixer/Whitespace/TypesSpacesFixer.php @@ -0,0 +1,126 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Fixer\Whitespace; + +use PhpCsFixer\AbstractFixer; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; +use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; +use PhpCsFixer\FixerDefinition\CodeSample; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\FixerDefinition\VersionSpecification; +use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; +use PhpCsFixer\Preg; +use PhpCsFixer\Tokenizer\CT; +use PhpCsFixer\Tokenizer\Token; +use PhpCsFixer\Tokenizer\Tokens; + +final class TypesSpacesFixer extends AbstractFixer implements ConfigurableFixerInterface +{ + /** + * {@inheritdoc} + */ + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition( + 'A single space or none should be around union type operator.', + [ + new CodeSample( + " 'single'] + ), + new VersionSpecificCodeSample( + "isTokenKindFound(CT::T_TYPE_ALTERNATION); + } + + /** + * {@inheritdoc} + */ + protected function createConfigurationDefinition(): FixerConfigurationResolverInterface + { + return new FixerConfigurationResolver([ + (new FixerOptionBuilder('space', 'spacing to apply around union type operator.')) + ->setAllowedValues(['none', 'single']) + ->setDefault('none') + ->getOption(), + ]); + } + + protected function applyFix(\SplFileInfo $file, Tokens $tokens): void + { + for ($index = $tokens->count() - 1; $index > 0; --$index) { + if (!$tokens[$index]->isGivenKind(CT::T_TYPE_ALTERNATION)) { + continue; + } + + if ('single' === $this->configuration['space']) { + $this->ensureSingleSpace($tokens, $index + 1, 0); + $this->ensureSingleSpace($tokens, $index - 1, 1); + } else { + $this->ensureNoSpace($tokens, $index + 1); + $this->ensureNoSpace($tokens, $index - 1); + } + } + } + + private function ensureSingleSpace(Tokens $tokens, int $index, int $offset): void + { + if (!$tokens[$index]->isWhitespace()) { + $tokens->insertSlices([$index + $offset => new Token([T_WHITESPACE, ' '])]); + + return; + } + + if (' ' === $tokens[$index]->getContent()) { + return; + } + + if (1 === Preg::match('/\R/', $tokens[$index]->getContent())) { + return; + } + + $tokens[$index] = new Token([T_WHITESPACE, ' ']); + } + + private function ensureNoSpace(Tokens $tokens, int $index): void + { + if (!$tokens[$index]->isWhitespace()) { + return; + } + + if (1 === Preg::match('/\R/', $tokens[$index]->getContent())) { + return; + } + + $tokens->clearAt($index); + } +} diff --git a/src/RuleSet/Sets/SymfonySet.php b/src/RuleSet/Sets/SymfonySet.php index 5a58b6fc6ec..e153c88bebd 100644 --- a/src/RuleSet/Sets/SymfonySet.php +++ b/src/RuleSet/Sets/SymfonySet.php @@ -170,6 +170,7 @@ public function getRules(): array 'switch_continue_to_break' => true, 'trailing_comma_in_multiline' => true, 'trim_array_spaces' => true, + 'types_spaces' => true, 'unary_operator_spaces' => true, 'whitespace_after_comma_in_array' => true, 'yoda_style' => true, diff --git a/tests/Fixer/Whitespace/TypesSpacesFixerTest.php b/tests/Fixer/Whitespace/TypesSpacesFixerTest.php new file mode 100644 index 00000000000..e4fe1f35fde --- /dev/null +++ b/tests/Fixer/Whitespace/TypesSpacesFixerTest.php @@ -0,0 +1,132 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Fixer\Whitespace; + +use PhpCsFixer\Tests\Test\AbstractFixerTestCase; + +/** + * @internal + * + * @covers \PhpCsFixer\Fixer\Whitespace\TypesSpacesFixer + */ +final class TypesSpacesFixerTest extends AbstractFixerTestCase +{ + /** + * @dataProvider provideFixCases + * @requires PHP 7.1 + */ + public function testFix(string $expected, ?string $input = null, array $configuration = []): void + { + $this->fixer->configure($configuration); + $this->doTest($expected, $input); + } + + public function provideFixCases() + { + yield [ + ' 'single'], + ]; + + yield [ + ' 'single'], + ]; + } + + /** + * @dataProvider provideFix80Cases + * @requires PHP 8.0 + */ + public function testFix80(string $expected, ?string $input = null, array $configuration = []): void + { + $this->fixer->configure($configuration); + $this->doTest($expected, $input); + } + + public function provideFix80Cases() + { + yield [ + ' 'single'], + ]; + + yield [ + ' 'single'], + ]; + + yield [ + ' 'single'], + ]; + } +} diff --git a/tests/Fixtures/Integration/misc/PHP7_1.test b/tests/Fixtures/Integration/misc/PHP7_1.test index cf4656f1ac3..757abadd270 100644 --- a/tests/Fixtures/Integration/misc/PHP7_1.test +++ b/tests/Fixtures/Integration/misc/PHP7_1.test @@ -14,7 +14,7 @@ function iterable_foo(iterable $foo): void try { $str = 'abcdef'; echo $str[-2]; - } catch (ExceptionType1 | ExceptionType2 $e) { + } catch (ExceptionType1|ExceptionType2 $e) { // Code to handle the exception } catch (\Exception $e) { // ... diff --git a/tests/Fixtures/Integration/misc/PHP8_0.test b/tests/Fixtures/Integration/misc/PHP8_0.test index f5b21fd4268..b2f80daaee3 100644 --- a/tests/Fixtures/Integration/misc/PHP8_0.test +++ b/tests/Fixtures/Integration/misc/PHP8_0.test @@ -59,12 +59,12 @@ class Number { private int|float|null $number; - public function setNumber(int | float $number): void + public function setNumber(int|float $number): void { $this->number = $number; } - public function getNumber(): int|float | null + public function getNumber(): int|float|null { return $this->number; } From 2bd7b63b0ac59fb72e3074336cc3e63000a04af5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Thu, 5 Aug 2021 22:31:03 +0200 Subject: [PATCH 12/80] Add AttributeAnalyzer --- src/Tokenizer/Analyzer/AttributeAnalyzer.php | 70 ++++++++++++ .../Analyzer/AttributeAnalyzerTest.php | 100 ++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 src/Tokenizer/Analyzer/AttributeAnalyzer.php create mode 100644 tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php diff --git a/src/Tokenizer/Analyzer/AttributeAnalyzer.php b/src/Tokenizer/Analyzer/AttributeAnalyzer.php new file mode 100644 index 00000000000..c67b76bc525 --- /dev/null +++ b/src/Tokenizer/Analyzer/AttributeAnalyzer.php @@ -0,0 +1,70 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tokenizer\Analyzer; + +use PhpCsFixer\Tokenizer\CT; +use PhpCsFixer\Tokenizer\Tokens; + +/** + * @internal + */ +final class AttributeAnalyzer +{ + private const TOKEN_KINDS_NOT_ALLOWED_IN_ATTRIBUTE = [ + ';', + '{', + [T_ATTRIBUTE], + [T_FUNCTION], + [T_OPEN_TAG], + [T_OPEN_TAG_WITH_ECHO], + [T_PRIVATE], + [T_PROTECTED], + [T_PUBLIC], + [T_RETURN], + [T_VARIABLE], + [CT::T_ATTRIBUTE_CLOSE], + ]; + + /** + * Check if given index is an attribute declaration. + */ + public static function isAttribute(Tokens $tokens, int $index): bool + { + if ( + !\defined('T_ATTRIBUTE') // attributes not available, PHP version lower than 8.0 + || !$tokens[$index]->isGivenKind(T_STRING) // checked token is not a string + || !$tokens->isAnyTokenKindsFound([T_ATTRIBUTE]) // no attributes in the tokens collection + ) { + return false; + } + + $attributeStartIndex = $tokens->getPrevTokenOfKind($index, self::TOKEN_KINDS_NOT_ALLOWED_IN_ATTRIBUTE); + if (!$tokens[$attributeStartIndex]->isGivenKind(T_ATTRIBUTE)) { + return false; + } + + // now, between attribute start and the attribute candidate index cannot be more "(" than ")" + $count = 0; + for ($i = $attributeStartIndex + 1; $i < $index; ++$i) { + if ($tokens[$i]->equals('(')) { + ++$count; + } elseif ($tokens[$i]->equals(')')) { + --$count; + } + } + + return 0 === $count; + } +} diff --git a/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php b/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php new file mode 100644 index 00000000000..362ea5684de --- /dev/null +++ b/tests/Tokenizer/Analyzer/AttributeAnalyzerTest.php @@ -0,0 +1,100 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Tokenizer\Analyzer; + +use PhpCsFixer\Tests\TestCase; +use PhpCsFixer\Tokenizer\Analyzer\AttributeAnalyzer; +use PhpCsFixer\Tokenizer\Tokens; + +/** + * @internal + * + * @covers \PhpCsFixer\Tokenizer\Analyzer\AttributeAnalyzer + */ +final class AttributeAnalyzerTest extends TestCase +{ + /** + * Check it's not crashing for PHP lower than 8.0 as other tests run for PHP 8.0 only. + */ + public function testNotAnAttribute(): void + { + $tokens = Tokens::fromCode(' $token) { + static::assertFalse(AttributeAnalyzer::isAttribute($tokens, $index)); + } + } + + /** + * @requires PHP 8.0 + * @dataProvider provideIsAttributeCases + */ + public function testIsAttribute(bool $isInAttribute, string $code): void + { + $tokens = Tokens::fromCode($code); + + foreach ($tokens as $index => $token) { + if ($token->equals([T_STRING, 'Foo'])) { + if (isset($testedIndex)) { + static::fail('Test is run against index of "Foo", multiple occurrences found.'); + } + $testedIndex = $index; + } + } + if (!isset($testedIndex)) { + static::fail('Test is run against index of "Foo", but it was not found in the code.'); + } + + static::assertSame($isInAttribute, AttributeAnalyzer::isAttribute($tokens, $testedIndex)); + } + + /** + * Test case requires to having "Foo" as it will be searched for to test its index. + */ + public static function provideIsAttributeCases(): iterable + { + yield [false, ' Date: Sat, 28 Aug 2021 12:43:57 +0200 Subject: [PATCH 13/80] TypeAlternationTransformer - fix for "callable" type --- .../TypeAlternationTransformer.php | 2 +- .../BinaryOperatorSpacesFixerTest.php | 4 ++ tests/Tokenizer/TokensAnalyzerTest.php | 37 +++++++++++++++++++ .../TypeAlternationTransformerTest.php | 15 ++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/src/Tokenizer/Transformer/TypeAlternationTransformer.php b/src/Tokenizer/Transformer/TypeAlternationTransformer.php index a407c63178e..9ebf9176d43 100644 --- a/src/Tokenizer/Transformer/TypeAlternationTransformer.php +++ b/src/Tokenizer/Transformer/TypeAlternationTransformer.php @@ -55,7 +55,7 @@ public function process(Tokens $tokens, Token $token, int $index): void return; } - $prevIndex = $tokens->getTokenNotOfKindsSibling($index, -1, [T_NS_SEPARATOR, T_STRING, CT::T_ARRAY_TYPEHINT, T_WHITESPACE, T_COMMENT, T_DOC_COMMENT]); + $prevIndex = $tokens->getTokenNotOfKindsSibling($index, -1, [T_CALLABLE, T_NS_SEPARATOR, T_STRING, CT::T_ARRAY_TYPEHINT, T_WHITESPACE, T_COMMENT, T_DOC_COMMENT]); /** @var Token $prevToken */ $prevToken = $tokens[$prevIndex]; diff --git a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php index 732d3dfb5b9..0b7d459b4d9 100644 --- a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php +++ b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php @@ -2052,6 +2052,10 @@ class Foo public function bar(TypeA | TypeB|TypeC $x): TypeA|TypeB | TypeC|TypeD { } + public function baz( + callable|array $a, + array|callable $b, + ) {} }' ); } diff --git a/tests/Tokenizer/TokensAnalyzerTest.php b/tests/Tokenizer/TokensAnalyzerTest.php index f0de9238fa5..10982b5ec0c 100644 --- a/tests/Tokenizer/TokensAnalyzerTest.php +++ b/tests/Tokenizer/TokensAnalyzerTest.php @@ -1505,6 +1505,43 @@ public function provideIsBinaryOperator74Cases() ]; } + /** + * @dataProvider provideIsBinaryOperator80Cases + * @requires PHP 8.0 + */ + public function testIsBinaryOperator80(string $source, array $expected): void + { + $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); + + foreach ($expected as $index => $isBinary) { + static::assertSame($isBinary, $tokensAnalyzer->isBinaryOperator($index)); + if ($isBinary) { + static::assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index)); + static::assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index)); + } + } + } + + public static function provideIsBinaryOperator80Cases(): iterable + { + yield [ + ' false], + ]; + yield [ + ' false], + ]; + yield [ + ' false], + ]; + yield [ + ' false], + ]; + } + /** * @dataProvider provideArrayExceptionsCases */ diff --git a/tests/Tokenizer/Transformer/TypeAlternationTransformerTest.php b/tests/Tokenizer/Transformer/TypeAlternationTransformerTest.php index f044628defb..8e7399bc179 100644 --- a/tests/Tokenizer/Transformer/TypeAlternationTransformerTest.php +++ b/tests/Tokenizer/Transformer/TypeAlternationTransformerTest.php @@ -282,5 +282,20 @@ function f4(A|B $x, C|D $y, E|F $z) {}; 66 => CT::T_TYPE_ALTERNATION, ], ]; + + yield 'callable type' => [ + ' CT::T_TYPE_ALTERNATION, + 22 => CT::T_TYPE_ALTERNATION, + 37 => CT::T_TYPE_ALTERNATION, + 52 => CT::T_TYPE_ALTERNATION, + ], + ]; } } From 9711c2bb7ea2978d77e174abc6a49380339b37a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Fri, 17 Apr 2020 17:03:33 +0200 Subject: [PATCH 14/80] PhpdocAlignFixer - fix for whitespace in type --- src/Fixer/Phpdoc/PhpdocAlignFixer.php | 16 ++++++----- tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php | 32 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/Fixer/Phpdoc/PhpdocAlignFixer.php b/src/Fixer/Phpdoc/PhpdocAlignFixer.php index 822bcb9f281..2ed92d525cf 100644 --- a/src/Fixer/Phpdoc/PhpdocAlignFixer.php +++ b/src/Fixer/Phpdoc/PhpdocAlignFixer.php @@ -16,6 +16,7 @@ use PhpCsFixer\AbstractFixer; use PhpCsFixer\DocBlock\DocBlock; +use PhpCsFixer\DocBlock\TypeExpression; use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface; use PhpCsFixer\FixerConfiguration\AllowedValueSubset; @@ -96,26 +97,27 @@ public function configure(array $configuration): void $tagsWithoutNameToAlign = array_diff($this->configuration['tags'], $tagsWithNameToAlign, $tagsWithMethodSignatureToAlign); $types = []; - $indent = '(?P(?: {2}|\t)*)'; + $indent = '(?P(?:\ {2}|\t)*)'; + // e.g. @param <$var> - if (!empty($tagsWithNameToAlign)) { - $types[] = '(?P'.implode('|', $tagsWithNameToAlign).')\s+(?P[^$]+?)\s+(?P(?:&|\.{3})?\$[^\s]+)'; + if ([] !== $tagsWithNameToAlign) { + $types[] = '(?P'.implode('|', $tagsWithNameToAlign).')\s+(?P(?:'.TypeExpression::REGEX_TYPES.')?)\s+(?P(?:&|\.{3})?\$\S+)'; } // e.g. @return - if (!empty($tagsWithoutNameToAlign)) { - $types[] = '(?P'.implode('|', $tagsWithoutNameToAlign).')\s+(?P[^\s]+?)'; + if ([] !== $tagsWithoutNameToAlign) { + $types[] = '(?P'.implode('|', $tagsWithoutNameToAlign).')\s+(?P(?:'.TypeExpression::REGEX_TYPES.')?)'; } // e.g. @method - if (!empty($tagsWithMethodSignatureToAlign)) { + if ([] !== $tagsWithMethodSignatureToAlign) { $types[] = '(?P'.implode('|', $tagsWithMethodSignatureToAlign).')(\s+(?P[^\s(]+)|)\s+(?P.+\))'; } // optional $desc = '(?:\s+(?P\V*))'; - $this->regex = '/^'.$indent.' \* @(?:'.implode('|', $types).')'.$desc.'\s*$/u'; + $this->regex = '/^'.$indent.'\ \*\ @(?J)(?:'.implode('|', $types).')'.$desc.'\s*$/ux'; $this->regexCommentLine = '/^'.$indent.' \*(?! @)(?:\s+(?P\V+))(?align = $this->configuration['align']; } diff --git a/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php index e24c0e71857..9b8772ee229 100644 --- a/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php @@ -1286,4 +1286,36 @@ public function provideInvalidPhpdocCases() ], ]; } + + public function testTypesContainingCallables(): void + { + $this->doTest( + 'doTest(' $value + */ + /** + * @param array $arrayOfIntegers + * @param array $arrayOfStrings + */ + '); + } } From a2f9c23b2300657eaeeddaa5465b80c55d3ff9db Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Fri, 28 May 2021 18:02:01 +0200 Subject: [PATCH 15/80] Extract DeclareBracesFixer from BracesFixer --- doc/rules/index.rst | 2 + .../language_construct/declare_braces.rst | 18 ++++++ src/Fixer/Basic/BracesFixer.php | 51 ++++++----------- .../LanguageConstruct/DeclareBracesFixer.php | 56 ++++++++++++++++++ .../DeclareBracesFixerTest.php | 57 +++++++++++++++++++ 5 files changed, 149 insertions(+), 35 deletions(-) create mode 100644 doc/rules/language_construct/declare_braces.rst create mode 100644 src/Fixer/LanguageConstruct/DeclareBracesFixer.php create mode 100644 tests/Fixer/LanguageConstruct/DeclareBracesFixerTest.php diff --git a/doc/rules/index.rst b/doc/rules/index.rst index 823c12d6f11..816a9d0d9cb 100644 --- a/doc/rules/index.rst +++ b/doc/rules/index.rst @@ -283,6 +283,8 @@ Language Construct Using ``isset($var) &&`` multiple times should be done in one call. - `combine_consecutive_unsets <./language_construct/combine_consecutive_unsets.rst>`_ Calling ``unset`` on multiple items should be done in one call. +- `declare_braces <./language_construct/declare_braces.rst>`_ + There must not be spaces around ``declare`` statement braces. - `declare_equal_normalize <./language_construct/declare_equal_normalize.rst>`_ Equal sign in declare statement should be surrounded by spaces or not following configuration. - `dir_constant <./language_construct/dir_constant.rst>`_ *(risky)* diff --git a/doc/rules/language_construct/declare_braces.rst b/doc/rules/language_construct/declare_braces.rst new file mode 100644 index 00000000000..80d071057d4 --- /dev/null +++ b/doc/rules/language_construct/declare_braces.rst @@ -0,0 +1,18 @@ +======================= +Rule ``declare_braces`` +======================= + +There must not be spaces around ``declare`` statement braces. + +Examples +-------- + +Example #1 +~~~~~~~~~~ + +.. code-block:: diff + + --- Original + +++ New + - */ -final class BracesFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface +final class BracesFixer extends AbstractProxyFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { /** * @internal @@ -156,6 +157,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $this->fixControlContinuationBraces($tokens); $this->fixSpaceAroundToken($tokens); $this->fixDoWhile($tokens); + + parent::applyFix($file, $tokens); } /** @@ -187,6 +190,13 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ]); } + protected function createProxyFixers(): array + { + return [ + new DeclareBracesFixer(), + ]; + } + private function fixCommentBeforeBrace(Tokens $tokens): void { $tokensAnalyzer = new TokensAnalyzer($tokens); @@ -697,8 +707,10 @@ private function fixSpaceAroundToken(Tokens $tokens): void // Declare tokens don't follow the same rules are other control statements if ($token->isGivenKind(T_DECLARE)) { - $this->fixDeclareStatement($tokens, $index); - } elseif ($token->isGivenKind($controlTokens) || $token->isGivenKind(CT::T_USE_LAMBDA)) { + continue; // delegated to DeclareBracesFixer + } + + if ($token->isGivenKind($controlTokens) || $token->isGivenKind(CT::T_USE_LAMBDA)) { $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($index); if (!$tokens[$nextNonWhitespaceIndex]->equals(':')) { @@ -869,37 +881,6 @@ private function getFinalControlContinuationTokensForOpeningToken(int $openingTo return []; } - private function fixDeclareStatement(Tokens $tokens, int $index): void - { - $tokens->removeTrailingWhitespace($index); - - $startParenthesisIndex = $tokens->getNextTokenOfKind($index, ['(']); - $tokens->removeTrailingWhitespace($startParenthesisIndex); - - $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex); - $tokens->removeLeadingWhitespace($endParenthesisIndex); - - $startBraceIndex = $tokens->getNextTokenOfKind($endParenthesisIndex, [';', '{']); - $startBraceToken = $tokens[$startBraceIndex]; - - if ($startBraceToken->equals('{')) { - $this->fixSingleLineWhitespaceForDeclare($tokens, $startBraceIndex); - } - } - - private function fixSingleLineWhitespaceForDeclare(Tokens $tokens, int $startBraceIndex): void - { - // fix single-line whitespace before { - // eg: `declare(ticks=1){` => `declare(ticks=1) {` - // eg: `declare(ticks=1) {` => `declare(ticks=1) {` - if ( - !$tokens[$startBraceIndex - 1]->isWhitespace() - || $tokens[$startBraceIndex - 1]->isWhitespace(" \t") - ) { - $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, ' '); - } - } - private function ensureWhitespaceAtIndexAndIndentMultilineComment(Tokens $tokens, int $index, string $whitespace): void { if ($tokens[$index]->isWhitespace()) { diff --git a/src/Fixer/LanguageConstruct/DeclareBracesFixer.php b/src/Fixer/LanguageConstruct/DeclareBracesFixer.php new file mode 100644 index 00000000000..089e57d89eb --- /dev/null +++ b/src/Fixer/LanguageConstruct/DeclareBracesFixer.php @@ -0,0 +1,56 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Fixer\LanguageConstruct; + +use PhpCsFixer\AbstractFixer; +use PhpCsFixer\FixerDefinition\CodeSample; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\Tokens; + +final class DeclareBracesFixer extends AbstractFixer +{ + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition( + 'There must not be spaces around `declare` statement braces.', + [new CodeSample("isTokenKindFound(T_DECLARE); + } + + protected function applyFix(\SplFileInfo $file, Tokens $tokens): void + { + for ($index = $tokens->count() - 1; 0 <= $index; --$index) { + $token = $tokens[$index]; + + if (!$token->isGivenKind(T_DECLARE)) { + continue; + } + + $tokens->removeTrailingWhitespace($index); + + $startParenthesisIndex = $tokens->getNextTokenOfKind($index, ['(']); + $tokens->removeTrailingWhitespace($startParenthesisIndex); + + $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex); + $tokens->removeLeadingWhitespace($endParenthesisIndex); + } + } +} diff --git a/tests/Fixer/LanguageConstruct/DeclareBracesFixerTest.php b/tests/Fixer/LanguageConstruct/DeclareBracesFixerTest.php new file mode 100644 index 00000000000..73420471061 --- /dev/null +++ b/tests/Fixer/LanguageConstruct/DeclareBracesFixerTest.php @@ -0,0 +1,57 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Fixer\LanguageConstruct; + +use PhpCsFixer\Tests\Test\AbstractFixerTestCase; + +/** + * @internal + * + * @covers \PhpCsFixer\Fixer\LanguageConstruct\DeclareBracesFixer + */ +final class DeclareBracesFixerTest extends AbstractFixerTestCase +{ + /** + * @dataProvider provideFixCases + */ + public function testFix(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFixCases() + { + yield 'spaces around parentheses' => [ + ' [ + ' [ + ' Date: Sat, 28 Aug 2021 15:52:43 +0200 Subject: [PATCH 16/80] Deprecate ClassKeywordRemoveFixer --- doc/rules/index.rst | 2 +- .../language_construct/class_keyword_remove.rst | 2 ++ .../LanguageConstruct/ClassKeywordRemoveFixer.php | 13 ++++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/rules/index.rst b/doc/rules/index.rst index 823c12d6f11..ac12a7be1de 100644 --- a/doc/rules/index.rst +++ b/doc/rules/index.rst @@ -277,7 +277,7 @@ Import Language Construct ------------------ -- `class_keyword_remove <./language_construct/class_keyword_remove.rst>`_ +- `class_keyword_remove <./language_construct/class_keyword_remove.rst>`_ *(deprecated)* Converts ``::class`` keywords to FQCN strings. - `combine_consecutive_issets <./language_construct/combine_consecutive_issets.rst>`_ Using ``isset($var) &&`` multiple times should be done in one call. diff --git a/doc/rules/language_construct/class_keyword_remove.rst b/doc/rules/language_construct/class_keyword_remove.rst index efcb8b68811..d59a7e51340 100644 --- a/doc/rules/language_construct/class_keyword_remove.rst +++ b/doc/rules/language_construct/class_keyword_remove.rst @@ -2,6 +2,8 @@ Rule ``class_keyword_remove`` ============================= +.. warning:: This rule is deprecated and will be removed on next major version. + Converts ``::class`` keywords to FQCN strings. Examples diff --git a/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php b/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php index 2a6b8d93b23..dd7b8244333 100644 --- a/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php +++ b/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php @@ -15,6 +15,7 @@ namespace PhpCsFixer\Fixer\LanguageConstruct; use PhpCsFixer\AbstractFixer; +use PhpCsFixer\Fixer\DeprecatedFixerInterface; use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; @@ -25,9 +26,11 @@ use PhpCsFixer\Tokenizer\TokensAnalyzer; /** + * @deprecated + * * @author Sullivan Senechal */ -final class ClassKeywordRemoveFixer extends AbstractFixer +final class ClassKeywordRemoveFixer extends AbstractFixer implements DeprecatedFixerInterface { /** * @var string[] @@ -54,6 +57,14 @@ public function getDefinition(): FixerDefinitionInterface ); } + /** + * {@inheritdoc} + */ + public function getSuccessorsNames(): array + { + return []; + } + /** * {@inheritdoc} * From d2fd18b7519b09503931daf1908303c09f4dd8c4 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sat, 28 Aug 2021 17:05:52 +0200 Subject: [PATCH 17/80] DX: rename DeclareBracesFixer to DeclareParenthesesFixer --- doc/rules/index.rst | 4 ++-- .../{declare_braces.rst => declare_parentheses.rst} | 8 ++++---- src/Fixer/Basic/BracesFixer.php | 6 +++--- ...DeclareBracesFixer.php => DeclareParenthesesFixer.php} | 4 ++-- ...racesFixerTest.php => DeclareParenthesesFixerTest.php} | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) rename doc/rules/language_construct/{declare_braces.rst => declare_parentheses.rst} (51%) rename src/Fixer/LanguageConstruct/{DeclareBracesFixer.php => DeclareParenthesesFixer.php} (95%) rename tests/Fixer/LanguageConstruct/{DeclareBracesFixerTest.php => DeclareParenthesesFixerTest.php} (89%) diff --git a/doc/rules/index.rst b/doc/rules/index.rst index 816a9d0d9cb..2dfaec2e977 100644 --- a/doc/rules/index.rst +++ b/doc/rules/index.rst @@ -283,10 +283,10 @@ Language Construct Using ``isset($var) &&`` multiple times should be done in one call. - `combine_consecutive_unsets <./language_construct/combine_consecutive_unsets.rst>`_ Calling ``unset`` on multiple items should be done in one call. -- `declare_braces <./language_construct/declare_braces.rst>`_ - There must not be spaces around ``declare`` statement braces. - `declare_equal_normalize <./language_construct/declare_equal_normalize.rst>`_ Equal sign in declare statement should be surrounded by spaces or not following configuration. +- `declare_parentheses <./language_construct/declare_parentheses.rst>`_ + There must not be spaces around ``declare`` statement parentheses. - `dir_constant <./language_construct/dir_constant.rst>`_ *(risky)* Replaces ``dirname(__FILE__)`` expression with equivalent ``__DIR__`` constant. - `error_suppression <./language_construct/error_suppression.rst>`_ *(risky)* diff --git a/doc/rules/language_construct/declare_braces.rst b/doc/rules/language_construct/declare_parentheses.rst similarity index 51% rename from doc/rules/language_construct/declare_braces.rst rename to doc/rules/language_construct/declare_parentheses.rst index 80d071057d4..6b63b9369a8 100644 --- a/doc/rules/language_construct/declare_braces.rst +++ b/doc/rules/language_construct/declare_parentheses.rst @@ -1,8 +1,8 @@ -======================= -Rule ``declare_braces`` -======================= +============================ +Rule ``declare_parentheses`` +============================ -There must not be spaces around ``declare`` statement braces. +There must not be spaces around ``declare`` statement parentheses. Examples -------- diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index 778b851af2d..2c26e490d2b 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -16,7 +16,7 @@ use PhpCsFixer\AbstractProxyFixer; use PhpCsFixer\Fixer\ConfigurableFixerInterface; -use PhpCsFixer\Fixer\LanguageConstruct\DeclareBracesFixer; +use PhpCsFixer\Fixer\LanguageConstruct\DeclareParenthesesFixer; use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; @@ -193,7 +193,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn protected function createProxyFixers(): array { return [ - new DeclareBracesFixer(), + new DeclareParenthesesFixer(), ]; } @@ -707,7 +707,7 @@ private function fixSpaceAroundToken(Tokens $tokens): void // Declare tokens don't follow the same rules are other control statements if ($token->isGivenKind(T_DECLARE)) { - continue; // delegated to DeclareBracesFixer + continue; // delegated to DeclareParenthesesFixer } if ($token->isGivenKind($controlTokens) || $token->isGivenKind(CT::T_USE_LAMBDA)) { diff --git a/src/Fixer/LanguageConstruct/DeclareBracesFixer.php b/src/Fixer/LanguageConstruct/DeclareParenthesesFixer.php similarity index 95% rename from src/Fixer/LanguageConstruct/DeclareBracesFixer.php rename to src/Fixer/LanguageConstruct/DeclareParenthesesFixer.php index 089e57d89eb..e3879731018 100644 --- a/src/Fixer/LanguageConstruct/DeclareBracesFixer.php +++ b/src/Fixer/LanguageConstruct/DeclareParenthesesFixer.php @@ -20,12 +20,12 @@ use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; -final class DeclareBracesFixer extends AbstractFixer +final class DeclareParenthesesFixer extends AbstractFixer { public function getDefinition(): FixerDefinitionInterface { return new FixerDefinition( - 'There must not be spaces around `declare` statement braces.', + 'There must not be spaces around `declare` statement parentheses.', [new CodeSample(" Date: Thu, 5 Aug 2021 22:28:22 +0200 Subject: [PATCH 18/80] GlobalNamespaceImportFixer - fix for attributes imported as constants --- src/Tokenizer/Analyzer/ClassyAnalyzer.php | 4 +++ src/Tokenizer/TokensAnalyzer.php | 6 ++-- .../Import/GlobalNamespaceImportFixerTest.php | 35 +++++++++++++++++++ .../Tokenizer/Analyzer/ClassyAnalyzerTest.php | 5 +++ tests/Tokenizer/TokensAnalyzerTest.php | 8 ++--- 5 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/Tokenizer/Analyzer/ClassyAnalyzer.php b/src/Tokenizer/Analyzer/ClassyAnalyzer.php index 49d6e3a7d3d..c45cece76a8 100644 --- a/src/Tokenizer/Analyzer/ClassyAnalyzer.php +++ b/src/Tokenizer/Analyzer/ClassyAnalyzer.php @@ -57,6 +57,10 @@ public function isClassyInvocation(Tokens $tokens, int $index): bool return true; } + if (AttributeAnalyzer::isAttribute($tokens, $index)) { + return true; + } + // `Foo & $bar` could be: // - function reference parameter: function baz(Foo & $bar) {} // - bit operator: $x = Foo & $bar; diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index 9ab225a65a0..86ca33e0a3e 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tokenizer; +use PhpCsFixer\Tokenizer\Analyzer\AttributeAnalyzer; use PhpCsFixer\Tokenizer\Analyzer\GotoLabelAnalyzer; /** @@ -357,10 +358,7 @@ public function isConstantInvocation(int $index): bool } // check for attribute: `#[Foo]` - if ( - \defined('T_ATTRIBUTE') // @TODO: drop condition when PHP 8.0+ is required - && $this->tokens[$prevIndex]->isGivenKind(T_ATTRIBUTE) - ) { + if (AttributeAnalyzer::isAttribute($this->tokens, $index)) { return false; } diff --git a/tests/Fixer/Import/GlobalNamespaceImportFixerTest.php b/tests/Fixer/Import/GlobalNamespaceImportFixerTest.php index 1d6c016fa89..c608183c0da 100644 --- a/tests/Fixer/Import/GlobalNamespaceImportFixerTest.php +++ b/tests/Fixer/Import/GlobalNamespaceImportFixerTest.php @@ -1011,4 +1011,39 @@ public function provideMultipleNamespacesCases() INPUT ]; } + + /** + * @requires PHP 8.0 + */ + public function testAttributes(): void + { + $this->fixer->configure([ + 'import_classes' => true, + 'import_constants' => true, + 'import_functions' => true, + ]); + $this->doTest( + ' false, 8 => false, 10 => true, 12 => false], ]; + + yield [ + ' true], + ]; } private static function assertClassyInvocation(string $source, array $expected): void diff --git a/tests/Tokenizer/TokensAnalyzerTest.php b/tests/Tokenizer/TokensAnalyzerTest.php index 10982b5ec0c..1a9359b265b 100644 --- a/tests/Tokenizer/TokensAnalyzerTest.php +++ b/tests/Tokenizer/TokensAnalyzerTest.php @@ -980,13 +980,13 @@ public function provideIsConstantInvocationPhp80Cases() ]; yield [ - ' false, 7 => false], + ' false, 5 => false, 10 => false], ]; yield [ - ' false, 9 => false], + ' false, 7 => false, 14 => false], ]; } From 229b44c3d59d97da14e1985e8053bc18bb4e8e6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sat, 28 Aug 2021 20:18:01 +0200 Subject: [PATCH 19/80] Use @PHP71Migration rules --- .php-cs-fixer.dist.php | 1 + src/AbstractFunctionReferenceFixer.php | 2 +- src/AbstractNoUselessElseFixer.php | 2 +- src/Cache/FileHandler.php | 2 +- src/DocBlock/DocBlock.php | 4 ++-- src/Doctrine/Annotation/Tokens.php | 2 +- src/Fixer/Alias/MbStrFunctionsFixer.php | 2 +- src/Fixer/Alias/NoAliasFunctionsFixer.php | 2 +- src/Fixer/Alias/RandomApiMigrationFixer.php | 2 +- src/Fixer/Basic/NonPrintableCharacterFixer.php | 2 +- .../CastNotation/ModernizeTypesCastingFixer.php | 2 +- src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php | 4 ++-- src/Fixer/Comment/HeaderCommentFixer.php | 2 +- src/Fixer/Comment/NoEmptyCommentFixer.php | 2 +- src/Fixer/FunctionNotation/ImplodeCallFixer.php | 2 +- .../FunctionNotation/PhpdocToParamTypeFixer.php | 2 +- .../FunctionNotation/PhpdocToPropertyTypeFixer.php | 2 +- .../FunctionNotation/PhpdocToReturnTypeFixer.php | 2 +- src/Fixer/Import/GlobalNamespaceImportFixer.php | 14 +++++++------- src/Fixer/Import/SingleImportPerStatementFixer.php | 2 +- .../CombineConsecutiveUnsetsFixer.php | 2 +- src/Fixer/LanguageConstruct/DirConstantFixer.php | 2 +- src/Fixer/LanguageConstruct/IsNullFixer.php | 2 +- src/Fixer/Naming/NoHomoglyphNamesFixer.php | 4 +--- src/Fixer/PhpUnit/PhpUnitExpectationFixer.php | 2 +- .../Phpdoc/PhpdocReturnSelfReferenceFixer.php | 2 +- src/Tokenizer/Token.php | 2 +- src/Tokenizer/Tokens.php | 6 +++--- src/Tokenizer/TokensAnalyzer.php | 8 ++++---- src/ToolInfo.php | 2 +- tests/AutoReview/CiConfigurationTest.php | 2 +- tests/AutoReview/FixerFactoryTest.php | 2 +- tests/AutoReview/ProjectCodeTest.php | 2 +- tests/AutoReview/TransformerTest.php | 4 ++-- tests/Console/Output/ErrorOutputTest.php | 2 +- tests/Console/Output/ProcessOutputTest.php | 2 +- tests/Fixer/Comment/NoEmptyCommentFixerTest.php | 2 +- tests/Tokenizer/TokensTest.php | 2 +- 38 files changed, 52 insertions(+), 53 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 6c4889c902e..29df7d8e5ed 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -36,6 +36,7 @@ $config ->setRiskyAllowed(true) ->setRules([ + '@PHP71Migration' => true, '@PHP71Migration:risky' => true, '@PHPUnit75Migration:risky' => true, '@PhpCsFixer' => true, diff --git a/src/AbstractFunctionReferenceFixer.php b/src/AbstractFunctionReferenceFixer.php index 9e81193a34a..8b2ded48fbe 100644 --- a/src/AbstractFunctionReferenceFixer.php +++ b/src/AbstractFunctionReferenceFixer.php @@ -52,7 +52,7 @@ protected function find(string $functionNameToSearch, Tokens $tokens, int $start } // translate results for humans - list($functionName, $openParenthesis) = array_keys($matches); + [$functionName, $openParenthesis] = array_keys($matches); $functionsAnalyzer = new FunctionsAnalyzer(); diff --git a/src/AbstractNoUselessElseFixer.php b/src/AbstractNoUselessElseFixer.php index 338d709ae68..2f6747d2b2a 100644 --- a/src/AbstractNoUselessElseFixer.php +++ b/src/AbstractNoUselessElseFixer.php @@ -37,7 +37,7 @@ protected function isSuperfluousElse(Tokens $tokens, int $index): bool do { // Check if all 'if', 'else if ' and 'elseif' blocks above this 'else' always end, // if so this 'else' is overcomplete. - list($previousBlockStart, $previousBlockEnd) = $this->getPreviousBlock($tokens, $previousBlockStart); + [$previousBlockStart, $previousBlockEnd] = $this->getPreviousBlock($tokens, $previousBlockStart); // short 'if' detection $previous = $previousBlockEnd; diff --git a/src/Cache/FileHandler.php b/src/Cache/FileHandler.php index 0f8833f4f9f..1a4727e0fe3 100644 --- a/src/Cache/FileHandler.php +++ b/src/Cache/FileHandler.php @@ -99,7 +99,7 @@ public function write(CacheInterface $cache): void $error = error_get_last(); throw new IOException( - sprintf('Failed to write file "%s", "%s".', $this->file, isset($error['message']) ? $error['message'] : 'no reason available'), + sprintf('Failed to write file "%s", "%s".', $this->file, $error['message'] ?? 'no reason available'), 0, null, $this->file diff --git a/src/DocBlock/DocBlock.php b/src/DocBlock/DocBlock.php index 4d00a17def2..96353e69c53 100644 --- a/src/DocBlock/DocBlock.php +++ b/src/DocBlock/DocBlock.php @@ -86,7 +86,7 @@ public function getLines(): array */ public function getLine(int $pos): ?Line { - return isset($this->lines[$pos]) ? $this->lines[$pos] : null; + return $this->lines[$pos] ?? null; } /** @@ -182,7 +182,7 @@ public function getAnnotation(int $pos): ?Annotation { $annotations = $this->getAnnotations(); - return isset($annotations[$pos]) ? $annotations[$pos] : null; + return $annotations[$pos] ?? null; } /** diff --git a/src/Doctrine/Annotation/Tokens.php b/src/Doctrine/Annotation/Tokens.php index fcbf04be503..d2c579b6fa9 100644 --- a/src/Doctrine/Annotation/Tokens.php +++ b/src/Doctrine/Annotation/Tokens.php @@ -248,7 +248,7 @@ public function insertAt(int $index, Token $token): void $this->setSize($this->getSize() + 1); for ($i = $this->getSize() - 1; $i > $index; --$i) { - $this[$i] = isset($this[$i - 1]) ? $this[$i - 1] : new Token(); + $this[$i] = $this[$i - 1] ?? new Token(); } $this[$index] = $token; diff --git a/src/Fixer/Alias/MbStrFunctionsFixer.php b/src/Fixer/Alias/MbStrFunctionsFixer.php index e37cb961238..b925b9fa62e 100644 --- a/src/Fixer/Alias/MbStrFunctionsFixer.php +++ b/src/Fixer/Alias/MbStrFunctionsFixer.php @@ -117,7 +117,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue 2; } - list($functionName, $openParenthesis, $closeParenthesis) = $boundaries; + [$functionName, $openParenthesis, $closeParenthesis] = $boundaries; $count = $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $closeParenthesis); if (!\in_array($count, $functionReplacement['argumentCount'], true)) { continue 2; diff --git a/src/Fixer/Alias/NoAliasFunctionsFixer.php b/src/Fixer/Alias/NoAliasFunctionsFixer.php index 566ed0c7070..af15d9731fc 100644 --- a/src/Fixer/Alias/NoAliasFunctionsFixer.php +++ b/src/Fixer/Alias/NoAliasFunctionsFixer.php @@ -229,7 +229,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } if (\is_array($this->aliases[$tokenContent])) { - list($alias, $numberOfArguments) = $this->aliases[$tokenContent]; + [$alias, $numberOfArguments] = $this->aliases[$tokenContent]; $count = $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesis)); diff --git a/src/Fixer/Alias/RandomApiMigrationFixer.php b/src/Fixer/Alias/RandomApiMigrationFixer.php index d88d1f6157c..7626db97c32 100644 --- a/src/Fixer/Alias/RandomApiMigrationFixer.php +++ b/src/Fixer/Alias/RandomApiMigrationFixer.php @@ -112,7 +112,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue 2; } - list($functionName, $openParenthesis, $closeParenthesis) = $boundaries; + [$functionName, $openParenthesis, $closeParenthesis] = $boundaries; $count = $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $closeParenthesis); if (!\in_array($count, $functionReplacement['argumentCount'], true)) { diff --git a/src/Fixer/Basic/NonPrintableCharacterFixer.php b/src/Fixer/Basic/NonPrintableCharacterFixer.php index 12be23d8085..c965828bcb0 100644 --- a/src/Fixer/Basic/NonPrintableCharacterFixer.php +++ b/src/Fixer/Basic/NonPrintableCharacterFixer.php @@ -128,7 +128,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $replacements = []; $escapeSequences = []; - foreach ($this->symbolsReplace as $character => list($replacement, $codepoint)) { + foreach ($this->symbolsReplace as $character => [$replacement, $codepoint]) { $replacements[$character] = $replacement; $escapeSequences[$character] = '\u{'.$codepoint.'}'; } diff --git a/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php b/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php index 2ebb286a626..99e51c06f1c 100644 --- a/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php +++ b/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php @@ -84,7 +84,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue 2; } - list($functionName, $openParenthesis, $closeParenthesis) = $boundaries; + [$functionName, $openParenthesis, $closeParenthesis] = $boundaries; // analysing cursor shift $currIndex = $openParenthesis; diff --git a/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php b/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php index 14ee1b25d63..423c4095ffe 100644 --- a/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php +++ b/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php @@ -167,7 +167,7 @@ private function fixConstructor(Tokens $tokens, string $className, int $classSta } // does the PHP4-constructor only call $this->__construct($args, ...)? - list($sequences, $case) = $this->getWrapperMethodSequence($tokens, '__construct', $php4['startIndex'], $php4['bodyIndex']); + [$sequences, $case] = $this->getWrapperMethodSequence($tokens, '__construct', $php4['startIndex'], $php4['bodyIndex']); foreach ($sequences as $seq) { if (null !== $tokens->findSequence($seq, $php4['bodyIndex'] - 1, $php4['endIndex'], $case)) { // good, delete it! @@ -180,7 +180,7 @@ private function fixConstructor(Tokens $tokens, string $className, int $classSta } // does __construct only call the PHP4-constructor (with the same args)? - list($sequences, $case) = $this->getWrapperMethodSequence($tokens, $className, $php4['startIndex'], $php4['bodyIndex']); + [$sequences, $case] = $this->getWrapperMethodSequence($tokens, $className, $php4['startIndex'], $php4['bodyIndex']); foreach ($sequences as $seq) { if (null !== $tokens->findSequence($seq, $php5['bodyIndex'] - 1, $php5['endIndex'], $case)) { // that was a weird choice, but we can safely delete it and... diff --git a/src/Fixer/Comment/HeaderCommentFixer.php b/src/Fixer/Comment/HeaderCommentFixer.php index 53d32ba1082..cae05c74050 100644 --- a/src/Fixer/Comment/HeaderCommentFixer.php +++ b/src/Fixer/Comment/HeaderCommentFixer.php @@ -436,7 +436,7 @@ private function removeHeader(Tokens $tokens, int $index): void } $nextIndex = $index + 1; - $nextToken = isset($tokens[$nextIndex]) ? $tokens[$nextIndex] : null; + $nextToken = $tokens[$nextIndex] ?? null; if (!$newlineRemoved && null !== $nextToken && $nextToken->isWhitespace()) { $content = Preg::replace('/^\R/', '', $nextToken->getContent()); diff --git a/src/Fixer/Comment/NoEmptyCommentFixer.php b/src/Fixer/Comment/NoEmptyCommentFixer.php index dde77e79ff3..c2a3c0e0340 100644 --- a/src/Fixer/Comment/NoEmptyCommentFixer.php +++ b/src/Fixer/Comment/NoEmptyCommentFixer.php @@ -72,7 +72,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - list($blockStart, $index, $isEmpty) = $this->getCommentBlock($tokens, $index); + [$blockStart, $index, $isEmpty] = $this->getCommentBlock($tokens, $index); if (false === $isEmpty) { continue; } diff --git a/src/Fixer/FunctionNotation/ImplodeCallFixer.php b/src/Fixer/FunctionNotation/ImplodeCallFixer.php index 6ac1e19b441..166482d6109 100644 --- a/src/Fixer/FunctionNotation/ImplodeCallFixer.php +++ b/src/Fixer/FunctionNotation/ImplodeCallFixer.php @@ -101,7 +101,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } if (2 === \count($argumentsIndices)) { - list($firstArgumentIndex, $secondArgumentIndex) = array_keys($argumentsIndices); + [$firstArgumentIndex, $secondArgumentIndex] = array_keys($argumentsIndices); // If the first argument is string we have nothing to do if ($tokens[$firstArgumentIndex]->isGivenKind(T_CONSTANT_ENCAPSED_STRING)) { diff --git a/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php index 06e36dc8001..6a1f7bdc9d1 100644 --- a/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php @@ -143,7 +143,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - list($paramType, $isNullable) = $typeInfo; + [$paramType, $isNullable] = $typeInfo; $startIndex = $tokens->getNextTokenOfKind($index, ['(']); $variableIndex = $this->findCorrectVariable($tokens, $startIndex, $paramTypeAnnotation); diff --git a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php index d3506c2036f..be041cd7e8d 100644 --- a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php @@ -143,7 +143,7 @@ private function fixClass(Tokens $tokens, int $index): void continue; } - list($propertyType, $isNullable) = $typeInfo; + [$propertyType, $isNullable] = $typeInfo; if (\in_array($propertyType, ['void', 'callable'], true)) { continue; diff --git a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php index 38e15cb2914..8b85b0681fe 100644 --- a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php @@ -178,7 +178,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - list($returnType, $isNullable) = $typeInfo; + [$returnType, $isNullable] = $typeInfo; $startIndex = $tokens->getNextTokenOfKind($index, ['{', ';']); diff --git a/src/Fixer/Import/GlobalNamespaceImportFixer.php b/src/Fixer/Import/GlobalNamespaceImportFixer.php index bf6abc987c5..198ecd123ee 100644 --- a/src/Fixer/Import/GlobalNamespaceImportFixer.php +++ b/src/Fixer/Import/GlobalNamespaceImportFixer.php @@ -176,7 +176,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn */ private function importConstants(Tokens $tokens, array $useDeclarations): array { - list($global, $other) = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global, $other] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { return $declaration->isConstant(); }, true); @@ -248,7 +248,7 @@ private function importConstants(Tokens $tokens, array $useDeclarations): array */ private function importFunctions(Tokens $tokens, array $useDeclarations): array { - list($global, $other) = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global, $other] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { return $declaration->isFunction(); }, false); @@ -299,7 +299,7 @@ private function importFunctions(Tokens $tokens, array $useDeclarations): array */ private function importClasses(Tokens $tokens, array $useDeclarations): array { - list($global, $other) = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global, $other] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { return $declaration->isClass(); }, false); @@ -490,7 +490,7 @@ private function fullyQualifyConstants(Tokens $tokens, array $useDeclarations): return; } - list($global) = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { return $declaration->isConstant() && !$declaration->isAliased(); }, true); @@ -532,7 +532,7 @@ private function fullyQualifyFunctions(Tokens $tokens, array $useDeclarations): return; } - list($global) = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { return $declaration->isFunction() && !$declaration->isAliased(); }, false); @@ -574,7 +574,7 @@ private function fullyQualifyClasses(Tokens $tokens, array $useDeclarations): vo return; } - list($global) = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { return $declaration->isClass() && !$declaration->isAliased(); }, false); @@ -723,7 +723,7 @@ private function traverseDocBlockTypes(DocBlock $doc, callable $callback): bool Preg::matchAll('/[\\\\\w]+/', $fullType, $matches, PREG_OFFSET_CAPTURE); - foreach (array_reverse($matches[0]) as list($type, $offset)) { + foreach (array_reverse($matches[0]) as [$type, $offset]) { $newType = $callback($type); if (null !== $newType && $type !== $newType) { diff --git a/src/Fixer/Import/SingleImportPerStatementFixer.php b/src/Fixer/Import/SingleImportPerStatementFixer.php index c941f5cf9e0..36fb2f5f642 100644 --- a/src/Fixer/Import/SingleImportPerStatementFixer.php +++ b/src/Fixer/Import/SingleImportPerStatementFixer.php @@ -173,7 +173,7 @@ private function getGroupStatements(Tokens $tokens, string $groupPrefix, int $gr private function fixGroupUse(Tokens $tokens, int $index, int $endIndex): void { - list($groupPrefix, $groupOpenIndex, $groupCloseIndex, $comment) = $this->getGroupDeclaration($tokens, $index); + [$groupPrefix, $groupOpenIndex, $groupCloseIndex, $comment] = $this->getGroupDeclaration($tokens, $index); $statements = $this->getGroupStatements($tokens, $groupPrefix, $groupOpenIndex, $groupCloseIndex, $comment); if (\count($statements) < 2) { diff --git a/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php b/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php index 68055a97523..007550f575c 100644 --- a/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php +++ b/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php @@ -73,7 +73,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - list($previousUnset, , $previousUnsetBraceEnd) = $previousUnsetCall; + [$previousUnset, , $previousUnsetBraceEnd] = $previousUnsetCall; // Merge the tokens inside the 'unset' call into the previous one 'unset' call. $tokensAddCount = $this->moveTokens( diff --git a/src/Fixer/LanguageConstruct/DirConstantFixer.php b/src/Fixer/LanguageConstruct/DirConstantFixer.php index 59e67e5cd21..96e02938325 100644 --- a/src/Fixer/LanguageConstruct/DirConstantFixer.php +++ b/src/Fixer/LanguageConstruct/DirConstantFixer.php @@ -69,7 +69,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void return; } - list($functionNameIndex, $openParenthesis, $closeParenthesis) = $boundaries; + [$functionNameIndex, $openParenthesis, $closeParenthesis] = $boundaries; // analysing cursor shift, so nested expressions kept processed $currIndex = $openParenthesis; diff --git a/src/Fixer/LanguageConstruct/IsNullFixer.php b/src/Fixer/LanguageConstruct/IsNullFixer.php index 784a92629c2..747347f6454 100644 --- a/src/Fixer/LanguageConstruct/IsNullFixer.php +++ b/src/Fixer/LanguageConstruct/IsNullFixer.php @@ -89,7 +89,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $matches = array_keys($matches); // move the cursor just after the sequence - list($isNullIndex, $currIndex) = $matches; + [$isNullIndex, $currIndex] = $matches; if (!$functionsAnalyzer->isGlobalFunctionCall($tokens, $matches[0])) { continue; diff --git a/src/Fixer/Naming/NoHomoglyphNamesFixer.php b/src/Fixer/Naming/NoHomoglyphNamesFixer.php index 35c18e0d059..0f16b07903f 100644 --- a/src/Fixer/Naming/NoHomoglyphNamesFixer.php +++ b/src/Fixer/Naming/NoHomoglyphNamesFixer.php @@ -233,9 +233,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $replaced = Preg::replaceCallback('/[^[:ascii:]]/u', static function (array $matches) { - return isset(self::$replacements[$matches[0]]) - ? self::$replacements[$matches[0]] - : $matches[0] + return self::$replacements[$matches[0]] ?? $matches[0] ; }, $token->getContent(), -1, $count); diff --git a/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php b/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php index 0f15868d7dc..4bb80013455 100644 --- a/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php @@ -207,7 +207,7 @@ private function applyPhpUnitClassFixWithObjectOperator(Tokens $tokens, int $sta return; } - list($thisIndex, , $index) = array_keys($match); + [$thisIndex, , $index] = array_keys($match); if (!isset($this->methodMap[$tokens[$index]->getContent()])) { continue; diff --git a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php index 015f7bdde04..bdf7a2468a7 100644 --- a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php +++ b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php @@ -219,7 +219,7 @@ private function fixMethod(Tokens $tokens, int $index): void $newTypes = []; foreach ($types as $type) { $lower = strtolower($type); - $newTypes[] = isset($this->configuration['replacements'][$lower]) ? $this->configuration['replacements'][$lower] : $type; + $newTypes[] = $this->configuration['replacements'][$lower] ?? $type; } if ($types === $newTypes) { diff --git a/src/Tokenizer/Token.php b/src/Tokenizer/Token.php index c178d7d2255..12d7af4e49f 100644 --- a/src/Tokenizer/Token.php +++ b/src/Tokenizer/Token.php @@ -212,7 +212,7 @@ public function equalsAny(array $others, bool $caseSensitive = true): bool public static function isKeyCaseSensitive($caseSensitive, int $key): bool { if (\is_array($caseSensitive)) { - return isset($caseSensitive[$key]) ? $caseSensitive[$key] : true; + return $caseSensitive[$key] ?? true; } return $caseSensitive; diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index f19aae0ba3a..37ff4b57424 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -1062,7 +1062,7 @@ public function isTokenKindFound($tokenKind): bool */ public function countTokenKind($tokenKind): int { - return isset($this->foundTokenKinds[$tokenKind]) ? $this->foundTokenKinds[$tokenKind] : 0; + return $this->foundTokenKinds[$tokenKind] ?? 0; } /** @@ -1167,7 +1167,7 @@ private function removeWhitespaceSafely(int $index, int $direction, ?string $whi // if the token candidate to remove is preceded by single line comment we do not consider the new line after this comment as part of T_WHITESPACE if (isset($this[$whitespaceIndex - 1]) && $this[$whitespaceIndex - 1]->isComment() && '/*' !== substr($this[$whitespaceIndex - 1]->getContent(), 0, 2)) { - list($emptyString, $newContent, $whitespacesToCheck) = Preg::split('/^(\R)/', $this[$whitespaceIndex]->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE); + [$emptyString, $newContent, $whitespacesToCheck] = Preg::split('/^(\R)/', $this[$whitespaceIndex]->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE); if ('' === $whitespacesToCheck) { return; @@ -1217,7 +1217,7 @@ private function findOppositeBlockEdge(int $type, int $searchIndex, bool $findEn $indexOffset = 1; if (!$findEnd) { - list($startEdge, $endEdge) = [$endEdge, $startEdge]; + [$startEdge, $endEdge] = [$endEdge, $startEdge]; $indexOffset = -1; $endIndex = 0; } diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index 9ab225a65a0..43bb54668b7 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -57,7 +57,7 @@ public function getClassyElements(): array for ($index = 1, $count = \count($this->tokens) - 2; $index < $count; ++$index) { if ($this->tokens[$index]->isClassy()) { - list($index, $newElements) = $this->findClassyElements($index, $index); + [$index, $newElements] = $this->findClassyElements($index, $index); $elements += $newElements; } } @@ -672,7 +672,7 @@ private function findClassyElements(int $classIndex, int $index): array --$nestedBracesLevel; if (0 === $nestedBracesLevel) { - list($index, $newElements) = $this->findClassyElements($nestedClassIndex, $index); + [$index, $newElements] = $this->findClassyElements($nestedClassIndex, $index); $elements += $newElements; break; @@ -682,12 +682,12 @@ private function findClassyElements(int $classIndex, int $index): array } if ($token->isClassy()) { // anonymous class in class - list($index, $newElements) = $this->findClassyElements($index, $index); + [$index, $newElements] = $this->findClassyElements($index, $index); $elements += $newElements; } } } else { - list($index, $newElements) = $this->findClassyElements($nestedClassIndex, $nestedClassIndex); + [$index, $newElements] = $this->findClassyElements($nestedClassIndex, $nestedClassIndex); $elements += $newElements; } diff --git a/src/ToolInfo.php b/src/ToolInfo.php index 3a675a71b90..554f9f4ca1c 100644 --- a/src/ToolInfo.php +++ b/src/ToolInfo.php @@ -48,7 +48,7 @@ public function getComposerInstallationDetails(): array if (null === $this->composerInstallationDetails) { $composerInstalled = json_decode(file_get_contents($this->getComposerInstalledFile()), true); - $packages = isset($composerInstalled['packages']) ? $composerInstalled['packages'] : $composerInstalled; + $packages = $composerInstalled['packages'] ?? $composerInstalled; foreach ($packages as $package) { if (\in_array($package['name'], [self::COMPOSER_PACKAGE_NAME, self::COMPOSER_LEGACY_PACKAGE_NAME], true)) { diff --git a/tests/AutoReview/CiConfigurationTest.php b/tests/AutoReview/CiConfigurationTest.php index ad01b08e3d9..ece4c406d8d 100644 --- a/tests/AutoReview/CiConfigurationTest.php +++ b/tests/AutoReview/CiConfigurationTest.php @@ -208,7 +208,7 @@ private function getPhpVersionsUsedByGitHub() { $yaml = Yaml::parse(file_get_contents(__DIR__.'/../../.github/workflows/ci.yml')); - $phpVersions = isset($yaml['jobs']['tests']['strategy']['matrix']['php-version']) ? $yaml['jobs']['tests']['strategy']['matrix']['php-version'] : []; + $phpVersions = $yaml['jobs']['tests']['strategy']['matrix']['php-version'] ?? []; foreach ($yaml['jobs']['tests']['strategy']['matrix']['include'] as $job) { $phpVersions[] = $job['php-version']; diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index df3316323f5..10a54eb0fce 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -519,7 +519,7 @@ public function testFixerPriorityComment(): void $map = []; foreach ($cases as $beforeAfter) { - list($before, $after) = $beforeAfter; + [$before, $after] = $beforeAfter; $beforeClass = \get_class($before); $afterClass = \get_class($after); diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index a4a7010dfad..41376af9ab1 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -167,7 +167,7 @@ public function testThatSrcClassesNotExposeProperties(string $className): void $extraProps = array_diff( $definedProps, $allowedProps, - isset($exceptionPropsPerClass[$className]) ? $exceptionPropsPerClass[$className] : [] + $exceptionPropsPerClass[$className] ?? [] ); sort($extraProps); diff --git a/tests/AutoReview/TransformerTest.php b/tests/AutoReview/TransformerTest.php index a7dcd11fd3d..f2aa1700a11 100644 --- a/tests/AutoReview/TransformerTest.php +++ b/tests/AutoReview/TransformerTest.php @@ -58,7 +58,7 @@ public function testTransformerPriorityIsListed(TransformerInterface $transforme $name = $transformer->getName(); foreach ($this->provideTransformerPriorityCases() as $pair) { - list($first, $second) = $pair; + [$first, $second] = $pair; if ($name === $first->getName() || $name === $second->getName()) { $this->addToAssertionCount(1); @@ -74,7 +74,7 @@ public function provideTransformerPriorityCases() { $transformers = []; - foreach ($this->provideTransformerCases() as list($transformer)) { + foreach ($this->provideTransformerCases() as [$transformer]) { $transformers[$transformer->getName()] = $transformer; } diff --git a/tests/Console/Output/ErrorOutputTest.php b/tests/Console/Output/ErrorOutputTest.php index e082583302f..17b1d835fb7 100644 --- a/tests/Console/Output/ErrorOutputTest.php +++ b/tests/Console/Output/ErrorOutputTest.php @@ -86,7 +86,7 @@ public function testErrorOutput(Error $error, int $verbosityLevel, int $lineNumb public function provideTestCases() { $lineNumber = __LINE__; - list($exceptionLineNumber, $error) = $this->getErrorAndLineNumber(); // note: keep call and __LINE__ separated with one line break + [$exceptionLineNumber, $error] = $this->getErrorAndLineNumber(); // note: keep call and __LINE__ separated with one line break ++$lineNumber; return [ diff --git a/tests/Console/Output/ProcessOutputTest.php b/tests/Console/Output/ProcessOutputTest.php index aad482a9577..11826741291 100644 --- a/tests/Console/Output/ProcessOutputTest.php +++ b/tests/Console/Output/ProcessOutputTest.php @@ -179,7 +179,7 @@ public function provideProcessProgressOutputCases() private function foreachStatus(array $statuses, \Closure $action): void { foreach ($statuses as $status) { - $multiplier = isset($status[1]) ? $status[1] : 1; + $multiplier = $status[1] ?? 1; $status = $status[0]; for ($i = 0; $i < $multiplier; ++$i) { diff --git a/tests/Fixer/Comment/NoEmptyCommentFixerTest.php b/tests/Fixer/Comment/NoEmptyCommentFixerTest.php index 6e575f9456b..0d0cbbc5624 100644 --- a/tests/Fixer/Comment/NoEmptyCommentFixerTest.php +++ b/tests/Fixer/Comment/NoEmptyCommentFixerTest.php @@ -267,7 +267,7 @@ public function testGetCommentBlock(string $source, int $startIndex, int $endInd $method = new \ReflectionMethod($this->fixer, 'getCommentBlock'); $method->setAccessible(true); - list($foundStart, $foundEnd, $foundIsEmpty) = $method->invoke($this->fixer, $tokens, $startIndex); + [$foundStart, $foundEnd, $foundIsEmpty] = $method->invoke($this->fixer, $tokens, $startIndex); static::assertSame($startIndex, $foundStart, 'Find start index of block failed.'); static::assertSame($endIndex, $foundEnd, 'Find end index of block failed.'); diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index b71280377fa..c85cfa39aa2 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -337,7 +337,7 @@ public function bar() PHP; $tokens = Tokens::fromCode($source); - list($fooIndex, $barIndex) = array_keys($tokens->findGivenKind(T_PUBLIC)); + [$fooIndex, $barIndex] = array_keys($tokens->findGivenKind(T_PUBLIC)); $tokens->clearRange($fooIndex, $barIndex - 1); From 840a40b787e217ef5306dc936b59e50419cd2d51 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sat, 28 Aug 2021 16:45:03 +0200 Subject: [PATCH 20/80] SingleSpaceAfterConstructFixer - improve comma handling --- src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php | 2 +- .../LanguageConstruct/SingleSpaceAfterConstructFixerTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index b0f0e67c757..5bd6290ed01 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -209,7 +209,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $whitespaceTokenIndex = $index + 1; - if ($tokens[$whitespaceTokenIndex]->equalsAny([';', ')', [CT::T_ARRAY_SQUARE_BRACE_CLOSE]])) { + if ($tokens[$whitespaceTokenIndex]->equalsAny([',', ';', ')', [CT::T_ARRAY_SQUARE_BRACE_CLOSE]])) { continue; } diff --git a/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php b/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php index 80cc31de011..22598f8ad45 100644 --- a/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php +++ b/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php @@ -2941,6 +2941,7 @@ public function provideCommentsCases() new Dummy(/* a */); new Dummy(/** b */); foo(/* c */); +foo($a /* d */, $b); $arr = [/* empty */]; ', ]; From 1fc2bdafcf0b9e6cde197881b7ed5c97b1372e0d Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Sun, 16 May 2021 14:24:58 +0200 Subject: [PATCH 21/80] NoUnusedImportsFixer - Fix undetected unused imports when type mismatch --- src/Fixer/Import/NoUnusedImportsFixer.php | 68 ++++-- .../Analysis/NamespaceUseAnalysis.php | 2 +- src/Tokenizer/Analyzer/GotoLabelAnalyzer.php | 2 +- .../Fixer/Import/NoUnusedImportsFixerTest.php | 209 +++++++++++++++++- tests/Fixtures/Integration/misc/PHP7_0.test | 1 - tests/Fixtures/Integration/misc/PHP7_2.test | 2 - .../Analyzer/GotoLabelAnalyzerTest.php | 19 +- 7 files changed, 270 insertions(+), 33 deletions(-) diff --git a/src/Fixer/Import/NoUnusedImportsFixer.php b/src/Fixer/Import/NoUnusedImportsFixer.php index 3f404710d71..9142123180d 100644 --- a/src/Fixer/Import/NoUnusedImportsFixer.php +++ b/src/Fixer/Import/NoUnusedImportsFixer.php @@ -21,10 +21,12 @@ use PhpCsFixer\Preg; use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceAnalysis; use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceUseAnalysis; +use PhpCsFixer\Tokenizer\Analyzer\GotoLabelAnalyzer; use PhpCsFixer\Tokenizer\Analyzer\NamespacesAnalyzer; use PhpCsFixer\Tokenizer\Analyzer\NamespaceUsesAnalyzer; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; +use PhpCsFixer\Tokenizer\TokensAnalyzer; /** * @author Dariusz RumiƄski @@ -73,24 +75,18 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } foreach ((new NamespacesAnalyzer())->getDeclarations($tokens) as $namespace) { - $currentNamespaceUseDeclarations = array_filter( - $useDeclarations, - static function (NamespaceUseAnalysis $useDeclaration) use ($namespace) { - return - $useDeclaration->getStartIndex() >= $namespace->getScopeStartIndex() - && $useDeclaration->getEndIndex() <= $namespace->getScopeEndIndex() - ; - } - ); - - $usagesSearchIgnoredIndexes = []; + $currentNamespaceUseDeclarations = []; + $currentNamespaceUseDeclarationIndexes = []; - foreach ($currentNamespaceUseDeclarations as $useDeclaration) { - $usagesSearchIgnoredIndexes[$useDeclaration->getStartIndex()] = $useDeclaration->getEndIndex(); + foreach ($useDeclarations as $useDeclaration) { + if ($useDeclaration->getStartIndex() >= $namespace->getScopeStartIndex() && $useDeclaration->getEndIndex() <= $namespace->getScopeEndIndex()) { + $currentNamespaceUseDeclarations[] = $useDeclaration; + $currentNamespaceUseDeclarationIndexes[$useDeclaration->getStartIndex()] = $useDeclaration->getEndIndex(); + } } foreach ($currentNamespaceUseDeclarations as $useDeclaration) { - if (!$this->isImportUsed($tokens, $namespace, $usagesSearchIgnoredIndexes, $useDeclaration->getShortName())) { + if (!$this->isImportUsed($tokens, $namespace, $useDeclaration, $currentNamespaceUseDeclarationIndexes)) { $this->removeUseDeclaration($tokens, $useDeclaration); } } @@ -100,10 +96,19 @@ static function (NamespaceUseAnalysis $useDeclaration) use ($namespace) { } /** - * @param array $ignoredIndexes + * @param array $ignoredIndexes indexes of the use statements themselves that should not be checked as being "used" */ - private function isImportUsed(Tokens $tokens, NamespaceAnalysis $namespace, array $ignoredIndexes, string $shortName): bool + private function isImportUsed(Tokens $tokens, NamespaceAnalysis $namespace, NamespaceUseAnalysis $import, array $ignoredIndexes): bool { + $analyzer = new TokensAnalyzer($tokens); + $gotoLabelAnalyzer = new GotoLabelAnalyzer(); + + $tokensNotBeforeFunctionCall = [T_NEW]; + // @TODO: drop condition when PHP 8.0+ is required + if (\defined('T_ATTRIBUTE')) { + $tokensNotBeforeFunctionCall[] = T_ATTRIBUTE; + } + $namespaceEndIndex = $namespace->getScopeEndIndex(); for ($index = $namespace->getScopeStartIndex(); $index <= $namespaceEndIndex; ++$index) { if (isset($ignoredIndexes[$index])) { @@ -115,6 +120,10 @@ private function isImportUsed(Tokens $tokens, NamespaceAnalysis $namespace, arra $token = $tokens[$index]; if ($token->isGivenKind(T_STRING)) { + if (0 !== strcasecmp($import->getShortName(), $token->getContent())) { + continue; + } + $prevMeaningfulToken = $tokens[$tokens->getPrevMeaningfulToken($index)]; if ($prevMeaningfulToken->isGivenKind(T_NAMESPACE)) { @@ -124,10 +133,29 @@ private function isImportUsed(Tokens $tokens, NamespaceAnalysis $namespace, arra } if ( - 0 === strcasecmp($shortName, $token->getContent()) - && !$prevMeaningfulToken->isGivenKind([T_NS_SEPARATOR, T_CONST, T_DOUBLE_COLON]) - && !$prevMeaningfulToken->isObjectOperator() + $prevMeaningfulToken->isGivenKind([T_NS_SEPARATOR, T_FUNCTION, T_CONST, T_DOUBLE_COLON]) + || $prevMeaningfulToken->isObjectOperator() ) { + continue; + } + + $nextMeaningfulIndex = $tokens->getNextMeaningfulToken($index); + + if ($gotoLabelAnalyzer->belongsToGoToLabel($tokens, $nextMeaningfulIndex)) { + continue; + } + + $nextMeaningfulToken = $tokens[$nextMeaningfulIndex]; + + if ($analyzer->isConstantInvocation($index)) { + $type = NamespaceUseAnalysis::TYPE_CONSTANT; + } elseif ($nextMeaningfulToken->equals('(') && !$prevMeaningfulToken->isGivenKind($tokensNotBeforeFunctionCall)) { + $type = NamespaceUseAnalysis::TYPE_FUNCTION; + } else { + $type = NamespaceUseAnalysis::TYPE_CLASS; + } + + if ($import->getType() === $type) { return true; } @@ -136,7 +164,7 @@ private function isImportUsed(Tokens $tokens, NamespaceAnalysis $namespace, arra if ($token->isComment() && Preg::match( - '/(?getShortName().'(?![[:alnum:]])/i', $token->getContent() ) ) { diff --git a/src/Tokenizer/Analyzer/Analysis/NamespaceUseAnalysis.php b/src/Tokenizer/Analyzer/Analysis/NamespaceUseAnalysis.php index adf57870a08..beb29d70edd 100644 --- a/src/Tokenizer/Analyzer/Analysis/NamespaceUseAnalysis.php +++ b/src/Tokenizer/Analyzer/Analysis/NamespaceUseAnalysis.php @@ -19,7 +19,7 @@ */ final class NamespaceUseAnalysis implements StartEndTokenAwareAnalysis { - public const TYPE_CLASS = 1; + public const TYPE_CLASS = 1; // "classy" could be class, interface or trait public const TYPE_FUNCTION = 2; public const TYPE_CONSTANT = 3; diff --git a/src/Tokenizer/Analyzer/GotoLabelAnalyzer.php b/src/Tokenizer/Analyzer/GotoLabelAnalyzer.php index fb851f8dcb5..15d5b0660f8 100644 --- a/src/Tokenizer/Analyzer/GotoLabelAnalyzer.php +++ b/src/Tokenizer/Analyzer/GotoLabelAnalyzer.php @@ -35,6 +35,6 @@ public function belongsToGoToLabel(Tokens $tokens, int $index): bool $prevMeaningfulTokenIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulTokenIndex); - return $tokens[$prevMeaningfulTokenIndex]->equalsAny([';', '{', '}', [T_OPEN_TAG]]); + return $tokens[$prevMeaningfulTokenIndex]->equalsAny([':', ';', '{', '}', [T_OPEN_TAG]]); } } diff --git a/tests/Fixer/Import/NoUnusedImportsFixerTest.php b/tests/Fixer/Import/NoUnusedImportsFixerTest.php index 84407301abf..507d4deba32 100644 --- a/tests/Fixer/Import/NoUnusedImportsFixerTest.php +++ b/tests/Fixer/Import/NoUnusedImportsFixerTest.php @@ -408,6 +408,7 @@ public function doSomething($foo) [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + 'doTest( + $this->doTest($expected, $input); + } + + public function providePhp80Cases() + { + yield [ 'bar; $y = foo?->bar(); -' - ); +', + ]; + + yield 'with union type in non-capturing catch' => [ + ' [ + 'after php tag' => [ ' [ + 'after closing brace' => [ ' [ + 'after statement' => [ ' [ + 'after opening brace' => [ ' [ + ' $test) { From fbc46e219eb661491abf14d9b70f36c4481e983b Mon Sep 17 00:00:00 2001 From: Alex Kalineskou Date: Sun, 29 Aug 2021 21:04:02 +0200 Subject: [PATCH 22/80] DoctrineAnnotationFixer - Add template to ignored_tags --- .../doctrine_annotation_array_assignment.rst | 2 +- doc/rules/doctrine_annotation/doctrine_annotation_braces.rst | 2 +- .../doctrine_annotation/doctrine_annotation_indentation.rst | 2 +- doc/rules/doctrine_annotation/doctrine_annotation_spaces.rst | 2 +- src/AbstractDoctrineAnnotationFixer.php | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/rules/doctrine_annotation/doctrine_annotation_array_assignment.rst b/doc/rules/doctrine_annotation/doctrine_annotation_array_assignment.rst index 999dc8bf03e..f5c9a580d8b 100644 --- a/doc/rules/doctrine_annotation/doctrine_annotation_array_assignment.rst +++ b/doc/rules/doctrine_annotation/doctrine_annotation_array_assignment.rst @@ -14,7 +14,7 @@ List of tags that must not be treated as Doctrine Annotations. Allowed types: ``array`` -Default value: ``['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'fix', 'FIXME', 'fixme', 'override']`` +Default value: ``['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'template', 'fix', 'FIXME', 'fixme', 'override']`` ``operator`` ~~~~~~~~~~~~ diff --git a/doc/rules/doctrine_annotation/doctrine_annotation_braces.rst b/doc/rules/doctrine_annotation/doctrine_annotation_braces.rst index 8852b7798cb..850925bdedd 100644 --- a/doc/rules/doctrine_annotation/doctrine_annotation_braces.rst +++ b/doc/rules/doctrine_annotation/doctrine_annotation_braces.rst @@ -14,7 +14,7 @@ List of tags that must not be treated as Doctrine Annotations. Allowed types: ``array`` -Default value: ``['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'fix', 'FIXME', 'fixme', 'override']`` +Default value: ``['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'template', 'fix', 'FIXME', 'fixme', 'override']`` ``syntax`` ~~~~~~~~~~ diff --git a/doc/rules/doctrine_annotation/doctrine_annotation_indentation.rst b/doc/rules/doctrine_annotation/doctrine_annotation_indentation.rst index 62f8d32bf70..708c30509ee 100644 --- a/doc/rules/doctrine_annotation/doctrine_annotation_indentation.rst +++ b/doc/rules/doctrine_annotation/doctrine_annotation_indentation.rst @@ -14,7 +14,7 @@ List of tags that must not be treated as Doctrine Annotations. Allowed types: ``array`` -Default value: ``['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'fix', 'FIXME', 'fixme', 'override']`` +Default value: ``['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'template', 'fix', 'FIXME', 'fixme', 'override']`` ``indent_mixed_lines`` ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/rules/doctrine_annotation/doctrine_annotation_spaces.rst b/doc/rules/doctrine_annotation/doctrine_annotation_spaces.rst index 9eb706e9dfd..4cbad2ebdbb 100644 --- a/doc/rules/doctrine_annotation/doctrine_annotation_spaces.rst +++ b/doc/rules/doctrine_annotation/doctrine_annotation_spaces.rst @@ -21,7 +21,7 @@ List of tags that must not be treated as Doctrine Annotations. Allowed types: ``array`` -Default value: ``['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'fix', 'FIXME', 'fixme', 'override']`` +Default value: ``['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'template', 'fix', 'FIXME', 'fixme', 'override']`` ``around_parentheses`` ~~~~~~~~~~~~~~~~~~~~~~ diff --git a/src/AbstractDoctrineAnnotationFixer.php b/src/AbstractDoctrineAnnotationFixer.php index dfa4bc16e9c..3aa32cfe8b3 100644 --- a/src/AbstractDoctrineAnnotationFixer.php +++ b/src/AbstractDoctrineAnnotationFixer.php @@ -192,6 +192,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn // PHPStan 'phpstan', + 'template', // other 'fix', From dbf8ac24cd9000d7f238739d98cc5dcbb22ffd3b Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 29 Aug 2021 21:48:25 +0200 Subject: [PATCH 23/80] prepared the 3.0.3 release --- CHANGELOG.md | 29 +++++++++++++++++++++++++++++ src/Console/Application.php | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 711540d3dcc..fec7eb88cde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,35 @@ CHANGELOG for PHP CS Fixer This file contains changelogs for stable releases only. +Changelog for v3.0.3 +-------------------- + +* bug #4927 PhpdocAlignFixer - fix for whitespace in type (kubawerlos) +* bug #5720 NoUnusedImportsFixer - Fix undetected unused imports when type mismatch (julienfalque, SpacePossum) +* bug #5806 DoctrineAnnotationFixer - Add template to ignored_tags (akalineskou) +* bug #5849 PhpdocTagTypeFixer - must not remove inlined tags within other tags (boesing) +* bug #5853 BracesFixer - handle alternative short foreach with if (SpacePossum) +* bug #5855 GlobalNamespaceImportFixer - fix for attributes imported as constants (kubawerlos) +* bug #5881 SelfUpdateCommand - fix link to UPGRADE docs (keradus) +* bug #5884 CurlyBraceTransformer - fix handling dynamic property with string with variable (kubawerlos, keradus) +* bug #5912 TypeAlternationTransformer - fix for "callable" type (kubawerlos) +* bug #5913 SingleSpaceAfterConstructFixer - improve comma handling (keradus) +* minor #5829 DX: Fix SCA with PHPMD (paulbalandan) +* minor #5838 PHP7 - use spaceship (SpacePossum, keradus) +* minor #5848 Docs: update PhpStorm integration link (keradus) +* minor #5856 Add AttributeAnalyzer (kubawerlos) +* minor #5857 DX: PHPMD - exclude fixtures (keradus) +* minor #5859 Various fixes (kubawerlos) +* minor #5864 DX: update dev tools (kubawerlos) +* minor #5876 AttributeTransformerTest - add more tests (SpacePossum) +* minor #5879 Update UPGRADE-v3.md adding relative links (shakaran, keradus) +* minor #5882 Docs: don't use v2 for installation example (keradus) +* minor #5883 Docs: typo (brianteeman, keradus) +* minor #5890 DX: use PHP 8.1 polyfill (keradus) +* minor #5902 Remove references to PHP 7.0 in tests (only removing lines) (kubawerlos) +* minor #5905 DX: Use "yield from" in tests (kubawerlos, keradus) +* minor #5917 Use `@PHP71Migration` rules (kubawerlos, keradus) + Changelog for v3.0.2 -------------------- diff --git a/src/Console/Application.php b/src/Console/Application.php index 7f5b4261b83..211c2fb63fc 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -39,7 +39,7 @@ */ final class Application extends BaseApplication { - public const VERSION = '3.0.3-DEV'; + public const VERSION = '3.0.3'; public const VERSION_CODENAME = 'Constitution'; /** From cf4cedb9e8991c2daa94a756176d81bf487e4c4b Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 29 Aug 2021 22:16:20 +0200 Subject: [PATCH 24/80] prepared the 3.1.0 release --- CHANGELOG.md | 13 +++++++++++++ src/Console/Application.php | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fec7eb88cde..e6222b2dab2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,19 @@ CHANGELOG for PHP CS Fixer This file contains changelogs for stable releases only. +Changelog for v3.1.0 +-------------------- + +* feature #5572 PhpdocToCommentFixer - Add `ignored_tags` option (VincentLanglet) +* feature #5588 NoAliasFunctionsFixer - Add more function aliases (danog) +* feature #5704 ClassAttributesSeparationFixer - Introduce `only_if_meta` spacing option (paulbalandan) +* feature #5734 TypesSpacesFixer - Introduction (kubawerlos) +* feature #5745 EmptyLoopBodyFixer - introduction (SpacePossum, keradus) +* feature #5751 Extract DeclareParenthesesFixer from BracesFixer (julienfalque, keradus) +* feature #5877 ClassDefinitionFixer - PSR12 for anonymous class (SpacePossum) +* minor #5875 EmptyLoopBodyFixer - NoTrailingWhitespaceFixer - priority test (SpacePossum) +* minor #5914 Deprecate ClassKeywordRemoveFixer (kubawerlos) + Changelog for v3.0.3 -------------------- diff --git a/src/Console/Application.php b/src/Console/Application.php index df86d7d2ec3..d7708da5449 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -39,8 +39,8 @@ */ final class Application extends BaseApplication { - public const VERSION = '3.1.0-DEV'; - public const VERSION_CODENAME = ''; + public const VERSION = '3.1.0'; + public const VERSION_CODENAME = 'River'; /** * @var ToolInfo From 0b905620790a71fa414f6f38fb09f0030ed05618 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Sun, 29 Aug 2021 22:16:45 +0200 Subject: [PATCH 25/80] bumped version --- src/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Application.php b/src/Console/Application.php index d7708da5449..541bf68b24c 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -39,7 +39,7 @@ */ final class Application extends BaseApplication { - public const VERSION = '3.1.0'; + public const VERSION = '3.1.1-DEV'; public const VERSION_CODENAME = 'River'; /** From a7d925e11838be178639fa69271b23cb29e70e1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Mon, 30 Aug 2021 16:41:51 +0200 Subject: [PATCH 26/80] TypeAlternationTransformer - fix for promoted properties --- .../Transformer/TypeAlternationTransformer.php | 1 + .../Fixer/Whitespace/TypesSpacesFixerTest.php | 18 +++++++++++++++++- .../TypeAlternationTransformerTest.php | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Tokenizer/Transformer/TypeAlternationTransformer.php b/src/Tokenizer/Transformer/TypeAlternationTransformer.php index 9ebf9176d43..22509f359cd 100644 --- a/src/Tokenizer/Transformer/TypeAlternationTransformer.php +++ b/src/Tokenizer/Transformer/TypeAlternationTransformer.php @@ -64,6 +64,7 @@ public function process(Tokens $tokens, Token $token, int $index): void CT::T_TYPE_COLON, // `:` is part of a function return type `foo(): X|Y` CT::T_TYPE_ALTERNATION, // `|` is part of a union (chain) `X|Y` T_STATIC, T_VAR, T_PUBLIC, T_PROTECTED, T_PRIVATE, // `var X|Y $a;`, `private X|Y $a` or `public static X|Y $a` + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, // promoted properties ])) { $this->replaceToken($tokens, $index); diff --git a/tests/Fixer/Whitespace/TypesSpacesFixerTest.php b/tests/Fixer/Whitespace/TypesSpacesFixerTest.php index e4fe1f35fde..0ad3ba8fbab 100644 --- a/tests/Fixer/Whitespace/TypesSpacesFixerTest.php +++ b/tests/Fixer/Whitespace/TypesSpacesFixerTest.php @@ -25,7 +25,6 @@ final class TypesSpacesFixerTest extends AbstractFixerTestCase { /** * @dataProvider provideFixCases - * @requires PHP 7.1 */ public function testFix(string $expected, ?string $input = null, array $configuration = []): void { @@ -128,5 +127,22 @@ public function provideFix80Cases() TypeB $x) {}', ['space' => 'single'], ]; + + yield [ + ' CT::T_TYPE_ALTERNATION, ], ]; + + yield 'promoted properties' => [ + ' CT::T_TYPE_ALTERNATION, + 26 => CT::T_TYPE_ALTERNATION, + 35 => CT::T_TYPE_ALTERNATION, + ], + ]; } } From 9ddbc01bf28c32518f95123c7c68b9effee8f355 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Tue, 10 Aug 2021 17:05:53 +0200 Subject: [PATCH 27/80] ClassAttributesSeparationFixer - fixes --- doc/ruleSets/PhpCsFixer.rst | 2 +- doc/ruleSets/Symfony.rst | 2 +- .../class_attributes_separation.rst | 33 +- doc/rules/whitespace/no_extra_blank_lines.rst | 22 +- .../ClassAttributesSeparationFixer.php | 425 ++++++++-------- .../Whitespace/NoExtraBlankLinesFixer.php | 19 +- src/RuleSet/Sets/PhpCsFixerSet.php | 1 - src/RuleSet/Sets/SymfonySet.php | 1 - tests/AutoReview/FixerFactoryTest.php | 1 + .../ClassAttributesSeparationFixerTest.php | 479 +++++++++++++++++- .../Whitespace/NoExtraBlankLinesFixerTest.php | 2 + ...butes_separation,no_extra_blank_lines.test | 28 + tests/Test/AbstractIntegrationCaseFactory.php | 18 + tests/Test/AbstractIntegrationTestCase.php | 5 + 14 files changed, 741 insertions(+), 297 deletions(-) create mode 100644 tests/Fixtures/Integration/priority/class_attributes_separation,no_extra_blank_lines.test diff --git a/doc/ruleSets/PhpCsFixer.rst b/doc/ruleSets/PhpCsFixer.rst index 3edd8678de3..6b35c813b91 100644 --- a/doc/ruleSets/PhpCsFixer.rst +++ b/doc/ruleSets/PhpCsFixer.rst @@ -30,7 +30,7 @@ Rules ``['strategy' => 'new_line_for_chained_calls']`` - `no_extra_blank_lines <./../rules/whitespace/no_extra_blank_lines.rst>`_ config: - ``['tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']]`` + ``['tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use']]`` - `no_null_property_initialization <./../rules/class_notation/no_null_property_initialization.rst>`_ - `no_superfluous_elseif <./../rules/control_structure/no_superfluous_elseif.rst>`_ - `no_useless_else <./../rules/control_structure/no_useless_else.rst>`_ diff --git a/doc/ruleSets/Symfony.rst b/doc/ruleSets/Symfony.rst index 5cfd476feea..d4914406e11 100644 --- a/doc/ruleSets/Symfony.rst +++ b/doc/ruleSets/Symfony.rst @@ -52,7 +52,7 @@ Rules - `no_empty_statement <./../rules/semicolon/no_empty_statement.rst>`_ - `no_extra_blank_lines <./../rules/whitespace/no_extra_blank_lines.rst>`_ config: - ``['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']]`` + ``['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use']]`` - `no_leading_namespace_whitespace <./../rules/namespace_notation/no_leading_namespace_whitespace.rst>`_ - `no_mixed_echo_print <./../rules/alias/no_mixed_echo_print.rst>`_ - `no_multiline_whitespace_around_double_arrow <./../rules/array_notation/no_multiline_whitespace_around_double_arrow.rst>`_ diff --git a/doc/rules/class_notation/class_attributes_separation.rst b/doc/rules/class_notation/class_attributes_separation.rst index 32ad8be710b..9b2156ef7ac 100644 --- a/doc/rules/class_notation/class_attributes_separation.rst +++ b/doc/rules/class_notation/class_attributes_separation.rst @@ -11,12 +11,11 @@ Configuration ``elements`` ~~~~~~~~~~~~ -Dictionary of ``const|method|property|trait_import`` => -``none|one|only_if_meta`` values. +Dictionary of ``const|method|property|trait_import`` => ``none|one`` values. Allowed types: ``array`` -Default value: ``['const' => 'one', 'method' => 'one', 'property' => 'one', 'trait_import' => 'one']`` +Default value: ``['const' => 'one', 'method' => 'one', 'property' => 'one', 'trait_import' => 'none']`` Examples -------- @@ -55,9 +54,9 @@ With configuration: ``['elements' => ['property' => 'one']]``. +++ New ['property' => 'only_if_meta']]``. -.. code-block:: diff - - --- Original - +++ New - ['property' => 'only_if_meta']]``. - .. code-block:: diff --- Original diff --git a/doc/rules/whitespace/no_extra_blank_lines.rst b/doc/rules/whitespace/no_extra_blank_lines.rst index 8f85be5b624..28ccf0b2cc4 100644 --- a/doc/rules/whitespace/no_extra_blank_lines.rst +++ b/doc/rules/whitespace/no_extra_blank_lines.rst @@ -198,24 +198,6 @@ With configuration: ``['tokens' => ['use']]``. Example #11 ~~~~~~~~~~~ -With configuration: ``['tokens' => ['use_trait']]``. - -.. code-block:: diff - - --- Original - +++ New - ['switch', 'case', 'default']]``. .. code-block:: diff @@ -240,9 +222,9 @@ The rule is part of the following rule sets: @PhpCsFixer Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``no_extra_blank_lines`` rule with the config below: - ``['tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']]`` + ``['tokens' => ['break', 'case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'switch', 'throw', 'use']]`` @Symfony Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``no_extra_blank_lines`` rule with the config below: - ``['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use', 'use_trait']]`` + ``['tokens' => ['case', 'continue', 'curly_brace_block', 'default', 'extra', 'parenthesis_brace_block', 'square_brace_block', 'switch', 'throw', 'use']]`` diff --git a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php index 0d0dabbc0a2..4bc55c708e3 100644 --- a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php +++ b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php @@ -41,26 +41,23 @@ */ final class ClassAttributesSeparationFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { - private const SPACING_NONE = 'none'; + /** + * @internal + */ + public const SPACING_NONE = 'none'; - private const SPACING_ONE = 'one'; + /** + * @internal + */ + public const SPACING_ONE = 'one'; private const SPACING_ONLY_IF_META = 'only_if_meta'; - private const SUPPORTED_SPACINGS = [self::SPACING_NONE, self::SPACING_ONE, self::SPACING_ONLY_IF_META]; - - private const SUPPORTED_TYPES = ['const', 'method', 'property', 'trait_import']; - /** * @var array */ private $classElementTypes = []; - /** - * @var array - */ - private $possibleMetadataKinds = []; - /** * {@inheritdoc} */ @@ -73,12 +70,6 @@ public function configure(array $configuration): void foreach ($this->configuration['elements'] as $elementType => $spacing) { $this->classElementTypes[$elementType] = $spacing; } - - $this->possibleMetadataKinds = [T_DOC_COMMENT]; - if (\defined('T_ATTRIBUTE')) { - // @todo remove check when PHP 8.0+ is required - $this->possibleMetadataKinds[] = T_ATTRIBUTE; - } } /** @@ -107,7 +98,7 @@ protected function bar() new CodeSample( ' ['property' => self::SPACING_ONLY_IF_META]] - ), - new VersionSpecificCodeSample( - 'getElementsByClass($tokens) as $class) { + $elements = $class['elements']; + $elementCount = \count($elements); - foreach (array_reverse($tokensAnalyzer->getClassyElements(), true) as $index => $element) { - if (!isset($this->classElementTypes[$element['type']])) { - continue; // not configured to be fixed + if (0 === $elementCount) { + continue; } - $spacing = $this->classElementTypes[$element['type']]; - - if ($element['classIndex'] !== $class) { - $class = $element['classIndex']; - $classStart = $tokens->getNextTokenOfKind($class, ['{']); - $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classStart); + if (isset($this->classElementTypes[$elements[0]['type']])) { + $this->fixSpaceBelowClassElement($tokens, $class); + $this->fixSpaceAboveClassElement($tokens, $class, 0); } - if ('method' === $element['type'] && !$tokens[$class]->isGivenKind(T_INTERFACE)) { - // method of class or trait - $attributes = $tokensAnalyzer->getMethodAttributes($index); - - $methodEnd = true === $attributes['abstract'] - ? $tokens->getNextTokenOfKind($index, [';']) - : $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tokens->getNextTokenOfKind($index, ['{'])) - ; - - $this->fixSpaceBelowClassMethod($tokens, $classEnd, $methodEnd, $spacing); - $this->fixSpaceAboveClassElement($tokens, $classStart, $index, $spacing); - - continue; + for ($index = 1; $index < $elementCount; ++$index) { + if (isset($this->classElementTypes[$elements[$index]['type']])) { + $this->fixSpaceAboveClassElement($tokens, $class, $index); + } } - - // `const`, `property` or `method` of an `interface` - $this->fixSpaceBelowClassElement($tokens, $classEnd, $tokens->getNextTokenOfKind($index, [';']), $spacing); - $this->fixSpaceAboveClassElement($tokens, $classStart, $index, $spacing); } } @@ -248,26 +206,30 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void protected function createConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ - (new FixerOptionBuilder('elements', sprintf('Dictionary of `%s` => `%s` values.', implode('|', self::SUPPORTED_TYPES), implode('|', self::SUPPORTED_SPACINGS)))) + (new FixerOptionBuilder('elements', 'Dictionary of `const|method|property|trait_import` => `none|one` values.')) ->setAllowedTypes(['array']) ->setAllowedValues([static function (array $option) { foreach ($option as $type => $spacing) { - if (!\in_array($type, self::SUPPORTED_TYPES, true)) { + $supportedTypes = ['const', 'method', 'property', 'trait_import']; + + if (!\in_array($type, $supportedTypes, true)) { throw new InvalidOptionsException( sprintf( 'Unexpected element type, expected any of "%s", got "%s".', - implode('", "', self::SUPPORTED_TYPES), + implode('", "', $supportedTypes), \gettype($type).'#'.$type ) ); } - if (!\in_array($spacing, self::SUPPORTED_SPACINGS, true)) { + $supportedSpacings = [self::SPACING_NONE, self::SPACING_ONE, self::SPACING_ONLY_IF_META]; + + if (!\in_array($spacing, $supportedSpacings, true)) { throw new InvalidOptionsException( sprintf( 'Unexpected spacing for element type "%s", expected any of "%s", got "%s".', $spacing, - implode('", "', self::SUPPORTED_SPACINGS), + implode('", "', $supportedSpacings), \is_object($spacing) ? \get_class($spacing) : (null === $spacing ? 'null' : \gettype($spacing).'#'.$spacing) ) ); @@ -280,197 +242,132 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn 'const' => self::SPACING_ONE, 'method' => self::SPACING_ONE, 'property' => self::SPACING_ONE, - 'trait_import' => self::SPACING_ONE, + 'trait_import' => self::SPACING_NONE, ]) ->getOption(), ]); } - /** - * Fix spacing below an element of a class, interface or trait. - * - * Deals with comments, PHPDocs and spaces above the element with respect to the position of the - * element within the class, interface or trait. - */ - private function fixSpaceBelowClassElement(Tokens $tokens, int $classEndIndex, int $elementEndIndex, string $spacing): void - { - for ($nextNotWhite = $elementEndIndex + 1;; ++$nextNotWhite) { - if (($tokens[$nextNotWhite]->isComment() || $tokens[$nextNotWhite]->isWhitespace()) && false === strpos($tokens[$nextNotWhite]->getContent(), "\n")) { - continue; - } - - break; - } - - if ($tokens[$nextNotWhite]->isWhitespace()) { - $nextNotWhite = $tokens->getNextNonWhitespace($nextNotWhite); - } - - $functionIndex = $tokens->getTokenNotOfKindsSibling($nextNotWhite - 1, 1, [T_ABSTRACT, T_FINAL, T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_WHITESPACE, T_COMMENT, T_DOC_COMMENT]); - - if ($tokens[$functionIndex]->isGivenKind(T_FUNCTION)) { - $this->correctLineBreaks($tokens, $elementEndIndex, $nextNotWhite, 2); - - return; - } - - $reqLineCount = $this->determineRequiredLineCount($tokens, $nextNotWhite, $classEndIndex, $spacing); - - $this->correctLineBreaks($tokens, $elementEndIndex, $nextNotWhite, $reqLineCount); - } - - /** - * Fix spacing below a method of a class or trait. - * - * Deals with comments, PHPDocs and spaces above the method with respect to the position of the - * method within the class or trait. - */ - private function fixSpaceBelowClassMethod(Tokens $tokens, int $classEndIndex, int $elementEndIndex, string $spacing): void - { - $nextNotWhite = $tokens->getNextNonWhitespace($elementEndIndex); - $reqLineCount = $this->determineRequiredLineCount($tokens, $nextNotWhite, $classEndIndex, $spacing); - - $this->correctLineBreaks($tokens, $elementEndIndex, $nextNotWhite, $reqLineCount); - } - /** * Fix spacing above an element of a class, interface or trait. * * Deals with comments, PHPDocs and spaces above the element with respect to the position of the * element within the class, interface or trait. - * - * @param int $classStartIndex index of the class Token the element is in - * @param int $elementIndex index of the element to fix */ - private function fixSpaceAboveClassElement(Tokens $tokens, int $classStartIndex, int $elementIndex, string $spacing): void + private function fixSpaceAboveClassElement(Tokens $tokens, array $class, int $elementIndex): void { - static $methodAttr = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; - - $nonWhiteAbove = null; - - // find out where the element definition starts - $firstElementAttributeIndex = $elementIndex; + $element = $class['elements'][$elementIndex]; + $elementAboveEnd = isset($class['elements'][$elementIndex + 1]) ? $class['elements'][$elementIndex + 1]['end'] : 0; + $nonWhiteAbove = $tokens->getPrevNonWhitespace($element['start']); - for ($i = $elementIndex; $i > $classStartIndex; --$i) { - $nonWhiteAbove = $tokens->getPrevNonWhitespace($i); + // element is directly after class open brace + if ($nonWhiteAbove === $class['open']) { + $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 1); - if (null !== $nonWhiteAbove && $tokens[$nonWhiteAbove]->isGivenKind($methodAttr)) { - $firstElementAttributeIndex = $nonWhiteAbove; - } else { - break; - } + return; } // deal with comments above an element if ($tokens[$nonWhiteAbove]->isGivenKind(T_COMMENT)) { - if (1 === $firstElementAttributeIndex - $nonWhiteAbove) { - // no white space found between comment and element start - $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 1); + // check if the comment belongs to the previous element + if ($elementAboveEnd === $nonWhiteAbove) { + $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], $this->determineRequiredLineCount($tokens, $class, $elementIndex)); return; } - // $tokens[$nonWhiteAbove + 1] is always a white space token here - if (substr_count($tokens[$nonWhiteAbove + 1]->getContent(), "\n") > 1) { - // more than one line break, always bring it back to 2 line breaks between the element start and what is above it - $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 2); + // more than one line break, always bring it back to 2 line breaks between the element start and what is above it + if ($tokens[$nonWhiteAbove + 1]->isWhitespace() && substr_count($tokens[$nonWhiteAbove + 1]->getContent(), "\n") > 1) { + $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 2); return; } // there are 2 cases: - if ($tokens[$nonWhiteAbove - 1]->isWhitespace() && substr_count($tokens[$nonWhiteAbove - 1]->getContent(), "\n") > 0) { + if ( + 1 === $element['start'] - $nonWhiteAbove + || $tokens[$nonWhiteAbove - 1]->isWhitespace() && substr_count($tokens[$nonWhiteAbove - 1]->getContent(), "\n") > 0 + || $tokens[$nonWhiteAbove + 1]->isWhitespace() && substr_count($tokens[$nonWhiteAbove + 1]->getContent(), "\n") > 0 + ) { // 1. The comment is meant for the element (although not a PHPDoc), // make sure there is one line break between the element and the comment... - $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 1); + $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 1); // ... and make sure there is blank line above the comment (with the exception when it is directly after a class opening) - $nonWhiteAbove = $this->findCommentBlockStart($tokens, $nonWhiteAbove); + $nonWhiteAbove = $this->findCommentBlockStart($tokens, $nonWhiteAbove, $elementAboveEnd); $nonWhiteAboveComment = $tokens->getPrevNonWhitespace($nonWhiteAbove); - $this->correctLineBreaks($tokens, $nonWhiteAboveComment, $nonWhiteAbove, $nonWhiteAboveComment === $classStartIndex ? 1 : 2); + $this->correctLineBreaks($tokens, $nonWhiteAboveComment, $nonWhiteAbove, $nonWhiteAboveComment === $class['open'] ? 1 : 2); } else { // 2. The comment belongs to the code above the element, // make sure there is a blank line above the element (i.e. 2 line breaks) - $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 2); + $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 2); } return; } - // deal with element with a PHPDoc above it - if ($tokens[$nonWhiteAbove]->isGivenKind(T_DOC_COMMENT)) { - // there should be one linebreak between the element and the PHPDoc above it - $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 1); - - // there should be one blank line between the PHPDoc and whatever is above (with the exception when it is directly after a class opening) - $nonWhiteAbovePHPDoc = $tokens->getPrevNonWhitespace($nonWhiteAbove); - $reqLineCount = $nonWhiteAbovePHPDoc === $classStartIndex ? 1 : 2; + // deal with element with a PHPDoc/attribute above it + if ($tokens[$nonWhiteAbove]->isGivenKind([T_DOC_COMMENT, CT::T_ATTRIBUTE_CLOSE])) { + // there should be one linebreak between the element and the attribute above it + $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], 1); - if ($tokens[$nonWhiteAbovePHPDoc]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { - // PHPDocs can have attributes adjacent to them, so adjust our comparison points - [$nonWhiteAbove, $nonWhiteAbovePHPDoc, $reqLineCount] = $this->getAttributePhpdocSequenceOffset($tokens, $nonWhiteAbovePHPDoc, $classStartIndex); - } + // make sure there is blank line above the comment (with the exception when it is directly after a class opening) + $nonWhiteAbove = $this->findCommentBlockStart($tokens, $nonWhiteAbove, $elementAboveEnd); + $nonWhiteAboveComment = $tokens->getPrevNonWhitespace($nonWhiteAbove); - $this->correctLineBreaks($tokens, $nonWhiteAbovePHPDoc, $nonWhiteAbove, $reqLineCount); + $this->correctLineBreaks($tokens, $nonWhiteAboveComment, $nonWhiteAbove, $nonWhiteAboveComment === $class['open'] ? 1 : 2); return; } - // deal with element with an attribute above it - if ($tokens[$nonWhiteAbove]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { - // there should be one linebreak between the element and the attribute above it - $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 1); - - // make sure there is blank line above the attribute comment - // with the exception when it is directly after a class opening or has an adjacent PHPDoc - [$nonWhiteAbove, $nonWhiteAboveComment, $reqLineCount] = $this->getAttributePhpdocSequenceOffset($tokens, $nonWhiteAbove, $classStartIndex); + $this->correctLineBreaks($tokens, $nonWhiteAbove, $element['start'], $this->determineRequiredLineCount($tokens, $class, $elementIndex)); + } - $this->correctLineBreaks($tokens, $nonWhiteAboveComment, $nonWhiteAbove, $reqLineCount); + private function determineRequiredLineCount(Tokens $tokens, array $class, int $elementIndex): int + { + $type = $class['elements'][$elementIndex]['type']; + $spacing = $this->classElementTypes[$type]; - return; + if (self::SPACING_ONE === $spacing) { + return 2; } - $reqLineCount = $this->determineRequiredLineCount($tokens, $nonWhiteAbove, $classStartIndex, $spacing); + if (self::SPACING_NONE === $spacing) { + if (!isset($class['elements'][$elementIndex + 1])) { + return 1; + } - $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, $reqLineCount); - } + $aboveElement = $class['elements'][$elementIndex + 1]; - /** - * @return array - */ - private function getAttributePhpdocSequenceOffset(Tokens $tokens, int $attributeCloseIndex, int $classStartIndex): array - { - $attributeStartIndex = $this->findAttributeBlockStart($tokens, $attributeCloseIndex); - $nonWhiteAboveAttribute = $tokens->getNonWhitespaceSibling($attributeStartIndex, -1); - $reqLineCount = $nonWhiteAboveAttribute === $classStartIndex || $tokens[$nonWhiteAboveAttribute]->isGivenKind(T_DOC_COMMENT) ? 1 : 2; + if ($aboveElement['type'] !== $type) { + return 2; + } - return [$attributeStartIndex, $nonWhiteAboveAttribute, $reqLineCount]; - } + $aboveElementDocCandidateIndex = $tokens->getPrevNonWhitespace($aboveElement['start']); - private function determineRequiredLineCount(Tokens $tokens, int $notWhiteIndex, int $classStartOrEndIndex, string $spacing): int - { - // if the two indices are equal, this means the index is either at the - // start or end of the class and no additional line breaks are needed - if ($notWhiteIndex === $classStartOrEndIndex) { - return 1; + return $tokens[$aboveElementDocCandidateIndex]->isGivenKind([T_DOC_COMMENT, CT::T_ATTRIBUTE_CLOSE]) ? 2 : 1; } - if (self::SPACING_NONE === $spacing) { - return 1; - } + if (self::SPACING_ONLY_IF_META === $spacing) { + $aboveElementDocCandidateIndex = $tokens->getPrevNonWhitespace($class['elements'][$elementIndex]['start']); - if (self::SPACING_ONE === $spacing) { - return 2; + return $tokens[$aboveElementDocCandidateIndex]->isGivenKind([T_DOC_COMMENT, CT::T_ATTRIBUTE_CLOSE]) ? 2 : 1; } - if (self::SPACING_ONLY_IF_META === $spacing && $tokens[$notWhiteIndex]->isGivenKind($this->possibleMetadataKinds)) { - return 2; - } + throw new \RuntimeException(sprintf('Unknown spacing "%s".', $spacing)); + } + + private function fixSpaceBelowClassElement(Tokens $tokens, array $class): void + { + $element = $class['elements'][0]; - return 1; + // if this is last element fix; fix to the class end `}` here if appropriate + if ($class['close'] === $tokens->getNextNonWhitespace($element['end'])) { + $this->correctLineBreaks($tokens, $element['end'], $class['close'], 1); + } } - private function correctLineBreaks(Tokens $tokens, int $startIndex, int $endIndex, int $reqLineCount = 2): void + private function correctLineBreaks(Tokens $tokens, int $startIndex, int $endIndex, int $reqLineCount): void { $lineEnding = $this->whitespacesConfig->getLineEnding(); @@ -524,22 +421,26 @@ private function correctLineBreaks(Tokens $tokens, int $startIndex, int $endInde } } - private function getLineBreakCount(Tokens $tokens, int $whiteSpaceStartIndex, int $whiteSpaceEndIndex): int + private function getLineBreakCount(Tokens $tokens, int $startIndex, int $endIndex): int { $lineCount = 0; - for ($i = $whiteSpaceStartIndex; $i < $whiteSpaceEndIndex; ++$i) { + for ($i = $startIndex; $i < $endIndex; ++$i) { $lineCount += substr_count($tokens[$i]->getContent(), "\n"); } return $lineCount; } - private function findCommentBlockStart(Tokens $tokens, int $commentIndex): int + private function findCommentBlockStart(Tokens $tokens, int $start, int $elementAboveEnd): int { - $start = $commentIndex; + for ($i = $start; $i > $elementAboveEnd; --$i) { + if ($tokens[$i]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { + $start = $i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ATTRIBUTE, $i); + + continue; + } - for ($i = $commentIndex - 1; $i > 0; --$i) { if ($tokens[$i]->isComment()) { $start = $i; @@ -554,25 +455,121 @@ private function findCommentBlockStart(Tokens $tokens, int $commentIndex): int return $start; } - /** - * @param int $index attribute close index - */ - private function findAttributeBlockStart(Tokens $tokens, int $index): int + private function getElementsByClass(Tokens $tokens): \Generator { - $start = $index = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ATTRIBUTE, $index); + $tokensAnalyzer = new TokensAnalyzer($tokens); + $class = $classIndex = false; + $elements = $tokensAnalyzer->getClassyElements(); - for ($i = $index - 1; $i > 0; --$i) { - if ($tokens[$i]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { - $start = $i = $tokens->findBlockStart(Tokens::BLOCK_TYPE_ATTRIBUTE, $i); + for (end($elements);; prev($elements)) { + $index = key($elements); - continue; + if (null === $index) { + break; } - if (!$tokens[$i]->isWhitespace() || $this->getLineBreakCount($tokens, $i, $i + 1) > 1) { + $element = current($elements); + $element['index'] = $index; + + if ($element['classIndex'] !== $classIndex) { + if (false !== $class) { + yield $class; + } + + $classIndex = $element['classIndex']; + $classOpen = $tokens->getNextTokenOfKind($classIndex, ['{']); + $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpen); + $class = [ + 'index' => $classIndex, + 'open' => $classOpen, + 'close' => $classEnd, + 'elements' => [], + ]; + } + + unset($element['classIndex']); + $element['start'] = $this->getFirstTokenIndexOfClassElement($tokens, $class, $element); + $element['end'] = $this->getLastTokenIndexOfClassElement($tokens, $class, $element, $tokensAnalyzer); + + $class['elements'][] = $element; // reset the key by design + } + + if (false !== $class) { + yield $class; + } + } + + private function getFirstTokenIndexOfClassElement(Tokens $tokens, array $class, array $element): int + { + static $methodAttr = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; + + $firstElementAttributeIndex = $element['index']; + + while ($firstElementAttributeIndex > $class['open']) { + $nonWhiteAbove = $tokens->getPrevMeaningfulToken($firstElementAttributeIndex); + + if (null !== $nonWhiteAbove && $tokens[$nonWhiteAbove]->isGivenKind($methodAttr)) { + $firstElementAttributeIndex = $nonWhiteAbove; + } else { break; } } - return $start; + return $firstElementAttributeIndex; + } + + // including trailing single line comments if belonging to the class element + private function getLastTokenIndexOfClassElement(Tokens $tokens, array $class, array $element, TokensAnalyzer $tokensAnalyzer): int + { + // find last token of the element + if ('method' === $element['type'] && !$tokens[$class['index']]->isGivenKind(T_INTERFACE)) { + $attributes = $tokensAnalyzer->getMethodAttributes($element['index']); + + if (true === $attributes['abstract']) { + $elementEndIndex = $tokens->getNextTokenOfKind($element['index'], [';']); + } else { + $elementEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tokens->getNextTokenOfKind($element['index'], ['{'])); + } + } elseif ('trait_import' === $element['type']) { + $elementEndIndex = $element['index']; + + do { + $elementEndIndex = $tokens->getNextMeaningfulToken($elementEndIndex); + } while ($tokens[$elementEndIndex]->isGivenKind([T_STRING, T_NS_SEPARATOR])); + + if (!$tokens[$elementEndIndex]->equals(';')) { + $elementEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tokens->getNextTokenOfKind($element['index'], ['{'])); + } + } else { // const or property + $elementEndIndex = $tokens->getNextTokenOfKind($element['index'], [';']); + } + + $singleLineElement = true; + + for ($i = $element['index'] + 1; $i < $elementEndIndex; ++$i) { + if (false !== strpos($tokens[$i]->getContent(), "\n")) { + $singleLineElement = false; + + break; + } + } + + if ($singleLineElement) { + do { + $nextToken = $tokens[$elementEndIndex + 1]; + + if (($nextToken->isComment() || $nextToken->isWhitespace()) && false === strpos($nextToken->getContent(), "\n")) { + ++$elementEndIndex; + } else { + break; + } + } while (true); + + if ($tokens[$elementEndIndex]->isWhitespace()) { + $elementEndIndex = $tokens->getPrevNonWhitespace($elementEndIndex); + } + } + + return $elementEndIndex; } } diff --git a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php index e7d71c0f703..283b5303359 100644 --- a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php +++ b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php @@ -29,6 +29,7 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\Tokenizer\TokensAnalyzer; +use PhpCsFixer\Utils; /** * @author Dariusz RumiƄski @@ -80,6 +81,10 @@ final class NoExtraBlankLinesFixer extends AbstractFixer implements Configurable */ public function configure(array $configuration): void { + if (isset($configuration['tokens']) && \in_array('use_trait', $configuration['tokens'], true)) { + Utils::triggerDeprecation(new \RuntimeException('Option "use_trait" is deprecated, use the rule `class_attributes_separation` with `elements: trait_import` instead.')); + } + parent::configure($configuration); static $reprToTokenMap = [ @@ -248,18 +253,6 @@ class Bar ), new CodeSample( ' ['use_trait']] - ), - new CodeSample( - ' true, diff --git a/src/RuleSet/Sets/SymfonySet.php b/src/RuleSet/Sets/SymfonySet.php index e153c88bebd..28377897c9e 100644 --- a/src/RuleSet/Sets/SymfonySet.php +++ b/src/RuleSet/Sets/SymfonySet.php @@ -86,7 +86,6 @@ public function getRules(): array 'switch', 'throw', 'use', - 'use_trait', ], ], 'no_leading_namespace_whitespace' => true, diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 7a186f73dab..7d6dc4832d2 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -78,6 +78,7 @@ public function provideFixersPriorityCases() [$fixers['braces'], $fixers['method_chaining_indentation']], [$fixers['class_attributes_separation'], $fixers['braces']], [$fixers['class_attributes_separation'], $fixers['indentation_type']], + [$fixers['class_attributes_separation'], $fixers['no_extra_blank_lines']], [$fixers['class_definition'], $fixers['braces']], [$fixers['class_keyword_remove'], $fixers['no_unused_imports']], [$fixers['combine_consecutive_issets'], $fixers['multiline_whitespace_before_semicolons']], diff --git a/tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php b/tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php index 8d846e03fd2..9cd6159b624 100644 --- a/tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php +++ b/tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php @@ -26,6 +26,171 @@ */ final class ClassAttributesSeparationFixerTest extends AbstractFixerTestCase { + /** + * @dataProvider provideFixCases + */ + public function testFixCases(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFixCases(): \Generator + { + yield [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + 'fixer, 'findCommentBlockStart'); $method->setAccessible(true); - $result = $method->invoke($this->fixer, $tokens, $index); + $result = $method->invoke($this->fixer, $tokens, $index, 0); static::assertSame( $expected, $result, @@ -392,7 +557,6 @@ public static function method145() } abstract protected function method245(); - // comment final private function method345() @@ -949,6 +1113,232 @@ public function testWithConfig(string $expected, string $input, array $config): public function provideConfigCases() { return [ + 'multi line property' => [ + ' true, + 2 => false, + ]; + + // comment2 + private $bar = 1; +}', + ' true, + 2 => false, + ]; // comment2 + private $bar = 1; +}', + ['elements' => ['property' => 'one']], + ], + 'trait group import none' => [ + ' ['trait_import' => 'none']], + ], + [ + ' ['property' => 'none']], + ], + [ + ' ['const' => 'none']], + ], + 'trait group import 5843' => [ + ' ['method' => 'one', 'trait_import' => 'one']], + ], + [ + ' ['method' => 'one', 'trait_import' => 'one']], + ], + 'trait group import 5852' => [ + ' ['const' => 'one', 'method' => 'one', 'property' => 'one', 'trait_import' => 'none']], + ], + [ + ' ['const' => 'one', 'method' => 'one', 'property' => 'one']], + ], [ ' ['const' => 'only_if_meta']], @@ -1271,6 +1670,31 @@ public function __destruct() {} ', ['elements' => ['const' => 'only_if_meta', 'property' => 'only_if_meta', 'method' => 'only_if_meta']], ], + [ + ' ['property' => 'none', 'trait_import' => 'none']], + ], ]; } @@ -1392,9 +1816,12 @@ public function H1(){} * @dataProvider provideFix74Cases * @requires PHP 7.4 */ - public function testFix74(string $expected, ?string $input, array $config): void + public function testFix74(string $expected, ?string $input = null, array $config = null): void { - $this->fixer->configure($config); + if (null !== $config) { + $this->fixer->configure($config); + } + $this->doTest($expected, $input); } @@ -1418,7 +1845,6 @@ class Foo { public iterable $baz; var ? Foo\Bar $qux; }', - ['elements' => ['property' => 'one']], ]; yield [ @@ -1433,7 +1859,6 @@ class Foo { private array $foo; private array $bar; }', - ['elements' => ['property' => 'one']], ]; yield [ @@ -1479,9 +1904,12 @@ class Entity * @dataProvider provideFixPhp80Cases * @requires PHP 8.0 */ - public function testFixPhp80(string $expected, ?string $input, array $config): void + public function testFixPhp80(string $expected, ?string $input, array $config = null): void { - $this->fixer->configure($config); + if (null !== $config) { + $this->fixer->configure($config); + } + $this->doTest($expected, $input); } @@ -1524,7 +1952,6 @@ class User1 }', - ['elements' => ['property' => 'one']], ]; yield 'attributes minimal' => [ @@ -1535,17 +1962,15 @@ class User2{ }', ' ['property' => 'one']], ]; - yield 'attributes not blocks' => [ + yield 'attribute block' => [ ' "Foo"])] private $email; }', @@ -1555,10 +1980,8 @@ class User3 { private $id; #[ORM\Column("string")] - #[Assert\Email(["message" => "Foo"])] private $email; }', - ['elements' => ['property' => 'one']], ]; yield 'constructor property promotion' => [ @@ -1584,7 +2007,6 @@ public function __construct( private float $z = 0.0, ) {} }', - ['elements' => ['property' => 'one', 'method' => 'one']], ]; yield 'typed properties' => [ @@ -1605,7 +2027,6 @@ class Foo { private int | float | null $c; private int | float | null $d; }', - ['elements' => ['property' => 'one']], ]; yield 'attributes with conditional spacing' => [ @@ -1681,6 +2102,30 @@ class User ', ['elements' => ['property' => 'only_if_meta']], ]; + + yield [ + ' "Foo"])] + private $email; + + private $foo1; #1 + private $foo2; /* @2 */ +}', + ' "Foo"])] + + private $email; + + private $foo1; #1 + + private $foo2; /* @2 */ +}', + ['elements' => ['property' => 'none']], + ]; } /** @@ -1698,7 +2143,6 @@ public function provideFixClassesWithTraitsCases(): iterable class Foo { use SomeTrait1; - use SomeTrait2; public function Bar(){} @@ -1708,6 +2152,7 @@ public function Bar(){} class Foo { use SomeTrait1; + use SomeTrait2; public function Bar(){} } diff --git a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php index 59e64dc8579..33080e20462 100644 --- a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php +++ b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php @@ -631,9 +631,11 @@ public function provideWithoutUsesCases() /** * @dataProvider provideRemoveBetweenUseTraitsCases + * @group legacy */ public function testRemoveBetweenUseTraits(string $expected, string $input): void { + $this->expectDeprecation('Option "use_trait" is deprecated, use the rule `class_attributes_separation` with `elements: trait_import` instead.'); $this->fixer->configure(['tokens' => ['use_trait']]); $this->doTest($expected, $input); diff --git a/tests/Fixtures/Integration/priority/class_attributes_separation,no_extra_blank_lines.test b/tests/Fixtures/Integration/priority/class_attributes_separation,no_extra_blank_lines.test new file mode 100644 index 00000000000..f995a577805 --- /dev/null +++ b/tests/Fixtures/Integration/priority/class_attributes_separation,no_extra_blank_lines.test @@ -0,0 +1,28 @@ +--TEST-- +Integration of fixers: class_attributes_separation,no_extra_blank_lines. +--RULESET-- +{"class_attributes_separation": {"elements": {"trait_import": "one"}}, "no_extra_blank_lines": {"tokens": ["use_trait"]}} +--SETTINGS-- +{ + "deprecations": [ + "Option \"use_trait\" is deprecated, use the rule `class_attributes_separation` with `elements: trait_import` instead." + ] +} +--EXPECT-- +parseJson($config, [ 'checkPriority' => true, + 'deprecations' => [], ]); if (!\is_bool($parsed['checkPriority'])) { @@ -157,6 +158,23 @@ protected function determineSettings(SplFileInfo $file, ?string $config): array )); } + if (!\is_array($parsed['deprecations'])) { + throw new \InvalidArgumentException(sprintf( + 'Expected array value for "deprecations", got "%s".', + \is_object($parsed['deprecations']) ? \get_class($parsed['deprecations']) : \gettype($parsed['deprecations']).'#'.$parsed['deprecations'] + )); + } + + foreach ($parsed['deprecations'] as $index => $deprecation) { + if (!\is_string($deprecation)) { + throw new \InvalidArgumentException(sprintf( + 'Expected only string value for "deprecations", got "%s" @ index %d.', + \is_object($deprecation) ? \get_class($deprecation) : \gettype($deprecation).'#'.$deprecation, + $index + )); + } + } + return $parsed; } diff --git a/tests/Test/AbstractIntegrationTestCase.php b/tests/Test/AbstractIntegrationTestCase.php index 5309fc93041..dbe8fa5f00e 100644 --- a/tests/Test/AbstractIntegrationTestCase.php +++ b/tests/Test/AbstractIntegrationTestCase.php @@ -122,9 +122,14 @@ protected function tearDown(): void * * @see doTest() * @large + * @group legacy */ public function testIntegration(IntegrationCase $case): void { + foreach ($case->getSettings()['deprecations'] as $deprecation) { + $this->expectDeprecation($deprecation); + } + $this->doTest($case); } From d305690f2d81856f5c313430df6ce21af2914c48 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Mon, 30 Aug 2021 17:24:03 +0000 Subject: [PATCH 28/80] PSR12 - ClassDefinition - space_before_parenthesis --- doc/ruleSets/PSR12.rst | 3 +++ doc/rules/class_notation/class_definition.rst | 4 +++- src/RuleSet/Sets/PSR12Set.php | 1 + tests/Fixtures/Integration/set/@PSR12_php70.test-out.php | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/ruleSets/PSR12.rst b/doc/ruleSets/PSR12.rst index ce4856bad54..2595a1b0299 100644 --- a/doc/ruleSets/PSR12.rst +++ b/doc/ruleSets/PSR12.rst @@ -12,6 +12,9 @@ Rules - `braces <./../rules/basic/braces.rst>`_ config: ``['allow_single_line_anonymous_class_with_empty_body' => true]`` +- `class_definition <./../rules/class_notation/class_definition.rst>`_ + config: + ``['space_before_parenthesis' => true]`` - `compact_nullable_typehint <./../rules/whitespace/compact_nullable_typehint.rst>`_ - `declare_equal_normalize <./../rules/language_construct/declare_equal_normalize.rst>`_ - `lowercase_cast <./../rules/cast_notation/lowercase_cast.rst>`_ diff --git a/doc/rules/class_notation/class_definition.rst b/doc/rules/class_notation/class_definition.rst index a436af6daf4..58f8966c5da 100644 --- a/doc/rules/class_notation/class_definition.rst +++ b/doc/rules/class_notation/class_definition.rst @@ -159,7 +159,9 @@ Rule sets The rule is part of the following rule sets: @PSR12 - Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``class_definition`` rule with the default config. + Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``class_definition`` rule with the config below: + + ``['space_before_parenthesis' => true]`` @PSR2 Using the `@PSR2 <./../../ruleSets/PSR2.rst>`_ rule set will enable the ``class_definition`` rule with the default config. diff --git a/src/RuleSet/Sets/PSR12Set.php b/src/RuleSet/Sets/PSR12Set.php index bc6a8ea6e2b..907a01208d6 100644 --- a/src/RuleSet/Sets/PSR12Set.php +++ b/src/RuleSet/Sets/PSR12Set.php @@ -29,6 +29,7 @@ public function getRules(): array 'braces' => [ 'allow_single_line_anonymous_class_with_empty_body' => true, ], + 'class_definition' => ['space_before_parenthesis' => true], // defined in PSR2 ¶8. Anonymous Classes 'compact_nullable_typehint' => true, 'declare_equal_normalize' => true, 'lowercase_cast' => true, diff --git a/tests/Fixtures/Integration/set/@PSR12_php70.test-out.php b/tests/Fixtures/Integration/set/@PSR12_php70.test-out.php index 57898fa26a8..edaa5ebd054 100644 --- a/tests/Fixtures/Integration/set/@PSR12_php70.test-out.php +++ b/tests/Fixtures/Integration/set/@PSR12_php70.test-out.php @@ -6,4 +6,4 @@ function foo(): void { } -$class = new class() {}; +$class = new class () {}; From fb1a9f77639a029cd7f17cc91f38d298c4ad33fb Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Tue, 31 Aug 2021 08:00:15 +0200 Subject: [PATCH 29/80] typo --- src/RuleSet/Sets/PSR12Set.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RuleSet/Sets/PSR12Set.php b/src/RuleSet/Sets/PSR12Set.php index 907a01208d6..9a8e4c1bf1e 100644 --- a/src/RuleSet/Sets/PSR12Set.php +++ b/src/RuleSet/Sets/PSR12Set.php @@ -29,7 +29,7 @@ public function getRules(): array 'braces' => [ 'allow_single_line_anonymous_class_with_empty_body' => true, ], - 'class_definition' => ['space_before_parenthesis' => true], // defined in PSR2 ¶8. Anonymous Classes + 'class_definition' => ['space_before_parenthesis' => true], // defined in PSR12 ¶8. Anonymous Classes 'compact_nullable_typehint' => true, 'declare_equal_normalize' => true, 'lowercase_cast' => true, From 694946fb61127c3e616b07f80aec4416cef602dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sat, 28 Aug 2021 11:09:26 +0200 Subject: [PATCH 30/80] NativeFunctionCasingFixer - fix for attributes --- .../Casing/NativeFunctionCasingFixer.php | 27 +++-------------- .../Casing/NativeFunctionCasingFixerTest.php | 30 +++++++++++++++++-- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/Fixer/Casing/NativeFunctionCasingFixer.php b/src/Fixer/Casing/NativeFunctionCasingFixer.php index db9e4fe9345..436baaaf7d7 100644 --- a/src/Fixer/Casing/NativeFunctionCasingFixer.php +++ b/src/Fixer/Casing/NativeFunctionCasingFixer.php @@ -18,7 +18,7 @@ use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\Tokenizer\CT; +use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -61,6 +61,8 @@ public function isCandidate(Tokens $tokens): bool */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { + $functionsAnalyzer = new FunctionsAnalyzer(); + static $nativeFunctionNames = null; if (null === $nativeFunctionNames) { @@ -69,30 +71,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void for ($index = 0, $count = $tokens->count(); $index < $count; ++$index) { // test if we are at a function all - if (!$tokens[$index]->isGivenKind(T_STRING)) { - continue; - } - - $next = $tokens->getNextMeaningfulToken($index); - if (!$tokens[$next]->equals('(')) { - $index = $next; - + if (!$functionsAnalyzer->isGlobalFunctionCall($tokens, $index)) { continue; } - $functionNamePrefix = $tokens->getPrevMeaningfulToken($index); - if ($tokens[$functionNamePrefix]->isGivenKind([T_DOUBLE_COLON, T_NEW, T_FUNCTION, CT::T_RETURN_REF]) || $tokens[$functionNamePrefix]->isObjectOperator()) { - continue; - } - - if ($tokens[$functionNamePrefix]->isGivenKind(T_NS_SEPARATOR)) { - // skip if the call is to a constructor or to a function in a namespace other than the default - $prev = $tokens->getPrevMeaningfulToken($functionNamePrefix); - if ($tokens[$prev]->isGivenKind([T_STRING, T_NEW])) { - continue; - } - } - // test if the function call is to a native PHP function $lower = strtolower($tokens[$index]->getContent()); if (!\array_key_exists($lower, $nativeFunctionNames)) { @@ -100,7 +82,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $tokens[$index] = new Token([T_STRING, $nativeFunctionNames[$lower]]); - $index = $next; } } diff --git a/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php b/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php index 56f276d1894..4abf419e6af 100644 --- a/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php +++ b/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php @@ -154,6 +154,16 @@ function &Next() { $next2 = & \Next($array2); ', ], + [ + 'name); + } + }', + ], ]; } @@ -186,10 +196,26 @@ public function provideFix73Cases() } /** + * @dataProvider provideFix80Cases * @requires PHP 8.0 */ - public function testFix80(): void + public function testFix80(string $expected): void { - $this->doTest('STRTOLOWER(1,);'); + $this->doTest($expected); + } + + public function provideFix80Cases(): iterable + { + yield ['STRTOLOWER(1,);']; + + yield [ + ' Date: Sat, 28 Aug 2021 22:22:31 +0000 Subject: [PATCH 31/80] Remove PHP version specific code sample constraint when not needed --- doc/rules/class_notation/class_definition.rst | 17 ++--------- .../phpdoc_to_param_type.rst | 25 ++++------------ .../phpdoc_to_return_type.rst | 25 +++++----------- doc/rules/import/ordered_imports.rst | 27 +++++------------ .../phpdoc/no_superfluous_phpdoc_tags.rst | 26 +++-------------- src/Fixer/Alias/ArrayPushFixer.php | 5 ++-- src/Fixer/ArrayNotation/ArraySyntaxFixer.php | 7 ++--- .../Basic/NonPrintableCharacterFixer.php | 5 +--- .../Casing/LowercaseStaticReferenceFixer.php | 7 ++--- ...tiveFunctionTypeDeclarationCasingFixer.php | 10 +++---- .../ClassNotation/ClassDefinitionFixer.php | 9 +----- .../ClassNotation/SelfStaticAccessorFixer.php | 7 ++--- .../ClassNotation/VisibilityRequiredFixer.php | 5 +--- .../CombineNestedDirnameFixer.php | 8 ++--- ...ypeDeclarationForDefaultNullValueFixer.php | 11 +++---- .../PhpdocToParamTypeFixer.php | 29 +++++++------------ .../PhpdocToReturnTypeFixer.php | 20 +++++-------- .../RegularCallableCallFixer.php | 7 ++--- .../ReturnTypeDeclarationFixer.php | 16 ++++------ .../FunctionNotation/VoidReturnFixer.php | 8 ++--- .../Import/FullyQualifiedStrictTypesFixer.php | 7 ++--- src/Fixer/Import/GroupImportFixer.php | 8 ++--- src/Fixer/Import/OrderedImportsFixer.php | 19 ++++-------- .../ExplicitIndirectVariableFixer.php | 7 ++--- .../SingleSpaceAfterConstructFixer.php | 5 +--- src/Fixer/ListNotation/ListSyntaxFixer.php | 11 +++---- .../Operator/TernaryToNullCoalescingFixer.php | 8 ++--- .../Phpdoc/NoSuperfluousPhpdocTagsFixer.php | 17 ++--------- .../SimplifiedNullReturnFixer.php | 6 +--- src/Fixer/Strict/DeclareStrictTypesFixer.php | 8 ++--- .../CompactNullableTypehintFixer.php | 8 ++--- 31 files changed, 107 insertions(+), 271 deletions(-) diff --git a/doc/rules/class_notation/class_definition.rst b/doc/rules/class_notation/class_definition.rst index f9a50bdd67f..18cc9d4793f 100644 --- a/doc/rules/class_notation/class_definition.rst +++ b/doc/rules/class_notation/class_definition.rst @@ -64,21 +64,10 @@ Example #1 { } -Example #2 -~~~~~~~~~~ - -*Default* configuration. - -.. code-block:: diff - - --- Original - +++ New - true]``. @@ -95,7 +84,7 @@ With configuration: ``['single_line' => true]``. +class Foo extends Bar implements Baz, BarBaz {} -Example #4 +Example #3 ~~~~~~~~~~ With configuration: ``['single_item_single_line' => true]``. @@ -112,7 +101,7 @@ With configuration: ``['single_item_single_line' => true]``. +class Foo extends Bar implements Baz {} -Example #5 +Example #4 ~~~~~~~~~~ With configuration: ``['multi_line_extends_each_single_line' => true]``. diff --git a/doc/rules/function_notation/phpdoc_to_param_type.rst b/doc/rules/function_notation/phpdoc_to_param_type.rst index d5ebf26293c..a176e966d64 100644 --- a/doc/rules/function_notation/phpdoc_to_param_type.rst +++ b/doc/rules/function_notation/phpdoc_to_param_type.rst @@ -40,30 +40,17 @@ Example #1 +++ New false]``. .. code-block:: diff diff --git a/doc/rules/function_notation/phpdoc_to_return_type.rst b/doc/rules/function_notation/phpdoc_to_return_type.rst index 72885bdc93d..2ea166cb253 100644 --- a/doc/rules/function_notation/phpdoc_to_return_type.rst +++ b/doc/rules/function_notation/phpdoc_to_return_type.rst @@ -41,27 +41,16 @@ Example #1 false]``. @@ -94,7 +83,7 @@ With configuration: ``['scalar_types' => false]``. /** @return string */ function bar() {} -Example #5 +Example #4 ~~~~~~~~~~ *Default* configuration. diff --git a/doc/rules/import/ordered_imports.rst b/doc/rules/import/ordered_imports.rst index f3d49cb3221..20d91fe0b19 100644 --- a/doc/rules/import/ordered_imports.rst +++ b/doc/rules/import/ordered_imports.rst @@ -39,8 +39,11 @@ Example #1 --- Original +++ New 'length']``. Example #3 ~~~~~~~~~~ -*Default* configuration. - -.. code-block:: diff - - --- Original - +++ New - 'length', 'imports_order' => ['const', 'class', 'function']]``. .. code-block:: diff @@ -99,7 +86,7 @@ With configuration: ``['sort_algorithm' => 'length', 'imports_order' => ['const' use function CCC\AA; -use function DDD; -Example #5 +Example #4 ~~~~~~~~~~ With configuration: ``['sort_algorithm' => 'alpha', 'imports_order' => ['const', 'class', 'function']]``. @@ -122,7 +109,7 @@ With configuration: ``['sort_algorithm' => 'alpha', 'imports_order' => ['const', use function DDD; -use function CCC\AA; -Example #6 +Example #5 ~~~~~~~~~~ With configuration: ``['sort_algorithm' => 'none', 'imports_order' => ['const', 'class', 'function']]``. diff --git a/doc/rules/phpdoc/no_superfluous_phpdoc_tags.rst b/doc/rules/phpdoc/no_superfluous_phpdoc_tags.rst index 771067cf4ef..133e0a1e3fd 100644 --- a/doc/rules/phpdoc/no_superfluous_phpdoc_tags.rst +++ b/doc/rules/phpdoc/no_superfluous_phpdoc_tags.rst @@ -54,8 +54,10 @@ Example #1 /** - * @param Bar $bar - * @param mixed $baz + * + - * @return Baz */ - public function doFoo(Bar $bar, $baz) {} + public function doFoo(Bar $bar, $baz): Baz {} } Example #2 @@ -79,26 +81,6 @@ With configuration: ``['allow_mixed' => true]``. Example #3 ~~~~~~~~~~ -*Default* configuration. - -.. code-block:: diff - - --- Original - +++ New - true]``. .. code-block:: diff @@ -114,7 +96,7 @@ With configuration: ``['remove_inheritdoc' => true]``. public function doFoo(Bar $bar, $baz) {} } -Example #5 +Example #4 ~~~~~~~~~~ With configuration: ``['allow_unused_params' => true]``. diff --git a/src/Fixer/Alias/ArrayPushFixer.php b/src/Fixer/Alias/ArrayPushFixer.php index b4923b8870b..f333585a67e 100644 --- a/src/Fixer/Alias/ArrayPushFixer.php +++ b/src/Fixer/Alias/ArrayPushFixer.php @@ -15,10 +15,9 @@ namespace PhpCsFixer\Fixer\Alias; use PhpCsFixer\AbstractFixer; +use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer; use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; @@ -36,7 +35,7 @@ public function getDefinition(): FixerDefinitionInterface { return new FixerDefinition( 'Converts simple usages of `array_push($x, $y);` to `$x[] = $y;`.', - [new VersionSpecificCodeSample(" false] ), ], diff --git a/src/Fixer/Casing/LowercaseStaticReferenceFixer.php b/src/Fixer/Casing/LowercaseStaticReferenceFixer.php index 085296d1961..50dbcae22e4 100644 --- a/src/Fixer/Casing/LowercaseStaticReferenceFixer.php +++ b/src/Fixer/Casing/LowercaseStaticReferenceFixer.php @@ -18,8 +18,6 @@ use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -55,7 +53,7 @@ public function baz3(PaRent $x) } } '), - new VersionSpecificCodeSample( + new CodeSample( ' ['const']] ), ] diff --git a/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php b/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php index 878d50a9b8f..9d58286862a 100644 --- a/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php +++ b/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php @@ -15,10 +15,9 @@ namespace PhpCsFixer\Fixer\FunctionNotation; use PhpCsFixer\AbstractFixer; +use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -36,9 +35,8 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( 'Replace multiple nested calls of `dirname` by only one call with second `$level` parameter. Requires PHP >= 7.0.', [ - new VersionSpecificCodeSample( - " false] ), ], diff --git a/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php index 06e36dc8001..9121b0d039a 100644 --- a/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php @@ -16,10 +16,9 @@ use PhpCsFixer\AbstractPhpdocToTypeDeclarationFixer; use PhpCsFixer\DocBlock\Annotation; +use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -56,25 +55,18 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( 'EXPERIMENTAL: Takes `@param` annotations of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.', [ - new VersionSpecificCodeSample( + new CodeSample( ' false] ), ], @@ -143,7 +134,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - list($paramType, $isNullable) = $typeInfo; + [$paramType, $isNullable] = $typeInfo; $startIndex = $tokens->getNextTokenOfKind($index, ['(']); $variableIndex = $this->findCorrectVariable($tokens, $startIndex, $paramTypeAnnotation); diff --git a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php index 38e15cb2914..f1b3cfc03ca 100644 --- a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php @@ -15,6 +15,7 @@ namespace PhpCsFixer\Fixer\FunctionNotation; use PhpCsFixer\AbstractPhpdocToTypeDeclarationFixer; +use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\FixerDefinition\VersionSpecification; @@ -54,23 +55,17 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( 'EXPERIMENTAL: Takes `@return` annotation of non-mixed types and adjusts accordingly the function signature. Requires PHP >= 7.0.', [ - new VersionSpecificCodeSample( + new CodeSample( ' false] ), new VersionSpecificCodeSample( @@ -178,7 +172,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - list($returnType, $isNullable) = $typeInfo; + [$returnType, $isNullable] = $typeInfo; $startIndex = $tokens->getNextTokenOfKind($index, ['{', ';']); diff --git a/src/Fixer/FunctionNotation/RegularCallableCallFixer.php b/src/Fixer/FunctionNotation/RegularCallableCallFixer.php index d226737ee7b..d98acf1b72c 100644 --- a/src/Fixer/FunctionNotation/RegularCallableCallFixer.php +++ b/src/Fixer/FunctionNotation/RegularCallableCallFixer.php @@ -18,8 +18,6 @@ use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Tokenizer\Analyzer\ArgumentsAnalyzer; use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer; use PhpCsFixer\Tokenizer\Token; @@ -47,13 +45,12 @@ public function getDefinition(): FixerDefinitionInterface call_user_func_array($callback, [1, 2]); ' ), - new VersionSpecificCodeSample( + new CodeSample( ' 'none'] ), - new VersionSpecificCodeSample( + new CodeSample( " 'one'] ), ], diff --git a/src/Fixer/FunctionNotation/VoidReturnFixer.php b/src/Fixer/FunctionNotation/VoidReturnFixer.php index 84ccdd52f4c..c7d9243d37a 100644 --- a/src/Fixer/FunctionNotation/VoidReturnFixer.php +++ b/src/Fixer/FunctionNotation/VoidReturnFixer.php @@ -17,10 +17,9 @@ use PhpCsFixer\AbstractFixer; use PhpCsFixer\DocBlock\Annotation; use PhpCsFixer\DocBlock\DocBlock; +use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -39,9 +38,8 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( 'Add `void` return type to functions with missing or empty return statements, but priority is given to `@return` annotations. Requires PHP >= 7.1.', [ - new VersionSpecificCodeSample( - " self::SORT_LENGTH] ), - new VersionSpecificCodeSample( - " self::SORT_LENGTH, 'imports_order' => [ @@ -129,7 +124,7 @@ public function getDefinition(): FixerDefinitionInterface ], ] ), - new VersionSpecificCodeSample( + new CodeSample( ' self::SORT_ALPHA, 'imports_order' => [ @@ -151,7 +145,7 @@ public function getDefinition(): FixerDefinitionInterface ], ] ), - new VersionSpecificCodeSample( + new CodeSample( ' self::SORT_NONE, 'imports_order' => [ diff --git a/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php b/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php index d63355c64c8..dfca5ac4adc 100644 --- a/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php +++ b/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php @@ -15,10 +15,9 @@ namespace PhpCsFixer\Fixer\LanguageConstruct; use PhpCsFixer\AbstractFixer; +use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -36,7 +35,7 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( 'Add curly braces to indirect variables to make them clear to understand. Requires PHP >= 7.0.', [ - new VersionSpecificCodeSample( + new CodeSample( <<<'EOT' $callback($baz); EOT -, - new VersionSpecification(70000) ), ] ); diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index b0f0e67c757..160b08f08dc 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -23,8 +23,6 @@ use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Preg; use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; @@ -159,12 +157,11 @@ public function getDefinition(): FixerDefinitionInterface ], ] ), - new VersionSpecificCodeSample( + new CodeSample( ' [ 'yield_from', diff --git a/src/Fixer/ListNotation/ListSyntaxFixer.php b/src/Fixer/ListNotation/ListSyntaxFixer.php index a7bd701b016..02c3c34d7e1 100644 --- a/src/Fixer/ListNotation/ListSyntaxFixer.php +++ b/src/Fixer/ListNotation/ListSyntaxFixer.php @@ -20,10 +20,9 @@ use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; +use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -60,13 +59,11 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( 'List (`array` destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1.', [ - new VersionSpecificCodeSample( - " 'long'] ), ] diff --git a/src/Fixer/Operator/TernaryToNullCoalescingFixer.php b/src/Fixer/Operator/TernaryToNullCoalescingFixer.php index d0b5ce4230d..ac1a649fe99 100644 --- a/src/Fixer/Operator/TernaryToNullCoalescingFixer.php +++ b/src/Fixer/Operator/TernaryToNullCoalescingFixer.php @@ -15,10 +15,9 @@ namespace PhpCsFixer\Fixer\Operator; use PhpCsFixer\AbstractFixer; +use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; -use PhpCsFixer\FixerDefinition\VersionSpecification; -use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -35,9 +34,8 @@ public function getDefinition(): FixerDefinitionInterface return new FixerDefinition( 'Use `null` coalescing operator `??` where possible. Requires PHP >= 7.0.', [ - new VersionSpecificCodeSample( - " true]), - new VersionSpecificCodeSample('= 7.0.', [ - new VersionSpecificCodeSample( - " Date: Fri, 27 Aug 2021 09:04:04 +0000 Subject: [PATCH 32/80] DX: update PHPStan --- dev-tools/composer.json | 2 +- phpstan.neon | 4 ++++ tests/AutoReview/ProjectCodeTest.php | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/dev-tools/composer.json b/dev-tools/composer.json index 7c4695137a2..5b5e584bbce 100644 --- a/dev-tools/composer.json +++ b/dev-tools/composer.json @@ -9,7 +9,7 @@ "maglnet/composer-require-checker": "2.0.0", "mi-schi/phpmd-extension": "^4.3", "phpmd/phpmd": "^2.10.2", - "phpstan/phpstan": "0.12.92", + "phpstan/phpstan": "0.12.96", "phpstan/phpstan-phpunit": "0.12.21" }, "config": { diff --git a/phpstan.neon b/phpstan.neon index 5c1c6d3c8d8..ffd5911c81c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,4 +10,8 @@ parameters: - tests excludePaths: - tests/Fixtures + ignoreErrors: + - '/^Class [a-zA-Z\\]+ extends @final class PhpCsFixer\\(ConfigurationException\\InvalidConfigurationException|ConfigurationException\\InvalidFixerConfigurationException|Tokenizer\\Tokens)\.$/' + - '/^Unsafe call to private method [a-zA-Z\\]+::[a-zA-Z]+\(\) through static::\.$/' + - '/^\$this\(PhpCsFixer\\Tokenizer\\Tokens\) does not accept PhpCsFixer\\Tokenizer\\Token\|null\.$/' tipsOfTheDay: false diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index a4a7010dfad..d62f479e53e 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -798,6 +798,7 @@ static function (SplFileInfo $file) { ); $classes = array_filter($classes, static function (string $class): bool { + // @phpstan-ignore-next-line due to false positive reported in https://github.com/phpstan/phpstan/issues/5369 return is_subclass_of($class, TestCase::class); }); From 2cd192d6ad5b0ac75ad642f688887d19314e269a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Tue, 31 Aug 2021 09:26:02 +0200 Subject: [PATCH 33/80] Remove not needed requirements from fixtures --- tests/Fixtures/Integration/misc/PHP7_0.test | 2 -- tests/Fixtures/Integration/misc/PHP7_1.test | 2 -- .../misc/combine_nested_dirname,no_trailing_whitespace.test | 2 -- .../combine_nested_dirname,no_whitespace_in_blank_line.test | 2 -- ...declare_strict_types,single_blank_line_before_namespace.test | 2 -- .../Integration/misc/header_comment,declare_strict_types.test | 2 -- tests/Fixtures/Integration/misc/huge_array.test | 2 -- .../misc/single_import_per_statement,ordered_imports.test | 2 -- .../Integration/misc/void_return,phpdoc_to_return_type.test | 2 -- .../priority/combine_nested_dirname,method_argument_space.test | 2 -- .../combine_nested_dirname,no_spaces_inside_parenthesis.test | 2 -- .../declare_strict_types,blank_line_after_opening_tag.test | 2 -- .../priority/declare_strict_types,declare_equal_normalize.test | 2 -- .../priority/declare_strict_types,header_comment.test | 2 -- .../priority/dir_constant,combine_nested_dirname.test | 2 -- .../priority/list_syntax,binary_operator_spaces.test | 2 -- .../priority/list_syntax,ternary_operator_spaces.test | 2 -- .../priority/no_superfluous_phpdoc_tags,void_return.test | 2 -- ...efault_null_value,no_unreachable_default_argument_value.test | 2 -- ...phpdoc_return_self_reference,no_superfluous_phpdoc_tags.test | 2 -- .../priority/phpdoc_scalar,phpdoc_to_return_type.test | 2 -- .../phpdoc_to_param_type,no_superfluous_phpdoc_tags.test | 2 -- .../phpdoc_to_return_type,fully_qualified_strict_types.test | 2 -- .../phpdoc_to_return_type,no_superfluous_phpdoc_tags.test | 2 -- .../priority/phpdoc_to_return_type,return_type_declaration.test | 2 -- .../priority/phpdoc_types,phpdoc_to_return_type.test | 2 -- .../priority/simplified_null_return,void_return.test | 2 -- .../Fixtures/Integration/priority/single_line_throw,braces.test | 2 -- .../priority/void_return,phpdoc_no_empty_return.test | 2 -- .../priority/void_return,return_type_declaration.test | 2 -- tests/Fixtures/Integration/set/@PHP54Migration.test | 2 -- tests/Fixtures/Integration/set/@PSR12_php70.test | 2 -- tests/Fixtures/Integration/set/@PSR12_php71.test | 2 -- 33 files changed, 66 deletions(-) diff --git a/tests/Fixtures/Integration/misc/PHP7_0.test b/tests/Fixtures/Integration/misc/PHP7_0.test index da6c47d60ea..643f61949af 100644 --- a/tests/Fixtures/Integration/misc/PHP7_0.test +++ b/tests/Fixtures/Integration/misc/PHP7_0.test @@ -7,8 +7,6 @@ PHP 7.0 test. "random_api_migration": true, "visibility_required": {"elements": ["property", "method"]} } ---REQUIREMENTS-- -{"php": 70000} --EXPECT-- Date: Tue, 31 Aug 2021 09:24:41 +0200 Subject: [PATCH 34/80] SymfonySet - empty_loop_body - braces style --- doc/ruleSets/Symfony.rst | 3 +++ doc/rules/class_notation/class_definition.rst | 2 +- doc/rules/control_structure/empty_loop_body.rst | 7 ++++++- src/RuleSet/Sets/SymfonySet.php | 1 + 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/ruleSets/Symfony.rst b/doc/ruleSets/Symfony.rst index d4914406e11..4be545f8dd1 100644 --- a/doc/ruleSets/Symfony.rst +++ b/doc/ruleSets/Symfony.rst @@ -27,6 +27,9 @@ Rules - `clean_namespace <./../rules/namespace_notation/clean_namespace.rst>`_ - `concat_space <./../rules/operator/concat_space.rst>`_ - `echo_tag_syntax <./../rules/php_tag/echo_tag_syntax.rst>`_ +- `empty_loop_body <./../rules/control_structure/empty_loop_body.rst>`_ + config: + ``['style' => 'braces']`` - `fully_qualified_strict_types <./../rules/import/fully_qualified_strict_types.rst>`_ - `function_typehint_space <./../rules/function_notation/function_typehint_space.rst>`_ - `general_phpdoc_tag_rename <./../rules/phpdoc/general_phpdoc_tag_rename.rst>`_ diff --git a/doc/rules/class_notation/class_definition.rst b/doc/rules/class_notation/class_definition.rst index 817c34e73cc..630cf6c1128 100644 --- a/doc/rules/class_notation/class_definition.rst +++ b/doc/rules/class_notation/class_definition.rst @@ -129,7 +129,7 @@ With configuration: ``['multi_line_extends_each_single_line' => true]``. + FooBarBaz {} -Example #6 +Example #5 ~~~~~~~~~~ With configuration: ``['space_before_parenthesis' => true]``. diff --git a/doc/rules/control_structure/empty_loop_body.rst b/doc/rules/control_structure/empty_loop_body.rst index e6d03793396..794f78f2b7f 100644 --- a/doc/rules/control_structure/empty_loop_body.rst +++ b/doc/rules/control_structure/empty_loop_body.rst @@ -46,7 +46,12 @@ With configuration: ``['style' => 'braces']``. Rule sets --------- -The rule is part of the following rule set: +The rule is part of the following rule sets: @PhpCsFixer Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``empty_loop_body`` rule with the default config. + +@Symfony + Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``empty_loop_body`` rule with the config below: + + ``['style' => 'braces']`` diff --git a/src/RuleSet/Sets/SymfonySet.php b/src/RuleSet/Sets/SymfonySet.php index 28377897c9e..608cc6e9e26 100644 --- a/src/RuleSet/Sets/SymfonySet.php +++ b/src/RuleSet/Sets/SymfonySet.php @@ -49,6 +49,7 @@ public function getRules(): array 'clean_namespace' => true, 'concat_space' => true, 'echo_tag_syntax' => true, + 'empty_loop_body' => ['style' => 'braces'], 'fully_qualified_strict_types' => true, 'function_typehint_space' => true, 'general_phpdoc_tag_rename' => [ From a5544fe276f65c37bfbf11779256d86227f6d6f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sun, 18 Jul 2021 09:08:00 +0200 Subject: [PATCH 35/80] FunctionsAnalyzer - fix for recognizing global functions in attributes --- src/Tokenizer/Analyzer/FunctionsAnalyzer.php | 4 + .../NativeFunctionInvocationFixerTest.php | 38 +-- .../Analyzer/FunctionsAnalyzerTest.php | 232 +++++++++--------- 3 files changed, 139 insertions(+), 135 deletions(-) diff --git a/src/Tokenizer/Analyzer/FunctionsAnalyzer.php b/src/Tokenizer/Analyzer/FunctionsAnalyzer.php index d10b02d0076..601b8ea29e1 100644 --- a/src/Tokenizer/Analyzer/FunctionsAnalyzer.php +++ b/src/Tokenizer/Analyzer/FunctionsAnalyzer.php @@ -125,6 +125,10 @@ public function isGlobalFunctionCall(Tokens $tokens, int $index): bool return $functionUse->getShortName() === ltrim($functionUse->getFullName(), '\\'); } + if (AttributeAnalyzer::isAttribute($tokens, $index)) { + return false; + } + return true; } diff --git a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php index 1dd399cf9e9..568084286c7 100644 --- a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php +++ b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php @@ -622,25 +622,35 @@ public function testFixPrePHP80(): void } /** + * @dataProvider provideFix80Cases * @requires PHP 8.0 */ - public function testFixWithAttributesAndStrict(): void + public function testFix80(string $expected, ?string $input = null, array $config = []): void { - $this->testFixWithConfiguredInclude( - ' true] - ); + $this->fixer->configure($config); + $this->doTest($expected, $input); } - /** - * @requires PHP 8.0 - */ - public function testFixWithNullSafeObjectOperator(): void + public function provideFix80Cases() { - $this->doTest('count();'); + yield 'attribute and strict' => [ + ' true], + ]; + + yield 'null safe operator' => ['count();']; + + yield 'multiple function-calls-like in attribute' => [ + ' ['@all']], + ]; } } diff --git a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php index f5ec4ee1c18..9645d33b339 100644 --- a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php @@ -30,98 +30,78 @@ final class FunctionsAnalyzerTest extends TestCase { /** + * @param int[] $indices + * * @dataProvider provideIsGlobalFunctionCallCases */ - public function testIsGlobalFunctionCall(bool $isFunctionIndex, string $code, int $index): void + public function testIsGlobalFunctionCall(string $code, array $indices): void { - $tokens = Tokens::fromCode($code); - $analyzer = new FunctionsAnalyzer(); - - static::assertSame($isFunctionIndex, $analyzer->isGlobalFunctionCall($tokens, $index)); + self::assertIsGlobalFunctionCall($code, $indices); } public function provideIsGlobalFunctionCallCases() { - yield '1' => [ - false, + yield [ ' [ - true, + yield [ ' [ - false, - ' [ - true, + yield [ ' [ - false, + yield [ ' [ - false, + yield [ ' [ - false, + yield [ ' [ - false, + yield [ ' [ - false, + yield [ 'bar("baz");', - 3, + [], ]; - yield '10' => [ - false, + yield [ ' [ - false, + yield [ ' [ - false, + yield [ ' [ - false, + yield [ ' [ - true, + yield [ ' [ - true, + yield [ ' [ - true, + yield [ ' [ - true, + yield [ ' [ - false, + yield [ ' [ - false, + yield [ ' [ - true, + yield [ ' [ - true, + yield [ ' [ - true, + yield [ ' [ - false, + yield [ ' [ - true, + yield [ ' [ - true, + yield [ ' [ - true, + yield [ ' [ - true, + yield [ ' [ - true, + yield [ 'isGlobalFunctionCall($tokens, $index)); + self::assertIsGlobalFunctionCall($code, $indices); } public function provideIsGlobalFunctionCallPhp74Cases() { yield [ - false, ' false;', - 5, + [], ]; } /** + * @param int[] $indices + * * @dataProvider provideIsGlobalFunctionCallPhp80Cases * @requires PHP 8.0 */ - public function testIsGlobalFunctionCallPhp80(bool $isFunctionIndex, string $code, int $index): void + public function testIsGlobalFunctionCallPhp80(string $code, array $indices): void { - $tokens = Tokens::fromCode($code); - $analyzer = new FunctionsAnalyzer(); - - static::assertSame($isFunctionIndex, $analyzer->isGlobalFunctionCall($tokens, $index)); + self::assertIsGlobalFunctionCall($code, $indices); } public function provideIsGlobalFunctionCallPhp80Cases() { yield [ - true, 'count();', - 3, + [], + ]; + + yield [ + ' $token) { + if ($analyzer->isGlobalFunctionCall($tokens, $index)) { + $actualIndices[] = $index; + } + } + + static::assertSame( + $expectedIndices, + $actualIndices, + sprintf( + 'Global function calls found at positions: [%s], expected at [%s].', + implode(', ', $actualIndices), + implode(', ', $expectedIndices) + ) + ); + } } From 59c3e9459f4e8e3f50e9d9361a07586025e96ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Fri, 27 Aug 2021 19:00:34 +0200 Subject: [PATCH 36/80] Remove references to PHP 7.0 in tests --- tests/Fixer/Basic/PsrAutoloadingFixerTest.php | 12 +- .../Casing/MagicMethodCasingFixerTest.php | 158 ++++---- .../ModernizeTypesCastingFixerTest.php | 17 +- .../ClassAttributesSeparationFixerTest.php | 126 +++--- .../ClassDefinitionFixerTest.php | 23 +- .../NoPhp4ConstructorFixerTest.php | 7 +- .../SelfStaticAccessorFixerTest.php | 19 +- ...ingleClassElementPerStatementFixerTest.php | 3 - ...SingleTraitInsertPerStatementFixerTest.php | 3 - .../VisibilityRequiredFixerTest.php | 22 +- .../NoBreakCommentFixerTest.php | 25 +- .../SwitchCaseSemicolonToColonFixerTest.php | 14 +- .../ControlStructure/YodaStyleFixerTest.php | 108 ++--- .../NoSpacesAfterFunctionNameFixerTest.php | 39 +- .../RegularCallableCallFixerTest.php | 14 +- .../Fixer/Import/NoUnusedImportsFixerTest.php | 16 +- .../Fixer/Import/OrderedImportsFixerTest.php | 376 +++++++++--------- .../LanguageConstruct/IsNullFixerTest.php | 15 +- .../SingleSpaceAfterConstructFixerTest.php | 2 - .../BinaryOperatorSpacesFixerTest.php | 69 ++-- .../Fixer/Operator/NewWithBracesFixerTest.php | 14 +- .../StandardizeIncrementFixerTest.php | 14 +- .../TernaryToElvisOperatorFixerTest.php | 14 +- .../NoSuperfluousPhpdocTagsFixerTest.php | 26 +- .../Fixer/Phpdoc/PhpdocToCommentFixerTest.php | 21 +- .../Semicolon/NoEmptyStatementFixerTest.php | 7 +- .../Whitespace/NoExtraBlankLinesFixerTest.php | 68 +--- .../Tokenizer/Analyzer/ClassyAnalyzerTest.php | 16 +- .../Analyzer/FunctionsAnalyzerTest.php | 23 +- tests/Tokenizer/TokensAnalyzerTest.php | 24 +- .../Transformer/CurlyBraceTransformerTest.php | 32 -- 31 files changed, 458 insertions(+), 869 deletions(-) diff --git a/tests/Fixer/Basic/PsrAutoloadingFixerTest.php b/tests/Fixer/Basic/PsrAutoloadingFixerTest.php index d5ceff7aa4d..26c2c35a979 100644 --- a/tests/Fixer/Basic/PsrAutoloadingFixerTest.php +++ b/tests/Fixer/Basic/PsrAutoloadingFixerTest.php @@ -160,6 +160,7 @@ public static function provideFixNewCases() /** * @dataProvider provideFixCases * @dataProvider provideIgnoredCases + * @dataProvider provideAnonymousClassCases */ public function testFix(string $expected, ?string $input = null, ?\SplFileInfo $file = null, ?string $dir = null): void { @@ -399,16 +400,7 @@ class Bar {}', }, $cases); } - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input, $this->getTestFile(__FILE__)); - } - - public function provideFix70Cases() + public function provideAnonymousClassCases(): iterable { yield 'class with anonymous class' => [ 'doTest($expected, $input); - } - public function provideDoNotFixCases() - { - return [ - [ - '__sleep() - /** ->__sleep() */ - echo $a->__sleep; - ', - ], - [ - '__not_magic(); - ', - ], - [ - 'a(); - ', - ], - [ - 'b;', - ], - ]; - } - - /** - * @requires PHP 7.0 - */ - public function testFixPHP7(): void - { - $this->doTest( + yield 'PHP 7 syntax' => [ '__UnSet($foo); // fix - ' - ); + ', + ]; + } + + /** + * @dataProvider provideDoNotFixCases + */ + public function testDoNotFix(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideDoNotFixCases() + { + return [ + [ + '__sleep() + /** ->__sleep() */ + echo $a->__sleep; + ', + ], + [ + '__not_magic(); + ', + ], + [ + 'a(); + ', + ], + [ + 'b;', + ], + ]; } /** diff --git a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php index b79ba130f3a..226b027a293 100644 --- a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php +++ b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php @@ -99,7 +99,7 @@ public function usesInval() } OVERRIDDEN; - return [ + yield from [ ['doTest($expected, $input); - } - - public function provideFix70Cases() - { - yield from [ [ 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - $to = $from = 'doTestClassyInheritanceInfo($source, $label, $expected); } - /** - * @param string $source PHP source code - * - * @requires PHP 7.0 - * @dataProvider provideClassyInheritanceInfo7Cases - */ - public function testClassyInheritanceInfo7(string $source, string $label, array $expected): void - { - $this->doTestClassyInheritanceInfo($source, $label, $expected); - } - public function provideClassyImplementsInfoCases() { yield from [ @@ -586,11 +575,8 @@ public function test() 'numberOfImplements', ['start' => 36, 'numberOfImplements' => 2, 'multiLine' => $multiLine], ]; - } - public function provideClassyInheritanceInfo7Cases() - { - return [ + yield from [ [ "fixer->configure([]); $this->doTest($expected, $input); } - public function providePHP70Cases() + public function provideFixCases() { return [ [ diff --git a/tests/Fixer/ClassNotation/NoPhp4ConstructorFixerTest.php b/tests/Fixer/ClassNotation/NoPhp4ConstructorFixerTest.php index 001b9af718f..6d3bcc77e17 100644 --- a/tests/Fixer/ClassNotation/NoPhp4ConstructorFixerTest.php +++ b/tests/Fixer/ClassNotation/NoPhp4ConstructorFixerTest.php @@ -26,15 +26,14 @@ final class NoPhp4ConstructorFixerTest extends AbstractFixerTestCase { /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 + * @dataProvider provideFixCases */ - public function testFix70(string $expected, ?string $input = null): void + public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } - public function provideFix70Cases() + public function provideFixCases() { return [ [ diff --git a/tests/Fixer/ClassNotation/SelfStaticAccessorFixerTest.php b/tests/Fixer/ClassNotation/SelfStaticAccessorFixerTest.php index 7058ccb49db..57dfd03576b 100644 --- a/tests/Fixer/ClassNotation/SelfStaticAccessorFixerTest.php +++ b/tests/Fixer/ClassNotation/SelfStaticAccessorFixerTest.php @@ -178,22 +178,7 @@ public function isBar($foo) 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ - 'simple' => [ + 'simple anonymous class' => [ ' [ + 'nested anonymous class' => [ 'doTest( diff --git a/tests/Fixer/ClassNotation/SingleTraitInsertPerStatementFixerTest.php b/tests/Fixer/ClassNotation/SingleTraitInsertPerStatementFixerTest.php index 3f4805bd3e2..143a7929593 100644 --- a/tests/Fixer/ClassNotation/SingleTraitInsertPerStatementFixerTest.php +++ b/tests/Fixer/ClassNotation/SingleTraitInsertPerStatementFixerTest.php @@ -250,9 +250,6 @@ class Talker { ]; } - /** - * @requires PHP 7.0 - */ public function testAnonymousClassFixing(): void { $this->doTest( diff --git a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php index fe619e3ea52..300a5927a92 100644 --- a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php +++ b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php @@ -96,18 +96,7 @@ public function testFixMethods(string $expected, string $input = null): void $this->doTest($expected, $input); } - /** - * @param string $input - * - * @requires PHP 7.0 - * @dataProvider provideFixMethods70Cases - */ - public function testFixMethods70(string $expected, string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFixMethods70Cases(): array + public function provideFixMethodsCases(): iterable { return [ [ @@ -144,12 +133,6 @@ public function testSomethingWithMoney( EOF , ], - ]; - } - - public function provideFixMethodsCases(): array - { - return [ [ <<<'EOF' doTest($expected, $input); } - /** - * @requires PHP 7.0 - */ public function testAnonymousClassFixing(): void { $this->doTest( diff --git a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php index 1bceea3d05e..2450cd4953c 100644 --- a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php +++ b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php @@ -26,7 +26,7 @@ final class NoBreakCommentFixerTest extends AbstractFixerTestCase { /** - * @dataProvider provideTestFixCases + * @dataProvider provideFixCases */ public function testFix(string $expected, ?string $input = null): void { @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void } /** - * @dataProvider provideTestFixCases + * @dataProvider provideFixCases */ public function testFixWithExplicitDefaultConfiguration(string $expected, ?string $input = null): void { @@ -45,7 +45,7 @@ public function testFixWithExplicitDefaultConfiguration(string $expected, ?strin $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideFixCases() { return [ [ @@ -886,21 +886,6 @@ public function provideTestFixCases() break; }', ], - ]; - } - - /** - * @dataProvider provideTestFixPhp70Cases - * @requires PHP 7.0 - */ - public function testFixPhp70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideTestFixPhp70Cases() - { - return [ [ 'provideTestFixCases(); + $cases = $this->provideFixCases(); $replaceCommentText = static function (string $php) { return strtr($php, [ @@ -1072,7 +1057,7 @@ public function testFixWithDifferentLineEnding(string $expected, ?string $input public function provideTestFixWithDifferentLineEndingCases() { $cases = []; - foreach ($this->provideTestFixCases() as $case) { + foreach ($this->provideFixCases() as $case) { $case[0] = str_replace("\n", "\r\n", $case[0]); if (isset($case[1])) { $case[1] = str_replace("\n", "\r\n", $case[1]); diff --git a/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php b/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php index 43bd00bef6d..0d45f2cf299 100644 --- a/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php +++ b/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php @@ -226,20 +226,8 @@ public function provideFixCases() ', ]; } - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - public function provideFix70Cases() - { - return [ + yield from [ 'nested switch in switch case' => [ ' $d;'], + [ + 'fixer->getDefinition()); } - /** - * @dataProvider providePHP70Cases - * @requires PHP 7.0 - */ - public function testPHP70Cases(string $expected, ?string $input = null): void - { - $this->fixer->configure(['equal' => true, 'identical' => true]); - $this->doTest($expected, $input); - } - - /** - * Test with the inverse config. - * - * @dataProvider providePHP70Cases - * @requires PHP 7.0 - */ - public function testPHP70CasesInverse(string $expected, ?string $input = null): void - { - $this->fixer->configure(['equal' => false, 'identical' => false]); - - if (null === $input) { - $this->doTest($expected); - } else { - $this->doTest($input, $expected); - } - } - - public function providePHP70Cases() - { - return [ - [' $d;'], - [ - 'doTest($expected, $input); - } - public function provideFix54Cases() - { - return [ - [ - 'getOutput();', - 'getOutput ();', - ], + yield [ + 'getOutput();', + 'getOutput ();', ]; - } - - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function test70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - public function provideFix70Cases() - { - return [ - [ - 'doTest($expected, $input); - } - - public function provideFix70Cases() - { - yield 'call by variable' => [ + yield 'call by property' => [ 'c)(1, 2); ($f->{c})(1, 2); diff --git a/tests/Fixer/Import/NoUnusedImportsFixerTest.php b/tests/Fixer/Import/NoUnusedImportsFixerTest.php index 507d4deba32..739f62226e1 100644 --- a/tests/Fixer/Import/NoUnusedImportsFixerTest.php +++ b/tests/Fixer/Import/NoUnusedImportsFixerTest.php @@ -1273,15 +1273,8 @@ public function foo() {} Bar3: ', ], - ]; - } - - /** - * @requires PHP 7.0 - */ - public function testPHP70(): void - { - $expected = <<<'EOF' + [ + $expected = <<<'EOF' doTest($expected); +EOF + ], + ]; } /** diff --git a/tests/Fixer/Import/OrderedImportsFixerTest.php b/tests/Fixer/Import/OrderedImportsFixerTest.php index 242bc3635e3..1ecde513548 100644 --- a/tests/Fixer/Import/OrderedImportsFixerTest.php +++ b/tests/Fixer/Import/OrderedImportsFixerTest.php @@ -24,91 +24,6 @@ */ final class OrderedImportsFixerTest extends AbstractFixerTestCase { - public function testFix(): void - { - $expected = <<<'EOF' -The normal -use of this fixer -should not change this sentence nor those statements below -use Zoo\Bar as ZooBar; -use Foo\Bar; -use Foo\Zar\Baz; - -toArray(); - /** @var ArrayInterface $bar */ - - return function () use ($bar, $foo) {}; - } -} -EOF; - - $input = <<<'EOF' -The normal -use of this fixer -should not change this sentence nor those statements below -use Zoo\Bar as ZooBar; -use Foo\Bar; -use Foo\Zar\Baz; - -toArray(); - /** @var ArrayInterface $bar */ - - return function () use ($bar, $foo) {}; - } -} -EOF; - - $this->doTest($expected, $input); - } - public function testFixWithMultipleNamespace(): void { $expected = <<<'EOF' @@ -636,19 +551,101 @@ public function testCodeWithCommentsAndMultiLine(): void } /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 + * @dataProvider provideFixCases */ - public function testFix70(string $expected, ?string $input = null, array $config = []): void + public function testFix(string $expected, ?string $input = null, array $config = []): void { $this->fixer->configure($config); $this->doTest($expected, $input); } - public function provideFix70Cases() + public function provideFixCases(): iterable { return [ + [ + <<<'EOF' +The normal +use of this fixer +should not change this sentence nor those statements below +use Zoo\Bar as ZooBar; +use Foo\Bar; +use Foo\Zar\Baz; + +toArray(); + /** @var ArrayInterface $bar */ + + return function () use ($bar, $foo) {}; + } +} +EOF + , + + <<<'EOF' +The normal +use of this fixer +should not change this sentence nor those statements below +use Zoo\Bar as ZooBar; +use Foo\Bar; +use Foo\Zar\Baz; + +toArray(); + /** @var ArrayInterface $bar */ + + return function () use ($bar, $foo) {}; + } +} +EOF + , + ], [ 'fixer->configure([ - 'sort_algorithm' => OrderedImportsFixer::SORT_LENGTH, - 'imports_order' => null, - ]); - - $expected = <<<'EOF' -The normal -use of this fixer -should not change this sentence nor those statements below -use Zoo\Bar as ZooBar; -use Foo\Bar; -use Foo\Zar\Baz; - -toArray(); - /** @var ArrayInterface $bar */ - - return function () use ($bar, $foo) {}; - } -} -EOF; - - $input = <<<'EOF' -The normal -use of this fixer -should not change this sentence nor those statements below -use Zoo\Bar as ZooBar; -use Foo\Bar; -use Foo\Zar\Baz; - -toArray(); - /** @var ArrayInterface $bar */ - - return function () use ($bar, $foo) {}; - } -} -EOF; - - $this->doTest($expected, $input); - } - public function testByLengthFixWithSameLength(): void { $this->fixer->configure([ @@ -1720,10 +1627,9 @@ public function testByLengthWithoutUses(): void } /** - * @dataProvider provideFix70ByLengthCases - * @requires PHP 7.0 + * @dataProvider provideFixByLengthCases */ - public function testFix70ByLength(string $expected, ?string $input = null): void + public function testFixByLength(string $expected, ?string $input = null): void { $this->fixer->configure([ 'sort_algorithm' => OrderedImportsFixer::SORT_LENGTH, @@ -1733,9 +1639,92 @@ public function testFix70ByLength(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix70ByLengthCases() + public function provideFixByLengthCases() { return [ + [ + <<<'EOF' +The normal +use of this fixer +should not change this sentence nor those statements below +use Zoo\Bar as ZooBar; +use Foo\Bar; +use Foo\Zar\Baz; + +toArray(); + /** @var ArrayInterface $bar */ + + return function () use ($bar, $foo) {}; + } +} +EOF + , + + <<<'EOF' +The normal +use of this fixer +should not change this sentence nor those statements below +use Zoo\Bar as ZooBar; +use Foo\Bar; +use Foo\Zar\Baz; + +toArray(); + /** @var ArrayInterface $bar */ + + return function () use ($bar, $foo) {}; + } +} +EOF + , + ], [ 'fixer->configure([ 'sort_algorithm' => OrderedImportsFixer::SORT_LENGTH, @@ -1797,7 +1785,7 @@ public function testFix70TypesOrderAndLength(string $expected, ?string $input = $this->doTest($expected, $input); } - public function provideFix70TypesOrderAndLengthCases() + public function provideFixTypesOrderAndLengthCases() { return [ [ @@ -1840,12 +1828,11 @@ public function provideFix70TypesOrderAndLengthCases() } /** - * @dataProvider provideFix70TypesOrderAndAlphabetCases - * @requires PHP 7.0 + * @dataProvider provideFixTypesOrderAndAlphabetCases * * @param string[] $importOrder */ - public function testFix70TypesOrderAndAlphabet(string $expected, ?string $input = null, array $importOrder = null): void + public function testFixTypesOrderAndAlphabet(string $expected, ?string $input = null, array $importOrder = null): void { $this->fixer->configure([ 'sort_algorithm' => OrderedImportsFixer::SORT_ALPHA, @@ -1855,7 +1842,7 @@ public function testFix70TypesOrderAndAlphabet(string $expected, ?string $input $this->doTest($expected, $input); } - public function provideFix70TypesOrderAndAlphabetCases() + public function provideFixTypesOrderAndAlphabetCases(): iterable { return [ [ @@ -1909,12 +1896,11 @@ public function provideFix70TypesOrderAndAlphabetCases() } /** - * @dataProvider provideFix70TypesOrderAndNoneCases - * @requires PHP 7.0 + * @dataProvider provideFixTypesOrderAndNoneCases * * @param null|string[] $importOrder */ - public function testFix70TypesOrderAndNone(string $expected, ?string $input = null, array $importOrder = null): void + public function testFixTypesOrderAndNone(string $expected, ?string $input = null, array $importOrder = null): void { $this->fixer->configure([ 'sort_algorithm' => OrderedImportsFixer::SORT_NONE, @@ -1924,7 +1910,7 @@ public function testFix70TypesOrderAndNone(string $expected, ?string $input = nu $this->doTest($expected, $input); } - public function provideFix70TypesOrderAndNoneCases() + public function provideFixTypesOrderAndNoneCases() { return [ [ diff --git a/tests/Fixer/LanguageConstruct/IsNullFixerTest.php b/tests/Fixer/LanguageConstruct/IsNullFixerTest.php index 6da5334d667..2057d71ad47 100644 --- a/tests/Fixer/LanguageConstruct/IsNullFixerTest.php +++ b/tests/Fixer/LanguageConstruct/IsNullFixerTest.php @@ -203,20 +203,13 @@ public function provideFixCases() 'doTest( - 'doTest($expected, $input); } - public function provideTestCases() + public function provideConfiguredCases() { return [ [ @@ -443,6 +443,35 @@ public function provideTestCases() 'operators' => ['|' => BinaryOperatorSpacesFixer::NO_SPACE], ], ], + [ + ' 1; +echo 1 <=> 2; +echo 2 <=> 1; +echo 2 <=> 1; + +$a = $a ?? $b; +$a = $ab ?? $b; +$a = $ac ?? $b; +$a = $ad ?? $b; +$a = $ae ?? $b; +', + '1; +echo 1 <=>2; +echo 2<=> 1; +echo 2 <=> 1; + +$a = $a ?? $b; +$a = $ab ?? $b; +$a = $ac ?? $b; +$a = $ad ?? $b; +$a = $ae?? $b; +', + ['operators' => ['=' => BinaryOperatorSpacesFixer::ALIGN_SINGLE_SPACE, '??' => BinaryOperatorSpacesFixer::ALIGN_SINGLE_SPACE_MINIMAL]], + ], ]; } @@ -1912,42 +1941,6 @@ public function testDoNotTouchEqualsAndArrowByConfig(): void ); } - /** - * @requires PHP 7.0 - */ - public function testPHP70Cases(): void - { - $this->fixer->configure(['operators' => ['=' => BinaryOperatorSpacesFixer::ALIGN_SINGLE_SPACE, '??' => BinaryOperatorSpacesFixer::ALIGN_SINGLE_SPACE_MINIMAL]]); - $this->doTest( - ' 1; -echo 1 <=> 2; -echo 2 <=> 1; -echo 2 <=> 1; - -$a = $a ?? $b; -$a = $ab ?? $b; -$a = $ac ?? $b; -$a = $ad ?? $b; -$a = $ae ?? $b; -', - '1; -echo 1 <=>2; -echo 2<=> 1; -echo 2 <=> 1; - -$a = $a ?? $b; -$a = $ab ?? $b; -$a = $ac ?? $b; -$a = $ad ?? $b; -$a = $ae?? $b; -' - ); - } - /** * @requires PHP 7.1 * diff --git a/tests/Fixer/Operator/NewWithBracesFixerTest.php b/tests/Fixer/Operator/NewWithBracesFixerTest.php index a20daf91ca4..986b053629a 100644 --- a/tests/Fixer/Operator/NewWithBracesFixerTest.php +++ b/tests/Fixer/Operator/NewWithBracesFixerTest.php @@ -33,15 +33,6 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - public function provideFixCases() { yield from [ @@ -271,11 +262,8 @@ public function provideFixCases() ' 1; diff --git a/tests/Fixer/Operator/StandardizeIncrementFixerTest.php b/tests/Fixer/Operator/StandardizeIncrementFixerTest.php index c26b21ad4d0..ec16720892a 100644 --- a/tests/Fixer/Operator/StandardizeIncrementFixerTest.php +++ b/tests/Fixer/Operator/StandardizeIncrementFixerTest.php @@ -575,20 +575,8 @@ public static function bar() { 'doTest($expected, $input); - } - public function provideFix70Cases() - { - return [ + yield from [ [ '$a[0] ? __FILE__.$a.$b{2}.$c->$a[0] : 1;', ]; } - } - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function test70Fix(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFix70Cases() - { - return [ + yield from [ [ 'fixer->configure($config); - $this->doTest($expected, $input); - } - - public function provideFixPhp70Cases() - { - return [ 'same type hint' => [ ' [ + 'multiple different types (with return type)' => [ ' [ + 'with import (with return type)' => [ ' [ + 'with root symbols (with return type)' => [ ' [ + 'with mix of imported and fully qualified symbols (with return type)' => [ ' [ + 'with aliased imported (with return type)' => [ 'doTest($expected, $input); } - /** - * @dataProvider provideTraitsCases - */ - public function testFixTraits(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - public function provideDocblocksCases() { $cases = []; @@ -700,16 +694,7 @@ public function test() {} ]; } - /** - * @dataProvider provideFix70Cases - * @requires PHP 7.0 - */ - public function testFix70(string $expected, ?string $input = null): void - { - $this->doTest($expected, $input); - } - - public function provideFix70Cases() + public function provideFixCases() { return [ [ diff --git a/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php b/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php index 1385c5fe363..b9e9a571269 100644 --- a/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php +++ b/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php @@ -427,15 +427,14 @@ trait TestTrait } /** - * @dataProvider providePHP7Cases - * @requires PHP 7.0 + * @dataProvider provideFixCases */ - public function testFixPHP7(string $expected, ?string $input = null): void + public function testFix(string $expected, ?string $input = null): void { $this->doTest($expected, $input); } - public function providePHP7Cases() + public function provideFixCases() { return [ [ diff --git a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php index 33080e20462..4d81717b4f9 100644 --- a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php +++ b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php @@ -518,9 +518,20 @@ class Test { ]; } - public function testRemoveLinesBetweenUseStatements(): void + /** + * @dataProvider provideRemoveLinesBetweenUseStatementsCases + */ + public function testRemoveLinesBetweenUseStatements(string $expected, ?string $input = null): void { - $expected = <<<'EOF' + $this->fixer->configure(['tokens' => ['use']]); + $this->doTest($expected, $input); + } + + public function provideRemoveLinesBetweenUseStatementsCases() + { + return [ + [ + <<<'EOF' fixer->configure(['tokens' => ['use']]); - $this->doTest($expected, $input); - } - - /** - * @dataProvider provideRemoveLinesBetweenUseStatements70Cases - * @requires PHP 7.0 - */ - public function testRemoveLinesBetweenUseStatements70(string $expected, ?string $input = null): void - { - $this->fixer->configure(['tokens' => ['use']]); - $this->doTest($expected, $input); - } - - public function provideRemoveLinesBetweenUseStatements70Cases() - { - return [ + , + ], [ 'fixer->configure(['tokens' => [ - 'break', - 'continue', - 'return', - 'throw', - 'curly_brace_block', - 'square_brace_block', - 'parenthesis_brace_block', - ]]); - $this->doTest($expected, $input); - } - - public function provideOneAndInLine70Cases() - { - return [ - [ - " true], @@ -103,21 +103,7 @@ public function provideIsClassyInvocationCases() [1 => false, 7 => false], ], ]; - } - /** - * @param array $expected - * - * @dataProvider provideIsClassyInvocation70Cases - * @requires PHP 7.0 - */ - public function testIsClassyInvocation70(string $source, array $expected): void - { - self::assertClassyInvocation($source, $expected); - } - - public function provideIsClassyInvocation70Cases() - { yield [ ' false, 5 => false, 10 => false, 17 => false], diff --git a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php index f5ec4ee1c18..8cdae606ec7 100644 --- a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php @@ -377,22 +377,9 @@ public function testFunctionArgumentInfo(string $code, int $methodIndex, array $ /** * @param ?array $expected * - * @dataProvider provideFunctionsWithReturnTypeCases + * @dataProvider provideFunctionReturnTypeInfoCases */ - public function testFunctionReturnTypeInfo(string $code, int $methodIndex, ?array $expected): void - { - $tokens = Tokens::fromCode($code); - $analyzer = new FunctionsAnalyzer(); - - $actual = $analyzer->getFunctionReturnType($tokens, $methodIndex); - static::assertSame(serialize($expected), serialize($actual)); - } - - /** - * @dataProvider provideFunctionsWithReturnTypePhp70Cases - * @requires PHP 7.0 - */ - public function testFunctionReturnTypeInfoPhp70(string $code, int $methodIndex, TypeAnalysis $expected): void + public function testFunctionReturnTypeInfo(string $code, int $methodIndex, $expected): void { $tokens = Tokens::fromCode($code); $analyzer = new FunctionsAnalyzer(); @@ -501,13 +488,9 @@ public function provideFunctionsWithArgumentsCases() } } - public function provideFunctionsWithReturnTypeCases() + public function provideFunctionReturnTypeInfoCases() { yield [' $isBinary) { - static::assertSame($isBinary, $tokensAnalyzer->isBinaryOperator($index)); - if ($isBinary) { - static::assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index)); - static::assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index)); - } - } - } + yield from $cases; - public function provideIsBinaryOperator70Cases() - { - return [ + yield from [ [ ' $b;', [3 => true], diff --git a/tests/Tokenizer/Transformer/CurlyBraceTransformerTest.php b/tests/Tokenizer/Transformer/CurlyBraceTransformerTest.php index c729cc1d661..a856b756a19 100644 --- a/tests/Tokenizer/Transformer/CurlyBraceTransformerTest.php +++ b/tests/Tokenizer/Transformer/CurlyBraceTransformerTest.php @@ -51,32 +51,6 @@ public function testProcess(string $source, array $expectedTokens = []): void ); } - /** - * @dataProvider provideProcess70Cases - * @requires PHP 7.0 - */ - public function testProcess70(string $source, array $expectedTokens = []): void - { - $this->doTest( - $source, - $expectedTokens, - [ - T_CURLY_OPEN, - CT::T_CURLY_CLOSE, - T_DOLLAR_OPEN_CURLY_BRACES, - CT::T_DOLLAR_CLOSE_CURLY_BRACES, - CT::T_DYNAMIC_PROP_BRACE_OPEN, - CT::T_DYNAMIC_PROP_BRACE_CLOSE, - CT::T_DYNAMIC_VAR_BRACE_OPEN, - CT::T_DYNAMIC_VAR_BRACE_CLOSE, - CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN, - CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE, - CT::T_GROUP_IMPORT_BRACE_OPEN, - CT::T_GROUP_IMPORT_BRACE_CLOSE, - ] - ); - } - public function provideProcessCases() { return [ @@ -206,12 +180,6 @@ public function provideProcessCases() 10 => CT::T_DYNAMIC_PROP_BRACE_CLOSE, ], ], - ]; - } - - public function provideProcess70Cases() - { - return [ [ ' Date: Mon, 1 Mar 2021 11:59:15 +0100 Subject: [PATCH 37/80] PhpdocTo*TypeFixer - add more test cases --- tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php | 3 +++ tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php | 3 +++ 2 files changed, 6 insertions(+) diff --git a/tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php b/tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php index dad5ae4475e..70eff406ea3 100644 --- a/tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php +++ b/tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php @@ -248,6 +248,9 @@ class Foo { 'skip mixed types including array' => [ ' [ + ' [ ' [ + ' [ ' Date: Tue, 31 Aug 2021 10:57:30 +0200 Subject: [PATCH 38/80] Remove not needed PHP version checks --- src/AbstractPhpdocToTypeDeclarationFixer.php | 2 +- src/Fixer/Alias/ArrayPushFixer.php | 2 +- .../Basic/NonPrintableCharacterFixer.php | 9 ---- ...tiveFunctionTypeDeclarationCasingFixer.php | 41 ++++++++----------- .../ClassNotation/VisibilityRequiredFixer.php | 4 -- .../CombineNestedDirnameFixer.php | 2 +- ...ypeDeclarationForDefaultNullValueFixer.php | 4 -- .../PhpdocToParamTypeFixer.php | 4 +- .../PhpdocToReturnTypeFixer.php | 2 +- .../RegularCallableCallFixer.php | 22 ++++------ .../ReturnTypeDeclarationFixer.php | 2 +- .../FunctionNotation/VoidReturnFixer.php | 2 +- .../Import/FullyQualifiedStrictTypesFixer.php | 4 -- src/Fixer/Import/GroupImportFixer.php | 2 +- .../ExplicitIndirectVariableFixer.php | 2 +- .../SingleSpaceAfterConstructFixer.php | 3 +- src/Fixer/ListNotation/ListSyntaxFixer.php | 2 +- src/Fixer/Operator/OperatorLinebreakFixer.php | 5 +-- .../Operator/TernaryToNullCoalescingFixer.php | 2 +- src/Fixer/Strict/DeclareStrictTypesFixer.php | 2 +- .../CompactNullableTypehintFixer.php | 2 +- .../Transformer/CurlyBraceTransformer.php | 5 +-- .../Transformer/SquareBraceTransformer.php | 2 +- 23 files changed, 42 insertions(+), 85 deletions(-) diff --git a/src/AbstractPhpdocToTypeDeclarationFixer.php b/src/AbstractPhpdocToTypeDeclarationFixer.php index 465d52684d2..57bb41806d4 100644 --- a/src/AbstractPhpdocToTypeDeclarationFixer.php +++ b/src/AbstractPhpdocToTypeDeclarationFixer.php @@ -182,7 +182,7 @@ protected function getCommonTypeFromAnnotation(Annotation $annotation, bool $isR return null; } - if ($isNullable && (\PHP_VERSION_ID < 70100 || 'void' === $commonType)) { + if ($isNullable && 'void' === $commonType) { return null; } diff --git a/src/Fixer/Alias/ArrayPushFixer.php b/src/Fixer/Alias/ArrayPushFixer.php index f333585a67e..14becbd76b0 100644 --- a/src/Fixer/Alias/ArrayPushFixer.php +++ b/src/Fixer/Alias/ArrayPushFixer.php @@ -46,7 +46,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(T_STRING) && $tokens->count() > 7; + return $tokens->isTokenKindFound(T_STRING) && $tokens->count() > 7; } /** diff --git a/src/Fixer/Basic/NonPrintableCharacterFixer.php b/src/Fixer/Basic/NonPrintableCharacterFixer.php index 2c791c63ecb..b36ed4fe486 100644 --- a/src/Fixer/Basic/NonPrintableCharacterFixer.php +++ b/src/Fixer/Basic/NonPrintableCharacterFixer.php @@ -19,14 +19,12 @@ use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; -use PhpCsFixer\FixerConfiguration\InvalidOptionsForEnvException; use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Preg; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -use Symfony\Component\OptionsResolver\Options; /** * Removes Zero-width space (ZWSP), Non-breaking space (NBSP) and other invisible unicode symbols. @@ -106,13 +104,6 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn (new FixerOptionBuilder('use_escape_sequences_in_strings', 'Whether characters should be replaced with escape sequences in strings.')) ->setAllowedTypes(['bool']) ->setDefault(true) - ->setNormalizer(static function (Options $options, $value) { - if (\PHP_VERSION_ID < 70000 && $value) { - throw new InvalidOptionsForEnvException('Escape sequences require PHP 7.0+.'); - } - - return $value; - }) ->getOption(), ]); } diff --git a/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php b/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php index 72a94797691..e3810dfff30 100644 --- a/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php +++ b/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php @@ -65,27 +65,23 @@ public function __construct() 'self' => true, ]; - if (\PHP_VERSION_ID >= 70000) { - $this->hints = array_merge( - $this->hints, - [ - 'bool' => true, - 'float' => true, - 'int' => true, - 'string' => true, - ] - ); - } + $this->hints = array_merge( + $this->hints, + [ + 'bool' => true, + 'float' => true, + 'int' => true, + 'string' => true, + ] + ); - if (\PHP_VERSION_ID >= 70100) { - $this->hints = array_merge( - $this->hints, - [ - 'iterable' => true, - 'void' => true, - ] - ); - } + $this->hints = array_merge( + $this->hints, + [ + 'iterable' => true, + 'void' => true, + ] + ); if (\PHP_VERSION_ID >= 70200) { $this->hints = array_merge($this->hints, ['object' => true]); @@ -137,10 +133,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { for ($index = $tokens->count() - 1; $index >= 0; --$index) { if ($tokens[$index]->isGivenKind(T_FUNCTION)) { - if (\PHP_VERSION_ID >= 70000) { - $this->fixFunctionReturnType($tokens, $index); - } - + $this->fixFunctionReturnType($tokens, $index); $this->fixFunctionArgumentTypes($tokens, $index); } } diff --git a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php index c61a33c4162..0cf7c880998 100644 --- a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php +++ b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php @@ -105,10 +105,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - if (\PHP_VERSION_ID < 70100 && 'const' === $element['type']) { - continue; - } - $abstractFinalIndex = null; $visibilityIndex = null; $staticIndex = null; diff --git a/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php b/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php index 9d58286862a..e75be43eb45 100644 --- a/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php +++ b/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php @@ -49,7 +49,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(T_STRING); + return $tokens->isTokenKindFound(T_STRING); } /** diff --git a/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php b/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php index 613ef30cd7f..117eab20ddb 100644 --- a/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php +++ b/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php @@ -58,10 +58,6 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - if (\PHP_VERSION_ID < 70100) { - return false; - } - if (!$tokens->isTokenKindFound(T_VARIABLE)) { return false; } diff --git a/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php index 9121b0d039a..52a082dbacd 100644 --- a/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToParamTypeFixer.php @@ -27,8 +27,6 @@ */ final class PhpdocToParamTypeFixer extends AbstractPhpdocToTypeDeclarationFixer { - private const MINIMUM_PHP_VERSION = 70000; - /** * @var array{int, string}[] */ @@ -87,7 +85,7 @@ function bar($foo) {} */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= self::MINIMUM_PHP_VERSION && $tokens->isTokenKindFound(T_FUNCTION); + return $tokens->isTokenKindFound(T_FUNCTION); } /** diff --git a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php index f1b3cfc03ca..e31f247e5a9 100644 --- a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php @@ -114,7 +114,7 @@ public function isCandidate(Tokens $tokens): bool return true; } - return \PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(T_FUNCTION); + return $tokens->isTokenKindFound(T_FUNCTION); } /** diff --git a/src/Fixer/FunctionNotation/RegularCallableCallFixer.php b/src/Fixer/FunctionNotation/RegularCallableCallFixer.php index d98acf1b72c..cea13b2a01d 100644 --- a/src/Fixer/FunctionNotation/RegularCallableCallFixer.php +++ b/src/Fixer/FunctionNotation/RegularCallableCallFixer.php @@ -123,17 +123,15 @@ private function processCall(Tokens $tokens, int $index, array $arguments): void $this->replaceCallUserFuncWithCallback($tokens, $index, $newCallTokens, $firstArgIndex, $firstArgIndex); } elseif ($firstArgToken->isGivenKind([T_FUNCTION, T_STATIC])) { - if (\PHP_VERSION_ID >= 70000) { - $firstArgEndIndex = $tokens->findBlockEnd( - Tokens::BLOCK_TYPE_CURLY_BRACE, - $tokens->getNextTokenOfKind($firstArgIndex, ['{']) - ); + $firstArgEndIndex = $tokens->findBlockEnd( + Tokens::BLOCK_TYPE_CURLY_BRACE, + $tokens->getNextTokenOfKind($firstArgIndex, ['{']) + ); - $newCallTokens = $this->getTokensSubcollection($tokens, $firstArgIndex, $firstArgEndIndex); - $newCallTokens->insertAt($newCallTokens->count(), new Token(')')); - $newCallTokens->insertAt(0, new Token('(')); - $this->replaceCallUserFuncWithCallback($tokens, $index, $newCallTokens, $firstArgIndex, $firstArgEndIndex); - } + $newCallTokens = $this->getTokensSubcollection($tokens, $firstArgIndex, $firstArgEndIndex); + $newCallTokens->insertAt($newCallTokens->count(), new Token(')')); + $newCallTokens->insertAt(0, new Token('(')); + $this->replaceCallUserFuncWithCallback($tokens, $index, $newCallTokens, $firstArgIndex, $firstArgEndIndex); } elseif ($firstArgToken->isGivenKind(T_VARIABLE)) { $firstArgEndIndex = reset($arguments); @@ -175,10 +173,6 @@ private function processCall(Tokens $tokens, int $index, array $arguments): void } if ($complex) { - if (\PHP_VERSION_ID < 70000) { - return; - } - $newCallTokens->insertAt($newCallTokens->count(), new Token(')')); $newCallTokens->insertAt(0, new Token('(')); } diff --git a/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php b/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php index 2d7f863fab2..fe3015929f0 100644 --- a/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php +++ b/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php @@ -70,7 +70,7 @@ public function getPriority(): int */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(CT::T_TYPE_COLON); + return $tokens->isTokenKindFound(CT::T_TYPE_COLON); } /** diff --git a/src/Fixer/FunctionNotation/VoidReturnFixer.php b/src/Fixer/FunctionNotation/VoidReturnFixer.php index c7d9243d37a..47fb0118268 100644 --- a/src/Fixer/FunctionNotation/VoidReturnFixer.php +++ b/src/Fixer/FunctionNotation/VoidReturnFixer.php @@ -63,7 +63,7 @@ public function getPriority(): int */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70100 && $tokens->isTokenKindFound(T_FUNCTION); + return $tokens->isTokenKindFound(T_FUNCTION); } /** diff --git a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php index d0dbeb0d2b9..91de9bd983c 100644 --- a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php +++ b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php @@ -126,10 +126,6 @@ private function fixFunctionArguments(Tokens $tokens, int $index): void private function fixFunctionReturnType(Tokens $tokens, int $index): void { - if (\PHP_VERSION_ID < 70000) { - return; - } - $returnType = (new FunctionsAnalyzer())->getFunctionReturnType($tokens, $index); if (!$returnType) { return; diff --git a/src/Fixer/Import/GroupImportFixer.php b/src/Fixer/Import/GroupImportFixer.php index b1c4532c43a..ad18bd055e2 100644 --- a/src/Fixer/Import/GroupImportFixer.php +++ b/src/Fixer/Import/GroupImportFixer.php @@ -49,7 +49,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(T_USE); + return $tokens->isTokenKindFound(T_USE); } /** diff --git a/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php b/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php index dfca5ac4adc..25925fe1f1c 100644 --- a/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php +++ b/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php @@ -54,7 +54,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(T_VARIABLE); + return $tokens->isTokenKindFound(T_VARIABLE); } /** diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index f95cb84cb92..c71f9374c56 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -250,8 +250,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } if ( - 70000 <= \PHP_VERSION_ID - && $token->isGivenKind(T_YIELD_FROM) + $token->isGivenKind(T_YIELD_FROM) && 'yield from' !== strtolower($token->getContent()) ) { $tokens[$index] = new Token([T_YIELD_FROM, Preg::replace( diff --git a/src/Fixer/ListNotation/ListSyntaxFixer.php b/src/Fixer/ListNotation/ListSyntaxFixer.php index 02c3c34d7e1..e6df93ba488 100644 --- a/src/Fixer/ListNotation/ListSyntaxFixer.php +++ b/src/Fixer/ListNotation/ListSyntaxFixer.php @@ -85,7 +85,7 @@ public function getPriority(): int */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70100 && $tokens->isTokenKindFound($this->candidateTokenKind); + return $tokens->isTokenKindFound($this->candidateTokenKind); } /** diff --git a/src/Fixer/Operator/OperatorLinebreakFixer.php b/src/Fixer/Operator/OperatorLinebreakFixer.php index 38cc50f1723..55c6b9ad738 100644 --- a/src/Fixer/Operator/OperatorLinebreakFixer.php +++ b/src/Fixer/Operator/OperatorLinebreakFixer.php @@ -84,10 +84,6 @@ public function configure(array $configuration): void $this->operators = self::BOOLEAN_OPERATORS; if (!$this->configuration['only_booleans']) { $this->operators = array_merge($this->operators, self::getNonBooleanOperators()); - if (\PHP_VERSION_ID >= 70000) { - $this->operators[] = [T_COALESCE]; - $this->operators[] = [T_SPACESHIP]; - } } $this->position = $this->configuration['position']; } @@ -314,6 +310,7 @@ private static function getNonBooleanOperators(): array [T_IS_IDENTICAL], [T_IS_NOT_EQUAL], [T_IS_NOT_IDENTICAL], [T_IS_SMALLER_OR_EQUAL], [T_MINUS_EQUAL], [T_MOD_EQUAL], [T_MUL_EQUAL], [T_OR_EQUAL], [T_PAAMAYIM_NEKUDOTAYIM], [T_PLUS_EQUAL], [T_POW], [T_POW_EQUAL], [T_SL], [T_SL_EQUAL], [T_SR], [T_SR_EQUAL], [T_XOR_EQUAL], + [T_COALESCE], [T_SPACESHIP], ], array_map(function ($id) { return [$id]; }, Token::getObjectOperatorKinds()) ); diff --git a/src/Fixer/Operator/TernaryToNullCoalescingFixer.php b/src/Fixer/Operator/TernaryToNullCoalescingFixer.php index ac1a649fe99..45349e5d1ea 100644 --- a/src/Fixer/Operator/TernaryToNullCoalescingFixer.php +++ b/src/Fixer/Operator/TernaryToNullCoalescingFixer.php @@ -46,7 +46,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(T_ISSET); + return $tokens->isTokenKindFound(T_ISSET); } /** diff --git a/src/Fixer/Strict/DeclareStrictTypesFixer.php b/src/Fixer/Strict/DeclareStrictTypesFixer.php index 652752ec47b..12a83d0fe53 100644 --- a/src/Fixer/Strict/DeclareStrictTypesFixer.php +++ b/src/Fixer/Strict/DeclareStrictTypesFixer.php @@ -60,7 +60,7 @@ public function getPriority(): int */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70000 && isset($tokens[0]) && $tokens[0]->isGivenKind(T_OPEN_TAG); + return isset($tokens[0]) && $tokens[0]->isGivenKind(T_OPEN_TAG); } /** diff --git a/src/Fixer/Whitespace/CompactNullableTypehintFixer.php b/src/Fixer/Whitespace/CompactNullableTypehintFixer.php index ce745f28e91..042d82847c4 100644 --- a/src/Fixer/Whitespace/CompactNullableTypehintFixer.php +++ b/src/Fixer/Whitespace/CompactNullableTypehintFixer.php @@ -47,7 +47,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return \PHP_VERSION_ID >= 70100 && $tokens->isTokenKindFound(CT::T_NULLABLE_TYPE); + return $tokens->isTokenKindFound(CT::T_NULLABLE_TYPE); } /** diff --git a/src/Tokenizer/Transformer/CurlyBraceTransformer.php b/src/Tokenizer/Transformer/CurlyBraceTransformer.php index abc4429893d..1d53a533e24 100644 --- a/src/Tokenizer/Transformer/CurlyBraceTransformer.php +++ b/src/Tokenizer/Transformer/CurlyBraceTransformer.php @@ -54,10 +54,7 @@ public function process(Tokens $tokens, Token $token, int $index): void $this->transformIntoDynamicPropBraces($tokens, $token, $index); $this->transformIntoDynamicVarBraces($tokens, $token, $index); $this->transformIntoCurlyIndexBraces($tokens, $token, $index); - - if (\PHP_VERSION_ID >= 70000) { - $this->transformIntoGroupUseBraces($tokens, $token, $index); - } + $this->transformIntoGroupUseBraces($tokens, $token, $index); } /** diff --git a/src/Tokenizer/Transformer/SquareBraceTransformer.php b/src/Tokenizer/Transformer/SquareBraceTransformer.php index 26982aee1ef..59467a14d65 100644 --- a/src/Tokenizer/Transformer/SquareBraceTransformer.php +++ b/src/Tokenizer/Transformer/SquareBraceTransformer.php @@ -150,7 +150,7 @@ private function isShortArray(Tokens $tokens, int $index): bool private function isArrayDestructing(Tokens $tokens, int $index): bool { - if (\PHP_VERSION_ID < 70100 || !$tokens[$index]->equals('[')) { + if (!$tokens[$index]->equals('[')) { return false; } From 0b1320af10343677a10fcc693bb30879ef31a556 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Tue, 31 Aug 2021 14:19:22 +0200 Subject: [PATCH 39/80] simplify code, more tests --- src/AbstractFunctionReferenceFixer.php | 2 +- .../InvalidConfigurationException.php | 2 +- src/Console/Command/DescribeCommand.php | 2 +- src/Console/ConfigurationResolver.php | 4 +- src/DocBlock/TypeExpression.php | 6 +- src/Documentation/DocumentationGenerator.php | 6 +- src/Fixer/ControlStructure/YodaStyleFixer.php | 2 +- .../Phpdoc/NoSuperfluousPhpdocTagsFixer.php | 6 +- src/FixerFactory.php | 6 +- tests/AbstractFunctionReferenceFixerTest.php | 2 +- tests/AutoReview/CiConfigurationTest.php | 10 +- tests/AutoReview/CommandTest.php | 2 +- tests/AutoReview/DescribeCommandTest.php | 8 +- tests/AutoReview/DocumentationTest.php | 10 +- tests/AutoReview/FixerFactoryTest.php | 5 +- tests/AutoReview/ProjectCodeTest.php | 14 +-- .../ProjectFixerConfigurationTest.php | 1 - tests/AutoReview/TransformerTest.php | 2 +- tests/Cache/CacheTest.php | 2 +- tests/Cache/SignatureTest.php | 2 +- .../FixCommandExitStatusCalculatorTest.php | 2 +- tests/Console/Command/FixCommandTest.php | 2 +- tests/Console/Command/HelpCommandTest.php | 4 +- .../Console/Command/SelfUpdateCommandTest.php | 20 ++-- tests/Console/ConfigurationResolverTest.php | 28 ++--- tests/Console/Output/ErrorOutputTest.php | 4 +- tests/Console/Output/ProcessOutputTest.php | 2 +- .../SelfUpdate/NewVersionCheckerTest.php | 4 +- tests/Differ/AbstractDifferTestCase.php | 4 +- tests/Differ/DiffConsoleFormatterTest.php | 2 +- tests/DocBlock/AnnotationTest.php | 52 +++----- tests/DocBlock/DocBlockTest.php | 4 +- tests/DocBlock/LineTest.php | 24 +--- tests/DocBlock/ShortDescriptionTest.php | 2 +- tests/DocBlock/TagComparatorTest.php | 2 +- tests/DocBlock/TagTest.php | 4 +- tests/DocBlock/TypeExpressionTest.php | 6 +- tests/FileReaderTest.php | 1 - tests/Fixer/Alias/ArrayPushFixerTest.php | 2 +- .../Alias/BacktickToShellExecFixerTest.php | 2 +- tests/Fixer/Alias/EregToPregFixerTest.php | 2 +- tests/Fixer/Alias/MbStrFunctionsFixerTest.php | 2 +- .../Fixer/Alias/NoAliasFunctionsFixerTest.php | 4 +- .../NoAliasLanguageConstructCallFixerTest.php | 2 +- .../Fixer/Alias/NoMixedEchoPrintFixerTest.php | 16 +-- .../Alias/PowToExponentiationFixerTest.php | 10 +- .../Alias/RandomApiMigrationFixerTest.php | 2 +- tests/Fixer/Alias/SetTypeToCastFixerTest.php | 4 +- .../ArrayNotation/ArraySyntaxFixerTest.php | 4 +- ...neWhitespaceAroundDoubleArrowFixerTest.php | 4 +- ...railingCommaInSinglelineArrayFixerTest.php | 4 +- ...oWhitespaceBeforeCommaInArrayFixerTest.php | 6 +- .../NormalizeIndexBraceFixerTest.php | 2 +- .../TrimArraySpacesFixerTest.php | 2 +- .../WhitespaceAfterCommaInArrayFixerTest.php | 4 +- tests/Fixer/Basic/EncodingFixerTest.php | 4 +- .../Basic/NonPrintableCharacterFixerTest.php | 4 +- tests/Fixer/Basic/PsrAutoloadingFixerTest.php | 6 +- tests/Fixer/Casing/ConstantCaseFixerTest.php | 40 +++---- .../Casing/LowercaseKeywordsFixerTest.php | 6 +- .../LowercaseStaticReferenceFixerTest.php | 4 +- .../Casing/MagicConstantCasingFixerTest.php | 4 +- .../Casing/MagicMethodCasingFixerTest.php | 4 +- .../Casing/NativeFunctionCasingFixerTest.php | 4 +- ...FunctionTypeDeclarationCasingFixerTest.php | 8 +- .../CastNotation/CastSpacesFixerTest.php | 4 +- .../CastNotation/LowercaseCastFixerTest.php | 6 +- .../ModernizeTypesCastingFixerTest.php | 4 +- .../CastNotation/NoShortBoolCastFixerTest.php | 2 +- .../CastNotation/NoUnsetCastFixerTest.php | 2 +- .../CastNotation/ShortScalarCastFixerTest.php | 8 +- .../ClassAttributesSeparationFixerTest.php | 18 +-- .../ClassDefinitionFixerTest.php | 26 ++-- .../ClassNotation/FinalClassFixerTest.php | 2 +- .../FinalInternalClassFixerTest.php | 7 +- ...lPublicMethodForAbstractClassFixerTest.php | 4 +- ...NoBlankLinesAfterClassOpeningFixerTest.php | 7 +- .../NoNullPropertyInitializationFixerTest.php | 8 +- .../NoPhp4ConstructorFixerTest.php | 6 +- .../NoUnneededFinalMethodFixerTest.php | 4 +- .../OrderedClassElementsFixerTest.php | 14 +-- .../OrderedInterfacesFixerTest.php | 8 +- .../ProtectedToPrivateFixerTest.php | 4 +- .../ClassNotation/SelfAccessorFixerTest.php | 6 +- .../SelfStaticAccessorFixerTest.php | 2 +- ...ingleClassElementPerStatementFixerTest.php | 10 +- ...SingleTraitInsertPerStatementFixerTest.php | 2 +- .../VisibilityRequiredFixerTest.php | 6 +- .../ClassUsage/DateTimeImmutableFixerTest.php | 2 +- .../Comment/CommentToPhpdocFixerTest.php | 2 +- .../Fixer/Comment/HeaderCommentFixerTest.php | 10 +- ...ultilineCommentOpeningClosingFixerTest.php | 2 +- .../Fixer/Comment/NoEmptyCommentFixerTest.php | 4 +- ...NoTrailingWhitespaceInCommentFixerTest.php | 2 +- .../SingleLineCommentStyleFixerTest.php | 6 +- .../ControlStructure/ElseifFixerTest.php | 2 +- .../EmptyLoopBodyFixerTest.php | 2 +- .../ControlStructure/IncludeFixerTest.php | 2 +- .../NoAlternativeSyntaxFixerTest.php | 2 +- .../NoBreakCommentFixerTest.php | 16 ++- .../NoSuperfluousElseifFixerTest.php | 4 +- .../NoTrailingCommaInListCallFixerTest.php | 2 +- .../NoUnneededControlParenthesesFixerTest.php | 4 +- .../NoUnneededCurlyBracesFixerTest.php | 6 +- .../NoUselessElseFixerTest.php | 18 +-- .../SimplifiedIfReturnFixerTest.php | 2 +- .../SwitchCaseSemicolonToColonFixerTest.php | 4 +- .../SwitchCaseSpaceFixerTest.php | 2 +- .../SwitchContinueToBreakFixerTest.php | 4 +- .../TrailingCommaInMultilineFixerTest.php | 8 +- .../ControlStructure/YodaStyleFixerTest.php | 16 +-- .../DoctrineAnnotationSpacesFixerTest.php | 26 ++-- .../CombineNestedDirnameFixerTest.php | 4 +- .../FopenFlagOrderFixerTest.php | 2 +- .../FunctionNotation/FopenFlagsFixerTest.php | 4 +- .../FunctionDeclarationFixerTest.php | 6 +- .../FunctionTypehintSpaceFixerTest.php | 6 +- .../FunctionNotation/ImplodeCallFixerTest.php | 4 +- .../LambdaNotUsedImportFixerTest.php | 6 +- .../MethodArgumentSpaceFixerTest.php | 8 +- .../NativeFunctionInvocationFixerTest.php | 6 +- .../NoSpacesAfterFunctionNameFixerTest.php | 2 +- .../NoUselessSprintfFixerTest.php | 2 +- ...eclarationForDefaultNullValueFixerTest.php | 12 +- .../PhpdocToParamTypeFixerTest.php | 2 +- .../PhpdocToPropertyTypeFixerTest.php | 2 +- .../PhpdocToReturnTypeFixerTest.php | 6 +- .../RegularCallableCallFixerTest.php | 4 +- .../ReturnTypeDeclarationFixerTest.php | 8 +- .../SingleLineThrowFixerTest.php | 2 +- .../StaticLambdaFixerTest.php | 6 +- .../UseArrowFunctionsFixerTest.php | 2 +- .../FunctionNotation/VoidReturnFixerTest.php | 4 +- .../FullyQualifiedStrictTypesFixerTest.php | 6 +- .../Import/GlobalNamespaceImportFixerTest.php | 16 +-- tests/Fixer/Import/GroupImportFixerTest.php | 2 +- .../Import/NoLeadingImportSlashFixerTest.php | 6 +- .../Fixer/Import/OrderedImportsFixerTest.php | 10 +- .../SingleImportPerStatementFixerTest.php | 6 +- .../SingleLineAfterImportsFixerTest.php | 6 +- .../ClassKeywordRemoveFixerTest.php | 2 +- .../CombineConsecutiveIssetsFixerTest.php | 2 +- .../CombineConsecutiveUnsetsFixerTest.php | 2 +- .../DeclareEqualNormalizeFixerTest.php | 4 +- .../DeclareParenthesesFixerTest.php | 2 +- .../DirConstantFixerTest.php | 4 +- .../ErrorSuppressionFixerTest.php | 2 +- .../ExplicitIndirectVariableFixerTest.php | 4 +- .../FunctionToConstantFixerTest.php | 4 +- .../LanguageConstruct/IsNullFixerTest.php | 4 +- .../NoUnsetOnPropertyFixerTest.php | 4 +- .../SingleSpaceAfterConstructFixerTest.php | 112 +++++++++--------- .../ListNotation/ListSyntaxFixerTest.php | 8 +- .../BlankLineAfterNamespaceFixerTest.php | 4 +- .../CleanNamespaceFixerTest.php | 2 +- .../NoLeadingNamespaceWhitespaceFixerTest.php | 5 +- .../Naming/NoHomoglyphNamesFixerTest.php | 4 +- .../BinaryOperatorSpacesFixerTest.php | 18 +-- tests/Fixer/Operator/ConcatSpaceFixerTest.php | 4 +- .../Operator/IncrementStyleFixerTest.php | 4 +- .../Operator/LogicalOperatorsFixerTest.php | 2 +- .../Fixer/Operator/NewWithBracesFixerTest.php | 4 +- .../NotOperatorWithSpaceFixerTest.php | 2 +- ...NotOperatorWithSuccessorSpaceFixerTest.php | 2 +- ...jectOperatorWithoutWhitespaceFixerTest.php | 4 +- .../Operator/OperatorLinebreakFixerTest.php | 6 +- .../StandardizeIncrementFixerTest.php | 4 +- .../StandardizeNotEqualsFixerTest.php | 2 +- .../TernaryOperatorSpacesFixerTest.php | 4 +- .../TernaryToElvisOperatorFixerTest.php | 4 +- .../TernaryToNullCoalescingFixerTest.php | 2 +- .../Operator/UnaryOperatorSpacesFixerTest.php | 2 +- .../BlankLineAfterOpeningTagFixerTest.php | 4 +- tests/Fixer/PhpTag/EchoTagSyntaxFixerTest.php | 4 +- .../Fixer/PhpTag/FullOpeningTagFixerTest.php | 4 +- .../LinebreakAfterOpeningTagFixerTest.php | 4 +- tests/Fixer/PhpTag/NoClosingTagFixerTest.php | 4 +- .../PhpUnit/PhpUnitConstructFixerTest.php | 9 +- .../PhpUnitDedicateAssertFixerTest.php | 10 +- ...nitDedicateAssertInternalTypeFixerTest.php | 2 +- .../PhpUnit/PhpUnitExpectationFixerTest.php | 6 +- .../PhpUnit/PhpUnitInternalClassFixerTest.php | 2 +- tests/Fixer/PhpUnit/PhpUnitMockFixerTest.php | 2 +- .../PhpUnit/PhpUnitNamespacedFixerTest.php | 4 +- ...hpUnitNoExpectationAnnotationFixerTest.php | 4 +- .../PhpUnit/PhpUnitSizeClassFixerTest.php | 2 +- .../Fixer/PhpUnit/PhpUnitStrictFixerTest.php | 15 ++- .../PhpUnit/PhpUnitTargetVersionTest.php | 2 +- .../PhpUnitTestAnnotationFixerTest.php | 2 +- ...UnitTestCaseStaticMethodCallsFixerTest.php | 2 +- ...hpUnitTestClassRequiresCoversFixerTest.php | 4 +- .../Phpdoc/AlignMultilineCommentFixerTest.php | 6 +- .../GeneralPhpdocTagRenameFixerTest.php | 4 +- .../NoBlankLinesAfterPhpdocFixerTest.php | 2 +- tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php | 2 +- .../NoSuperfluousPhpdocTagsFixerTest.php | 8 +- ...pdocAddMissingParamAnnotationFixerTest.php | 10 +- tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php | 6 +- .../PhpdocAnnotationWithoutDotFixerTest.php | 2 +- tests/Fixer/Phpdoc/PhpdocIndentFixerTest.php | 2 +- .../PhpdocInlineTagNormalizerFixerTest.php | 2 +- .../Fixer/Phpdoc/PhpdocLineSpanFixerTest.php | 4 +- .../Phpdoc/PhpdocNoAliasTagFixerTest.php | 8 +- .../PhpdocNoUselessInheritdocFixerTest.php | 2 +- .../Phpdoc/PhpdocOrderByValueFixerTest.php | 30 ++--- .../PhpdocReturnSelfReferenceFixerTest.php | 8 +- tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php | 2 +- .../Phpdoc/PhpdocSeparationFixerTest.php | 2 +- .../PhpdocSingleLineVarSpacingFixerTest.php | 2 +- tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php | 4 +- .../Fixer/Phpdoc/PhpdocTagCasingFixerTest.php | 2 +- tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php | 2 +- .../Fixer/Phpdoc/PhpdocToCommentFixerTest.php | 12 +- ...onsecutiveBlankLineSeparationFixerTest.php | 2 +- tests/Fixer/Phpdoc/PhpdocTrimFixerTest.php | 2 +- .../Phpdoc/PhpdocTypesOrderFixerTest.php | 10 +- ...pdocVarAnnotationCorrectOrderFixerTest.php | 2 +- .../Phpdoc/PhpdocVarWithoutNameFixerTest.php | 2 +- .../NoUselessReturnFixerTest.php | 2 +- .../ReturnAssignmentFixerTest.php | 8 +- .../SimplifiedNullReturnFixerTest.php | 4 +- ...ineWhitespaceBeforeSemicolonsFixerTest.php | 10 +- .../Semicolon/NoEmptyStatementFixerTest.php | 8 +- ...ineWhitespaceBeforeSemicolonsFixerTest.php | 2 +- .../SemicolonAfterInstructionFixerTest.php | 2 +- .../SpaceAfterSemicolonFixerTest.php | 4 +- .../Strict/DeclareStrictTypesFixerTest.php | 6 +- .../Strict/StrictComparisonFixerTest.php | 2 +- tests/Fixer/Strict/StrictParamFixerTest.php | 4 +- .../EscapeImplicitBackslashesFixerTest.php | 2 +- .../ExplicitStringVariableFixerTest.php | 5 +- .../HeredocToNowdocFixerTest.php | 2 +- .../NoBinaryStringFixerTest.php | 2 +- .../NoTrailingWhitespaceInStringFixerTest.php | 2 +- .../StringNotation/SingleQuoteFixerTest.php | 4 +- .../Whitespace/ArrayIndentationFixerTest.php | 10 +- .../BlankLineBeforeStatementFixerTest.php | 10 +- .../CompactNullableTypehintFixerTest.php | 4 +- .../HeredocIndentationFixerTest.php | 2 +- .../MethodChainingIndentationFixerTest.php | 4 +- .../Whitespace/NoExtraBlankLinesFixerTest.php | 28 ++--- .../NoSpacesAroundOffsetFixerTest.php | 10 +- .../NoSpacesInsideParenthesisFixerTest.php | 4 +- .../NoWhitespaceInBlankLineFixerTest.php | 4 +- .../Fixer/Whitespace/TypesSpacesFixerTest.php | 4 +- .../AliasedFixerOptionTest.php | 14 +-- .../AllowedValueSubsetTest.php | 2 +- .../DeprecatedFixerOptionTest.php | 4 +- tests/FixerFactoryTest.php | 38 +++++- tests/FixerNameValidatorTest.php | 2 +- .../PhpUnitTestCaseIndicatorTest.php | 4 +- tests/Linter/CachingLinterTest.php | 2 +- tests/PregTest.php | 6 +- tests/RuleSet/RuleSetTest.php | 29 ++--- tests/RuleSet/Sets/AbstractSetTest.php | 26 +++- tests/Smoke/CiIntegrationTest.php | 2 +- tests/Test/AbstractFixerTestCase.php | 4 +- tests/Test/IntegrationCase.php | 2 +- tests/TextDiffTest.php | 7 +- .../Analyzer/Analysis/TypeAnalysisTest.php | 2 +- .../Analyzer/ArgumentsAnalyzerTest.php | 10 +- .../Tokenizer/Analyzer/BlocksAnalyzerTest.php | 6 +- .../Tokenizer/Analyzer/ClassyAnalyzerTest.php | 6 +- .../Analyzer/CommentsAnalyzerTest.php | 14 +-- .../Analyzer/FunctionsAnalyzerTest.php | 18 +-- .../Analyzer/GotoLabelAnalyzerTest.php | 2 +- .../Analyzer/NamespaceUsesAnalyzerTest.php | 4 +- .../Analyzer/NamespacesAnalyzerTest.php | 4 +- .../Analyzer/ReferenceAnalyzerTest.php | 4 +- .../Tokenizer/Analyzer/SwitchAnalyzerTest.php | 2 +- .../Analyzer/WhitespacesAnalyzerTest.php | 2 +- tests/Tokenizer/CTTest.php | 8 +- .../NamespacedStringTokenGeneratorTest.php | 2 +- .../Resolver/TypeShortNameResolverTest.php | 2 +- tests/Tokenizer/TokenTest.php | 46 ++++--- tests/Tokenizer/TokensAnalyzerTest.php | 44 +++---- tests/Tokenizer/TokensTest.php | 50 ++++---- .../ArrayTypehintTransformerTest.php | 4 +- .../Transformer/AttributeTransformerTest.php | 4 +- ...BraceClassInstantiationTransformerTest.php | 8 +- .../ClassConstantTransformerTest.php | 2 +- .../ConstructorPromotionTransformerTest.php | 2 +- .../Transformer/CurlyBraceTransformerTest.php | 4 +- .../Transformer/ImportTransformerTest.php | 2 +- .../NameQualifiedTransformerTest.php | 2 +- .../NamedArgumentTransformerTest.php | 4 +- .../NamespaceOperatorTransformerTest.php | 2 +- .../NullableTypeTransformerTest.php | 6 +- .../Transformer/ReturnRefTransformerTest.php | 4 +- .../SquareBraceTransformerTest.php | 8 +- .../TypeAlternationTransformerTest.php | 4 +- .../Transformer/TypeColonTransformerTest.php | 4 +- .../Transformer/UseTransformerTest.php | 4 +- .../WhitespacyCommentTransformerTest.php | 2 +- tests/Tokenizer/TransformersTest.php | 2 +- tests/UtilsTest.php | 6 +- tests/WhitespacesFixerConfigTest.php | 2 +- 297 files changed, 952 insertions(+), 975 deletions(-) diff --git a/src/AbstractFunctionReferenceFixer.php b/src/AbstractFunctionReferenceFixer.php index 8b2ded48fbe..a1c57d9541d 100644 --- a/src/AbstractFunctionReferenceFixer.php +++ b/src/AbstractFunctionReferenceFixer.php @@ -41,7 +41,7 @@ public function isRisky(): bool protected function find(string $functionNameToSearch, Tokens $tokens, int $start = 0, ?int $end = null): ?array { // make interface consistent with findSequence - $end = null === $end ? $tokens->count() : $end; + $end = $end ?? $tokens->count(); // find raw sequence which we can analyse for context $candidateSequence = [[T_STRING, $functionNameToSearch], '(']; diff --git a/src/ConfigurationException/InvalidConfigurationException.php b/src/ConfigurationException/InvalidConfigurationException.php index 9356b6098df..001c724ee96 100644 --- a/src/ConfigurationException/InvalidConfigurationException.php +++ b/src/ConfigurationException/InvalidConfigurationException.php @@ -30,7 +30,7 @@ public function __construct(string $message, ?int $code = null, ?\Throwable $pre { parent::__construct( $message, - null === $code ? FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG : $code, + $code ?? FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG, $previous ); } diff --git a/src/Console/Command/DescribeCommand.php b/src/Console/Command/DescribeCommand.php index ba013159966..66464a025ce 100644 --- a/src/Console/Command/DescribeCommand.php +++ b/src/Console/Command/DescribeCommand.php @@ -278,7 +278,7 @@ static function (string $type) { $configuration = $codeSample->getConfiguration(); if ($fixer instanceof ConfigurableFixerInterface) { - $fixer->configure(null === $configuration ? [] : $configuration); + $fixer->configure($configuration ?? []); } $file = $codeSample instanceof FileSpecificCodeSampleInterface diff --git a/src/Console/ConfigurationResolver.php b/src/Console/ConfigurationResolver.php index ea2df2eb31e..849ffd1ae4d 100644 --- a/src/Console/ConfigurationResolver.php +++ b/src/Console/ConfigurationResolver.php @@ -591,9 +591,7 @@ private function createFixerFactory(): FixerFactory private function getFormat(): string { if (null === $this->format) { - $this->format = null === $this->options['format'] - ? $this->getConfig()->getFormat() - : $this->options['format']; + $this->format = $this->options['format'] ?? $this->getConfig()->getFormat(); } return $this->format; diff --git a/src/DocBlock/TypeExpression.php b/src/DocBlock/TypeExpression.php index 66738cbd3c0..3fcb471d3fb 100644 --- a/src/DocBlock/TypeExpression.php +++ b/src/DocBlock/TypeExpression.php @@ -217,11 +217,7 @@ private function getParentType(string $type1, string $type2): ?string 'self|static' => 'self', ]; - if (isset($parents[$types])) { - return $parents[$types]; - } - - return null; + return $parents[$types] ?? null; } private function normalize(string $type): string diff --git a/src/Documentation/DocumentationGenerator.php b/src/Documentation/DocumentationGenerator.php index ae8e66279f6..c56e87365a5 100644 --- a/src/Documentation/DocumentationGenerator.php +++ b/src/Documentation/DocumentationGenerator.php @@ -90,11 +90,7 @@ public function generateFixersDocumentationIndex(array $fixers): string $currentGroup = null; foreach ($fixers as $fixer) { $namespace = Preg::replace('/^.*\\\\(.+)\\\\.+Fixer$/', '$1', \get_class($fixer)); - if (isset($overrideGroups[$namespace])) { - $group = $overrideGroups[$namespace]; - } else { - $group = Preg::replace('/(?<=[[:lower:]])(?=[[:upper:]])/', ' ', $namespace); - } + $group = $overrideGroups[$namespace] ?? Preg::replace('/(?<=[[:lower:]])(?=[[:upper:]])/', ' ', $namespace); if ($group !== $currentGroup) { $underline = str_repeat('-', \strlen($group)); diff --git a/src/Fixer/ControlStructure/YodaStyleFixer.php b/src/Fixer/ControlStructure/YodaStyleFixer.php index 9cfd7f45481..1770af180a9 100644 --- a/src/Fixer/ControlStructure/YodaStyleFixer.php +++ b/src/Fixer/ControlStructure/YodaStyleFixer.php @@ -459,7 +459,7 @@ private function isOfLowerPrecedence(Token $token): bool * Checks whether the given assignment token has a lower precedence than `T_IS_EQUAL` * or `T_IS_IDENTICAL`. */ - private function isOfLowerPrecedenceAssignment(Token $token) + private function isOfLowerPrecedenceAssignment(Token $token): bool { static $tokens; diff --git a/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php b/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php index 3430fc36b0a..fb3fa346f4c 100644 --- a/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php +++ b/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php @@ -408,11 +408,7 @@ private function toComparableNames(array $types, array $symbolShortNames): array static function (string $type) use ($symbolShortNames) { $type = strtolower($type); - if (isset($symbolShortNames[$type])) { - return $symbolShortNames[$type]; - } - - return $type; + return $symbolShortNames[$type] ?? $type; }, $types ); diff --git a/src/FixerFactory.php b/src/FixerFactory.php index c683052fc03..ec47fc93585 100644 --- a/src/FixerFactory.php +++ b/src/FixerFactory.php @@ -89,12 +89,10 @@ public function registerBuiltInFixers(): self $builtInFixers = []; /** @var SplFileInfo $file */ - foreach (SymfonyFinder::create()->files()->in(__DIR__.'/Fixer')->depth(1) as $file) { + foreach (SymfonyFinder::create()->files()->in(__DIR__.'/Fixer')->name('*Fixer.php')->depth(1) as $file) { $relativeNamespace = $file->getRelativePath(); $fixerClass = 'PhpCsFixer\\Fixer\\'.($relativeNamespace ? $relativeNamespace.'\\' : '').$file->getBasename('.php'); - if ('Fixer' === substr($fixerClass, -5)) { - $builtInFixers[] = $fixerClass; - } + $builtInFixers[] = $fixerClass; } } diff --git a/tests/AbstractFunctionReferenceFixerTest.php b/tests/AbstractFunctionReferenceFixerTest.php index 2c84a2396a4..e7841336ad3 100644 --- a/tests/AbstractFunctionReferenceFixerTest.php +++ b/tests/AbstractFunctionReferenceFixerTest.php @@ -69,7 +69,7 @@ public function testAbstractFunctionReferenceFixer( static::assertFalse($tokens->isChanged()); } - public function provideAbstractFunctionReferenceFixerCases() + public function provideAbstractFunctionReferenceFixerCases(): array { return [ 'simple case I' => [ diff --git a/tests/AutoReview/CiConfigurationTest.php b/tests/AutoReview/CiConfigurationTest.php index ece4c406d8d..9cf09f793ec 100644 --- a/tests/AutoReview/CiConfigurationTest.php +++ b/tests/AutoReview/CiConfigurationTest.php @@ -81,7 +81,7 @@ public function testDeploymentJobsRunOnLatestStablePhpThatIsSupportedByTool(): v } } - private static function generateMinorVersionsRange(float $from, float $to) + private static function generateMinorVersionsRange(float $from, float $to): array { $range = []; @@ -135,7 +135,7 @@ private static function assertSupportedPhpVersionsAreCoveredByCiJobs(array $supp )); } - private function getAllPhpVersionsUsedByCiForDeployments() + private function getAllPhpVersionsUsedByCiForDeployments(): array { $jobs = array_filter($this->getGitHubJobs(), function (array $job) { return isset($job['execute-deployment']) && 'yes' === $job['execute-deployment']; @@ -151,7 +151,7 @@ private function getAllPhpVersionsUsedByCiForTests() return $this->getPhpVersionsUsedByGitHub(); } - private function convertPhpVerIdToNiceVer(string $verId) + private function convertPhpVerIdToNiceVer(string $verId): string { $matchResult = Preg::match('/^(?\d{1,2})(?\d{2})(?\d{2})$/', $verId, $capture); if (1 !== $matchResult) { @@ -161,7 +161,7 @@ private function convertPhpVerIdToNiceVer(string $verId) return sprintf('%d.%d', $capture['major'], $capture['minor']); } - private function getMaxPhpVersionFromEntryFile() + private function getMaxPhpVersionFromEntryFile(): string { $tokens = Tokens::fromCode(file_get_contents(__DIR__.'/../../php-cs-fixer')); $sequence = $tokens->findSequence([ @@ -179,7 +179,7 @@ private function getMaxPhpVersionFromEntryFile() return $this->convertPhpVerIdToNiceVer((string) ($phpVerId - 100)); } - private function getMinPhpVersionFromEntryFile() + private function getMinPhpVersionFromEntryFile(): string { $tokens = Tokens::fromCode(file_get_contents(__DIR__.'/../../php-cs-fixer')); $sequence = $tokens->findSequence([ diff --git a/tests/AutoReview/CommandTest.php b/tests/AutoReview/CommandTest.php index 8d0a5209bb5..861482c4b89 100644 --- a/tests/AutoReview/CommandTest.php +++ b/tests/AutoReview/CommandTest.php @@ -37,7 +37,7 @@ public function testCommandHasNameConst(Command $command): void static::assertNotNull($command->getDefaultName()); } - public function provideCommandHasNameConstCases() + public function provideCommandHasNameConstCases(): array { $application = new Application(); $commands = $application->all(); diff --git a/tests/AutoReview/DescribeCommandTest.php b/tests/AutoReview/DescribeCommandTest.php index a520bbf5456..ebe700e58a2 100644 --- a/tests/AutoReview/DescribeCommandTest.php +++ b/tests/AutoReview/DescribeCommandTest.php @@ -48,17 +48,13 @@ public function testDescribeCommand(FixerFactory $factory, string $fixerName): v static::assertSame(0, $commandTester->getStatusCode()); } - public function provideDescribeCommandCases() + public function provideDescribeCommandCases(): \Generator { $factory = new FixerFactory(); $factory->registerBuiltInFixers(); - $cases = []; - foreach ($factory->getFixers() as $fixer) { - $cases[] = [$factory, $fixer->getName()]; + yield [$factory, $fixer->getName()]; } - - return $cases; } } diff --git a/tests/AutoReview/DocumentationTest.php b/tests/AutoReview/DocumentationTest.php index 7c86470cd90..71244c72fc4 100644 --- a/tests/AutoReview/DocumentationTest.php +++ b/tests/AutoReview/DocumentationTest.php @@ -85,15 +85,11 @@ function (array $matches) use ($actual) { static::assertSame($expected, $actual); } - public function provideFixerCases() + public function provideFixerCases(): \Generator { - $cases = []; - foreach ($this->getFixers() as $fixer) { - $cases[$fixer->getName()] = [$fixer]; + yield $fixer->getName() => [$fixer]; } - - return $cases; } public function testFixersDocumentationIndexFileIsUpToDate(): void @@ -183,7 +179,7 @@ private static function assertFileEqualsString(string $expectedString, string $a static::assertSame($expectedString, file_get_contents($actualFilePath), $message); } - private function getFixers() + private function getFixers(): array { $factory = new FixerFactory(); $factory->registerBuiltInFixers(); diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 7d6dc4832d2..24e0134f70c 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -382,7 +382,7 @@ public function testFixersPriorityPairsHaveIntegrationTest(FixerInterface $first static::assertSame($expected, $actual, sprintf('The ruleset of "%s" must contain the rules for the priority test.', $file)); } - public function provideFixersPriorityPairsHaveIntegrationTestCases() + public function provideFixersPriorityPairsHaveIntegrationTestCases(): array { return array_filter( $this->provideFixersPriorityCases(), @@ -455,9 +455,10 @@ public function testPriorityIntegrationTestFilesAreListedPriorityCases(string $f ); } - public function provideIntegrationTestFilesCases() + public function provideIntegrationTestFilesCases(): array { $fileNames = []; + foreach (new \DirectoryIterator($this->getIntegrationPriorityDirectory()) as $candidate) { if ($candidate->isDot()) { continue; diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index 9ccfb8ed6c1..7c640f9ed76 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -559,7 +559,7 @@ static function (\ReflectionMethod $rm) { ); } - public function provideSrcClassCases() + public function provideSrcClassCases(): array { return array_map( static function (string $item) { @@ -569,7 +569,7 @@ static function (string $item) { ); } - public function provideSrcClassesNotAbuseInterfacesCases() + public function provideSrcClassesNotAbuseInterfacesCases(): array { return array_map( static function (string $item) { @@ -615,7 +615,7 @@ static function (string $item) { ); } - public function provideSrcConcreteClassCases() + public function provideSrcConcreteClassCases(): array { return array_map( static function (string $item) { return [$item]; }, @@ -630,7 +630,7 @@ static function (string $className) { ); } - public function provideTestClassCases() + public function provideTestClassCases(): array { return array_map( static function (string $item) { @@ -640,7 +640,7 @@ static function (string $item) { ); } - public function provideClassesWherePregFunctionsAreForbiddenCases() + public function provideClassesWherePregFunctionsAreForbiddenCases(): array { return array_map( static function (string $item) { @@ -665,7 +665,7 @@ public function testPhpUnitFixerExtendsAbstractPhpUnitFixer(string $className): static::assertTrue($reflection->isSubclassOf(\PhpCsFixer\Fixer\AbstractPhpUnitFixer::class)); } - public function providePhpUnitFixerExtendsAbstractPhpUnitFixerCases() + public function providePhpUnitFixerExtendsAbstractPhpUnitFixerCases(): \Generator { $factory = new FixerFactory(); $factory->registerBuiltInFixers(); @@ -710,7 +710,7 @@ public function testConstantsAreInUpperCase(string $className): void } } - private function getUsedDataProviderMethodNames(string $testClassName) + private function getUsedDataProviderMethodNames(string $testClassName): array { $dataProviderMethodNames = []; $tokens = Tokens::fromCode(file_get_contents( diff --git a/tests/AutoReview/ProjectFixerConfigurationTest.php b/tests/AutoReview/ProjectFixerConfigurationTest.php index 35b531ac27c..9a938c200a5 100644 --- a/tests/AutoReview/ProjectFixerConfigurationTest.php +++ b/tests/AutoReview/ProjectFixerConfigurationTest.php @@ -34,7 +34,6 @@ public function testCreate(): void { $config = $this->loadConfig(); - static::assertInstanceOf(\PhpCsFixer\Config::class, $config); static::assertEmpty($config->getCustomFixers()); static::assertNotEmpty($config->getRules()); diff --git a/tests/AutoReview/TransformerTest.php b/tests/AutoReview/TransformerTest.php index f2aa1700a11..1ca4d645b65 100644 --- a/tests/AutoReview/TransformerTest.php +++ b/tests/AutoReview/TransformerTest.php @@ -70,7 +70,7 @@ public function testTransformerPriorityIsListed(TransformerInterface $transforme static::fail(sprintf('Transformer "%s" has priority %d but is not in priority test list.', $name, $priority)); } - public function provideTransformerPriorityCases() + public function provideTransformerPriorityCases(): array { $transformers = []; diff --git a/tests/Cache/CacheTest.php b/tests/Cache/CacheTest.php index 0e12441a91a..0bdbac63037 100644 --- a/tests/Cache/CacheTest.php +++ b/tests/Cache/CacheTest.php @@ -155,7 +155,7 @@ public function testCanConvertToAndFromJson(SignatureInterface $signature): void static::assertSame($hash, $cached->get($file)); } - public function provideCanConvertToAndFromJsonCases() + public function provideCanConvertToAndFromJsonCases(): array { $toolInfo = new ToolInfo(); $config = new Config(); diff --git a/tests/Cache/SignatureTest.php b/tests/Cache/SignatureTest.php index 3b49ff2844e..a6d7e72adfc 100644 --- a/tests/Cache/SignatureTest.php +++ b/tests/Cache/SignatureTest.php @@ -74,7 +74,7 @@ public function testEqualsReturnsFalseIfValuesAreNotIdentical(Signature $signatu static::assertFalse($signature->equals($anotherSignature)); } - public function provideEqualsReturnsFalseIfValuesAreNotIdenticalCases() + public function provideEqualsReturnsFalseIfValuesAreNotIdenticalCases(): \Generator { $php = PHP_VERSION; $version = '2.0'; diff --git a/tests/Console/Command/FixCommandExitStatusCalculatorTest.php b/tests/Console/Command/FixCommandExitStatusCalculatorTest.php index 732dcb41440..9cd824ef389 100644 --- a/tests/Console/Command/FixCommandExitStatusCalculatorTest.php +++ b/tests/Console/Command/FixCommandExitStatusCalculatorTest.php @@ -40,7 +40,7 @@ public function testCalculate(int $expected, bool $isDryRun, bool $hasChangedFil ); } - public function provideCalculateCases() + public function provideCalculateCases(): array { return [ [0, true, false, false, false, false], diff --git a/tests/Console/Command/FixCommandTest.php b/tests/Console/Command/FixCommandTest.php index 30eea9f7837..c113e9cc491 100644 --- a/tests/Console/Command/FixCommandTest.php +++ b/tests/Console/Command/FixCommandTest.php @@ -81,7 +81,7 @@ private function doTestExecute(array $arguments): CommandTester return $commandTester; } - private function getDefaultArguments() + private function getDefaultArguments(): array { return [ 'path' => [__FILE__], diff --git a/tests/Console/Command/HelpCommandTest.php b/tests/Console/Command/HelpCommandTest.php index 84314f09d9e..ac2c01649da 100644 --- a/tests/Console/Command/HelpCommandTest.php +++ b/tests/Console/Command/HelpCommandTest.php @@ -36,7 +36,7 @@ public function testToString(string $expected, $input): void static::assertSame($expected, HelpCommand::toString($input)); } - public function provideToStringCases() + public function provideToStringCases(): \Generator { yield ["['a' => 3, 'b' => 'c']", ['a' => 3, 'b' => 'c']]; yield ['[[1], [2]]', [[1], [2]]]; @@ -61,7 +61,7 @@ public function testGetDisplayableAllowedValues($expected, FixerOptionInterface static::assertSame($expected, HelpCommand::getDisplayableAllowedValues($input)); } - public function provideGetDisplayableAllowedValuesCases() + public function provideGetDisplayableAllowedValuesCases(): \Generator { yield [null, new FixerOption('foo', 'bar', false, null, ['int'], [])]; yield [['A', 'B', 'x', 'z'], new FixerOption('foo', 'bar', false, null, ['string'], ['z', 'x', 'B', 'A'])]; diff --git a/tests/Console/Command/SelfUpdateCommandTest.php b/tests/Console/Command/SelfUpdateCommandTest.php index 52c6476ca15..eee0bfc3736 100644 --- a/tests/Console/Command/SelfUpdateCommandTest.php +++ b/tests/Console/Command/SelfUpdateCommandTest.php @@ -80,7 +80,7 @@ public function testCommandName(string $name): void static::assertSame($command, $application->find($name)); } - public function provideCommandNameCases() + public function provideCommandNameCases(): array { return [ ['self-update'], @@ -134,7 +134,7 @@ public function testExecute( static::assertSame(0, $commandTester->getStatusCode()); } - public function provideExecuteCases() + public function provideExecuteCases(): array { $currentVersion = Application::VERSION; $minorRelease = $this->getNewMinorReleaseVersion(); @@ -273,7 +273,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions( static::assertSame(1, $commandTester->getStatusCode()); } - public function provideExecuteWhenNotAbleToGetLatestVersionsCases() + public function provideExecuteWhenNotAbleToGetLatestVersionsCases(): array { return [ [false, false, [], true], @@ -317,7 +317,7 @@ public function testExecuteWhenNotInstalledAsPhar(array $input, bool $decorated) static::assertSame(1, $commandTester->getStatusCode()); } - public function provideExecuteWhenNotInstalledAsPharCases() + public function provideExecuteWhenNotInstalledAsPharCases(): array { return [ [[], true], @@ -329,7 +329,7 @@ public function provideExecuteWhenNotInstalledAsPharCases() ]; } - private function execute(Command $command, array $input, $decorated) + private function execute(Command $command, array $input, $decorated): CommandTester { $application = new Application(); $application->add($command); @@ -381,27 +381,27 @@ private function createToolInfo(bool $isInstalledAsPhar = true) return $toolInfo->reveal(); } - private function getToolPath() + private function getToolPath(): string { return "{$this->root->url()}/php-cs-fixer"; } - private function getCurrentMajorVersion() + private function getCurrentMajorVersion(): int { return (int) preg_replace('/^v?(\d+).*$/', '$1', Application::VERSION); } - private function getNewMinorReleaseVersion() + private function getNewMinorReleaseVersion(): string { return "{$this->getCurrentMajorVersion()}.999.0"; } - private function getNewMajorVersion() + private function getNewMajorVersion(): int { return $this->getCurrentMajorVersion() + 1; } - private function getNewMajorReleaseVersion() + private function getNewMajorReleaseVersion(): string { return $this->getNewMajorVersion().'.0.0'; } diff --git a/tests/Console/ConfigurationResolverTest.php b/tests/Console/ConfigurationResolverTest.php index ff17a476980..677778c979e 100644 --- a/tests/Console/ConfigurationResolverTest.php +++ b/tests/Console/ConfigurationResolverTest.php @@ -130,7 +130,7 @@ public function testResolveProgressWithNegativeConfigAndExplicitProgress(string static::assertSame($progressType, $resolver->getProgress()); } - public function provideProgressTypeCases() + public function provideProgressTypeCases(): array { return [ ['none'], @@ -195,7 +195,7 @@ public function testResolveConfigFileChooseFile(string $expectedFile, string $ex static::assertInstanceOf($expectedClass, $resolver->getConfig()); } - public function provideResolveConfigFileDefaultCases() + public function provideResolveConfigFileDefaultCases(): array { $dirBase = $this->getFixtureDir(); @@ -297,7 +297,7 @@ public function testResolvePath(array $paths, string $cwd, array $expectedPaths) static::assertSame($expectedPaths, $resolver->getPath()); } - public function providePathCases() + public function providePathCases(): \Generator { yield [ ['Command'], @@ -343,7 +343,7 @@ public function testRejectInvalidPath(array $paths, string $expectedMessage): vo $resolver->getPath(); } - public function provideEmptyPathCases() + public function provideEmptyPathCases(): \Generator { yield [ [''], @@ -496,7 +496,7 @@ static function (\SplFileInfo $file) { static::assertSame($expected, $intersectionItems); } - public function provideResolveIntersectionOfPathsCases() + public function provideResolveIntersectionOfPathsCases(): array { $dir = __DIR__.'/../Fixtures/ConfigurationResolverPathsIntersection'; $cb = static function (array $items) use ($dir) { @@ -662,7 +662,7 @@ public function testConfigFinderIsOverridden(array $options, bool $expectedResul static::assertSame($expectedResult, $resolver->configFinderIsOverridden()); } - public function provideConfigFinderIsOverriddenCases() + public function provideConfigFinderIsOverriddenCases(): array { $root = __DIR__.'/../..'; @@ -1040,7 +1040,7 @@ public function testResolveDiffer(string $expected, $diffConfig): void static::assertInstanceOf($expected, $resolver->getDiffer()); } - public function provideDifferCases() + public function provideDifferCases(): array { return [ [ @@ -1081,7 +1081,7 @@ public function testDeprecationOfPassingOtherThanNoOrYes(): void $resolver->getRiskyAllowed(); } - public function provideResolveBooleanOptionCases() + public function provideResolveBooleanOptionCases(): array { return [ [true, true, 'yes'], @@ -1122,7 +1122,7 @@ public function testDeprecatedFixerConfigured($ruleConfig): void $resolver->getFixers(); } - public function provideDeprecatedFixerConfiguredCases() + public function provideDeprecatedFixerConfiguredCases(): array { return [ [true], @@ -1131,7 +1131,7 @@ public function provideDeprecatedFixerConfiguredCases() ]; } - public function provideGetDirectoryCases() + public function provideGetDirectoryCases(): array { return [ [null, '/my/path/my/file', 'path/my/file'], @@ -1171,20 +1171,20 @@ private function normalizePath(string $path): string return str_replace('/', \DIRECTORY_SEPARATOR, $path); } - private static function assertSameRules(array $expected, array $actual, string $message = ''): void + private static function assertSameRules(array $expected, array $actual): void { ksort($expected); ksort($actual); - static::assertSame($expected, $actual, $message); + static::assertSame($expected, $actual); } - private function getFixtureDir() + private function getFixtureDir(): string { return realpath(__DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Fixtures'.\DIRECTORY_SEPARATOR.'ConfigurationResolverConfigFile'.\DIRECTORY_SEPARATOR).'/'; } - private function createConfigurationResolver(array $options, Config $config = null, string $cwdPath = '') + private function createConfigurationResolver(array $options, Config $config = null, string $cwdPath = ''): ConfigurationResolver { if (null === $config) { $config = new Config(); diff --git a/tests/Console/Output/ErrorOutputTest.php b/tests/Console/Output/ErrorOutputTest.php index 17b1d835fb7..df588de4b07 100644 --- a/tests/Console/Output/ErrorOutputTest.php +++ b/tests/Console/Output/ErrorOutputTest.php @@ -83,7 +83,7 @@ public function testErrorOutput(Error $error, int $verbosityLevel, int $lineNumb static::assertStringStartsWith($startWith, $displayed); } - public function provideTestCases() + public function provideTestCases(): array { $lineNumber = __LINE__; [$exceptionLineNumber, $error] = $this->getErrorAndLineNumber(); // note: keep call and __LINE__ separated with one line break @@ -159,7 +159,7 @@ private function readFullStreamOutput(StreamOutput $output): string return str_replace(PHP_EOL, "\n", $displayed); } - private function getErrorAndLineNumber() + private function getErrorAndLineNumber(): array { $lineNumber = __LINE__; $exception = new \RuntimeException(// note: keep exception constructor and __LINE__ separated with one line break diff --git a/tests/Console/Output/ProcessOutputTest.php b/tests/Console/Output/ProcessOutputTest.php index 11826741291..c76774e0280 100644 --- a/tests/Console/Output/ProcessOutputTest.php +++ b/tests/Console/Output/ProcessOutputTest.php @@ -50,7 +50,7 @@ public function testProcessProgressOutput(array $statuses, string $expectedOutpu static::assertSame($expectedOutput, $output->fetch()); } - public function provideProcessProgressOutputCases() + public function provideProcessProgressOutputCases(): array { return [ [ diff --git a/tests/Console/SelfUpdate/NewVersionCheckerTest.php b/tests/Console/SelfUpdate/NewVersionCheckerTest.php index 682a81eb31d..668169088bd 100644 --- a/tests/Console/SelfUpdate/NewVersionCheckerTest.php +++ b/tests/Console/SelfUpdate/NewVersionCheckerTest.php @@ -42,7 +42,7 @@ public function testGetLatestVersionOfMajor(int $majorVersion, ?string $expected static::assertSame($expectedVersion, $checker->getLatestVersionOfMajor($majorVersion)); } - public function provideLatestVersionOfMajorCases() + public function provideLatestVersionOfMajorCases(): array { return [ [1, 'v1.13.2'], @@ -68,7 +68,7 @@ public function testCompareVersions(string $versionA, string $versionB, int $exp ); } - public function provideCompareVersionsCases() + public function provideCompareVersionsCases(): array { $cases = []; diff --git a/tests/Differ/AbstractDifferTestCase.php b/tests/Differ/AbstractDifferTestCase.php index 17f8de29bf5..7a0b303c605 100644 --- a/tests/Differ/AbstractDifferTestCase.php +++ b/tests/Differ/AbstractDifferTestCase.php @@ -40,7 +40,7 @@ final public function testIsDiffer(): void static::assertInstanceOf(\PhpCsFixer\Differ\DifferInterface::class, $differ); } - final protected function oldCode() + final protected function oldCode(): string { return <<<'PHP' $content) { - $cases[] = [$index, $content]; + yield [$index, $content]; } - - return $cases; } /** @@ -122,15 +118,11 @@ public function testStart(int $index, int $start): void static::assertSame($start, $annotation->getStart()); } - public function provideStartCases() + public function provideStartCases(): \Generator { - $cases = []; - foreach (self::$start as $index => $start) { - $cases[] = [$index, $start]; + yield [$index, $start]; } - - return $cases; } /** @@ -144,15 +136,11 @@ public function testEnd(int $index, int $end): void static::assertSame($end, $annotation->getEnd()); } - public function provideEndCases() + public function provideEndCases(): \Generator { - $cases = []; - foreach (self::$end as $index => $end) { - $cases[] = [$index, $end]; + yield [$index, $end]; } - - return $cases; } /** @@ -166,15 +154,11 @@ public function testGetTag(int $index, string $tag): void static::assertSame($tag, $annotation->getTag()->getName()); } - public function provideGetTagCases() + public function provideGetTagCases(): \Generator { - $cases = []; - foreach (self::$tags as $index => $tag) { - $cases[] = [$index, $tag]; + yield [$index, $tag]; } - - return $cases; } /** @@ -191,15 +175,11 @@ public function testRemove(int $index, int $start, int $end): void static::assertSame('', $doc->getLine($end)->getContent()); } - public function provideRemoveCases() + public function provideRemoveCases(): \Generator { - $cases = []; - foreach (self::$start as $index => $start) { - $cases[] = [$index, $start, self::$end[$index]]; + yield [$index, $start, self::$end[$index]]; } - - return $cases; } /** @@ -214,7 +194,7 @@ public function testRemoveEdgeCases(string $expected, string $input): void static::assertSame($expected, $doc->getContent()); } - public function provideRemoveEdgeCasesCases() + public function provideRemoveEdgeCasesCases(): array { return [ // Single line @@ -263,7 +243,7 @@ public function testTypeParsing(string $input, array $expected): void static::assertSame($expected, $tag->getTypes()); } - public function provideTypeParsingCases() + public function provideTypeParsingCases(): array { return [ [ @@ -485,7 +465,7 @@ public function testTypes(array $expected, array $new, string $input, string $ou static::assertSame($output, $line->getContent()); } - public function provideTypesCases() + public function provideTypesCases(): array { return [ [['Foo', 'null'], ['Bar[]'], ' * @param Foo|null $foo', ' * @param Bar[] $foo'], @@ -510,7 +490,7 @@ public function testNormalizedTypes(array $expected, string $input): void static::assertSame($expected, $tag->getNormalizedTypes()); } - public function provideNormalizedTypesCases() + public function provideNormalizedTypesCases(): array { return [ [['null', 'string'], '* @param StRiNg|NuLl $foo'], @@ -564,7 +544,7 @@ public function testGetTypeExpression(array $lines, ?NamespaceAnalysis $namespac static::assertSame($expectedCommonType, $result->getCommonType()); } - public function provideTypeExpressionCases() + public function provideTypeExpressionCases(): \Generator { $appNamespace = new NamespaceAnalysis('App', 'App', 0, 999, 0, 999); $useTraversable = new NamespaceUseAnalysis('Traversable', 'Traversable', false, 0, 999, NamespaceUseAnalysis::TYPE_CLASS); @@ -585,7 +565,7 @@ public function testGetVariableName(array $lines, ?string $expectedVariableName) static::assertSame($expectedVariableName, $annotation->getVariableName()); } - public function provideGetVariableCases() + public function provideGetVariableCases(): \Generator { yield [[new Line('* @param int $foo')], '$foo']; yield [[new Line('* @param int $foo some description')], '$foo']; diff --git a/tests/DocBlock/DocBlockTest.php b/tests/DocBlock/DocBlockTest.php index e7e702abf14..a60539b0da1 100644 --- a/tests/DocBlock/DocBlockTest.php +++ b/tests/DocBlock/DocBlockTest.php @@ -178,7 +178,7 @@ public function testMakeMultiLIne(string $inputDocBlock, string $outputDocBlock static::assertSame($outputDocBlock, $doc->getContent()); } - public function provideDocBlocksToConvertToMultiLineCases() + public function provideDocBlocksToConvertToMultiLineCases(): array { return [ 'It keeps a multi line doc block as is' => [ @@ -225,7 +225,7 @@ public function testMakeSingleLine(string $inputDocBlock, string $outputDocBlock static::assertSame($outputDocBlock, $doc->getContent()); } - public function provideDocBlocksToConvertToSingleLineCases() + public function provideDocBlocksToConvertToSingleLineCases(): array { return [ 'It keeps a single line doc block as is' => [ diff --git a/tests/DocBlock/LineTest.php b/tests/DocBlock/LineTest.php index 70e3b2aa023..87dba810dda 100644 --- a/tests/DocBlock/LineTest.php +++ b/tests/DocBlock/LineTest.php @@ -141,15 +141,11 @@ public function testStartOrEndPos(int $pos): void static::assertSame(14 === $pos, $line->isTheEnd()); } - public function provideLinesCases() + public function provideLinesCases(): \Generator { - $cases = []; - foreach (self::$content as $index => $content) { - $cases[] = [$index, $content]; + yield [$index, $content]; } - - return $cases; } /** @@ -163,15 +159,11 @@ public function testUseful(int $pos, bool $useful): void static::assertSame($useful, $line->containsUsefulContent()); } - public function provideLinesWithUsefulCases() + public function provideLinesWithUsefulCases(): \Generator { - $cases = []; - foreach (self::$useful as $index => $useful) { - $cases[] = [$index, $useful]; + yield [$index, $useful]; } - - return $cases; } /** @@ -185,15 +177,11 @@ public function testTag(int $pos, bool $tag): void static::assertSame($tag, $line->containsATag()); } - public function provideLinesWithTagCases() + public function provideLinesWithTagCases(): \Generator { - $cases = []; - foreach (self::$tag as $index => $tag) { - $cases[] = [$index, $tag]; + yield [$index, $tag]; } - - return $cases; } public function testSetContent(): void diff --git a/tests/DocBlock/ShortDescriptionTest.php b/tests/DocBlock/ShortDescriptionTest.php index 524c0307d0a..60265ba290b 100644 --- a/tests/DocBlock/ShortDescriptionTest.php +++ b/tests/DocBlock/ShortDescriptionTest.php @@ -36,7 +36,7 @@ public function testGetEnd(?int $expected, string $input): void static::assertSame($expected, $shortDescription->getEnd()); } - public function provideGetEndCases() + public function provideGetEndCases(): array { return [ [1, '/** diff --git a/tests/DocBlock/TagComparatorTest.php b/tests/DocBlock/TagComparatorTest.php index d0123145af5..2da7cc434e4 100644 --- a/tests/DocBlock/TagComparatorTest.php +++ b/tests/DocBlock/TagComparatorTest.php @@ -39,7 +39,7 @@ public function testComparatorTogether(string $first, string $second, bool $expe static::assertSame($expected, TagComparator::shouldBeTogether($tag1, $tag2)); } - public function provideComparatorCases() + public function provideComparatorCases(): array { return [ ['return', 'return', true], diff --git a/tests/DocBlock/TagTest.php b/tests/DocBlock/TagTest.php index 715821f7df5..06e115e3ed0 100644 --- a/tests/DocBlock/TagTest.php +++ b/tests/DocBlock/TagTest.php @@ -46,7 +46,7 @@ public function testName(string $expected, string $new, string $input): void static::assertSame($new, $tag->getName()); } - public function provideNameCases() + public function provideNameCases(): array { return [ ['param', 'var', ' * @param Foo $foo'], @@ -72,7 +72,7 @@ public function testValid(bool $expected, string $input): void static::assertSame($expected, $tag->valid()); } - public function provideValidCases() + public function provideValidCases(): array { return [ [true, ' * @param Foo $foo'], diff --git a/tests/DocBlock/TypeExpressionTest.php b/tests/DocBlock/TypeExpressionTest.php index 534ecf26a3d..67030e4e501 100644 --- a/tests/DocBlock/TypeExpressionTest.php +++ b/tests/DocBlock/TypeExpressionTest.php @@ -37,7 +37,7 @@ public function testGetTypes(string $typesExpression, array $expectedTypes): voi static::assertSame($expectedTypes, $expression->getTypes()); } - public function provideGetTypesCases() + public function provideGetTypesCases(): \Generator { yield ['int', ['int']]; yield ['Foo[][]', ['Foo[][]']]; @@ -97,7 +97,7 @@ public function testGetCommonType(string $typesExpression, ?string $expectedComm static::assertSame($expectedCommonType, $expression->getCommonType()); } - public function provideCommonTypeCases() + public function provideCommonTypeCases(): \Generator { $globalNamespace = new NamespaceAnalysis('', '', 0, 999, 0, 999); $appNamespace = new NamespaceAnalysis('App', 'App', 0, 999, 0, 999); @@ -166,7 +166,7 @@ public function testAllowsNull(string $typesExpression, bool $expectNullAllowed) static::assertSame($expectNullAllowed, $expression->allowsNull()); } - public function provideAllowsNullCases() + public function provideAllowsNullCases(): \Generator { yield ['null', true]; yield ['mixed', true]; diff --git a/tests/FileReaderTest.php b/tests/FileReaderTest.php index 1024f485acb..b099fa89e76 100644 --- a/tests/FileReaderTest.php +++ b/tests/FileReaderTest.php @@ -41,7 +41,6 @@ public function testCreateSingleton(): void { $instance = FileReader::createSingleton(); - static::assertInstanceOf(\PhpCsFixer\FileReader::class, $instance); static::assertSame($instance, FileReader::createSingleton()); } diff --git a/tests/Fixer/Alias/ArrayPushFixerTest.php b/tests/Fixer/Alias/ArrayPushFixerTest.php index 690f07cad3e..4c307dce5ee 100644 --- a/tests/Fixer/Alias/ArrayPushFixerTest.php +++ b/tests/Fixer/Alias/ArrayPushFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield 'minimal' => [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'plain' => [ diff --git a/tests/Fixer/Alias/EregToPregFixerTest.php b/tests/Fixer/Alias/EregToPregFixerTest.php index 86c8b01348f..aa721f9a201 100644 --- a/tests/Fixer/Alias/EregToPregFixerTest.php +++ b/tests/Fixer/Alias/EregToPregFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $cases = [ ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $finalCases = []; $defaultSets = [ @@ -103,7 +103,7 @@ public function testFixWithConfiguration(string $expected, ?string $input, array $this->doTest($expected, $input); } - public function provideFixWithConfigurationCases() + public function provideFixWithConfigurationCases(): array { $finalCases = [ '@internal' => [ diff --git a/tests/Fixer/Alias/NoAliasLanguageConstructCallFixerTest.php b/tests/Fixer/Alias/NoAliasLanguageConstructCallFixerTest.php index 410ca8526e8..a18025dc246 100644 --- a/tests/Fixer/Alias/NoAliasLanguageConstructCallFixerTest.php +++ b/tests/Fixer/Alias/NoAliasLanguageConstructCallFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php b/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php index be848a24693..6eebff5ef87 100644 --- a/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php +++ b/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php @@ -38,7 +38,7 @@ public function testFixEchoToPrint(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideEchoToPrintFixCases() + public function provideEchoToPrintFixCases(): array { return [ [ @@ -135,9 +135,9 @@ public function provideEchoToPrintFixCases() ]; } - public static function provideEchoToPrintFixNewCases() + public static function provideEchoToPrintFixNewCases(): \Generator { - foreach (self::getCodeSnippetsToConvertBothWays() as $name => $codeSnippet) { + foreach (self::getCodeSnippetsToConvertBothWays() as $codeSnippet) { yield [ sprintf($codeSnippet, 'print'), sprintf($codeSnippet, 'echo'), @@ -156,7 +156,7 @@ public function testFixPrintToEcho(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function providePrintToEchoFixCases() + public function providePrintToEchoFixCases(): array { return [ [ @@ -274,9 +274,9 @@ function testFunction() { ]; } - public static function providePrintToEchoFixNewCases() + public static function providePrintToEchoFixNewCases(): \Generator { - foreach (self::getCodeSnippetsToConvertBothWays() as $name => $codeSnippet) { + foreach (self::getCodeSnippetsToConvertBothWays() as $codeSnippet) { yield [ sprintf($codeSnippet, 'echo'), sprintf($codeSnippet, 'print'), @@ -302,7 +302,7 @@ public function testWrongConfig(array $wrongConfig, string $expectedMessage): vo $this->fixer->configure($wrongConfig); } - public function provideWrongConfigCases() + public function provideWrongConfigCases(): array { return [ [ @@ -332,7 +332,7 @@ private static function assertCandidateTokenType($expected, AbstractFixer $fixer static::assertSame($expected, $reflectionProperty->getValue($fixer)); } - private static function getCodeSnippetsToConvertBothWays() + private static function getCodeSnippetsToConvertBothWays(): \Generator { yield 'inside of HTML' => '
'; diff --git a/tests/Fixer/Alias/PowToExponentiationFixerTest.php b/tests/Fixer/Alias/PowToExponentiationFixerTest.php index 785c007a25b..936a1353de3 100644 --- a/tests/Fixer/Alias/PowToExponentiationFixerTest.php +++ b/tests/Fixer/Alias/PowToExponentiationFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ [ @@ -242,7 +242,7 @@ public function testNotFix(string $expected): void $this->doTest($expected); } - public function provideNotFixCases() + public function provideNotFixCases(): array { return [ [ @@ -269,7 +269,7 @@ public function testFix73(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ @@ -292,7 +292,7 @@ public function testFix74(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ [ @@ -311,7 +311,7 @@ public function testFix80(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): array { return [ [ diff --git a/tests/Fixer/Alias/RandomApiMigrationFixerTest.php b/tests/Fixer/Alias/RandomApiMigrationFixerTest.php index fc1ffc0ec72..3294990961f 100644 --- a/tests/Fixer/Alias/RandomApiMigrationFixerTest.php +++ b/tests/Fixer/Alias/RandomApiMigrationFixerTest.php @@ -184,7 +184,7 @@ public function testFix73(string $expected, string $input, array $config = []): $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ diff --git a/tests/Fixer/Alias/SetTypeToCastFixerTest.php b/tests/Fixer/Alias/SetTypeToCastFixerTest.php index 180a66fcdd4..2c564362931 100644 --- a/tests/Fixer/Alias/SetTypeToCastFixerTest.php +++ b/tests/Fixer/Alias/SetTypeToCastFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'null cast' => [ @@ -232,7 +232,7 @@ public function testFix73(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ 'null cast' => [ diff --git a/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php b/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php index bd118749cd6..d3a3c729020 100644 --- a/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php +++ b/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php @@ -53,7 +53,7 @@ public function testFixLongSyntax(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideLongSyntaxCases() + public function provideLongSyntaxCases(): array { return [ ['doTest($expected, $input); } - public function provideShortSyntaxCases() + public function provideShortSyntaxCases(): array { return [ ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -104,7 +104,7 @@ public function testFixPhp74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ [ diff --git a/tests/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixerTest.php b/tests/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixerTest.php index 25de8e3d624..d3c76c0efea 100644 --- a/tests/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixerTest.php +++ b/tests/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ [ diff --git a/tests/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixerTest.php b/tests/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixerTest.php index cf55971a9ae..f0743615364 100644 --- a/tests/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixerTest.php +++ b/tests/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ //old style array @@ -150,7 +150,7 @@ public function testFix73(string $expected, ?string $input = null, array $config $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ @@ -181,7 +181,7 @@ public function testFixPhp74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ [ diff --git a/tests/Fixer/ArrayNotation/NormalizeIndexBraceFixerTest.php b/tests/Fixer/ArrayNotation/NormalizeIndexBraceFixerTest.php index fd59510599d..28440e2fdd8 100644 --- a/tests/Fixer/ArrayNotation/NormalizeIndexBraceFixerTest.php +++ b/tests/Fixer/ArrayNotation/NormalizeIndexBraceFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/ArrayNotation/TrimArraySpacesFixerTest.php b/tests/Fixer/ArrayNotation/TrimArraySpacesFixerTest.php index a7e5ba0ea8a..4250fe3323d 100644 --- a/tests/Fixer/ArrayNotation/TrimArraySpacesFixerTest.php +++ b/tests/Fixer/ArrayNotation/TrimArraySpacesFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixerTest.php b/tests/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixerTest.php index 6f4d18b6603..3fb8116697b 100644 --- a/tests/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixerTest.php +++ b/tests/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ //old style array @@ -124,7 +124,7 @@ public function testFixPhp74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ [ diff --git a/tests/Fixer/Basic/EncodingFixerTest.php b/tests/Fixer/Basic/EncodingFixerTest.php index fa454e38a99..0b3bf7df56a 100644 --- a/tests/Fixer/Basic/EncodingFixerTest.php +++ b/tests/Fixer/Basic/EncodingFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null, \SplFileInfo $f $this->doTest($expected, $input, $file); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield $this->prepareTestCase('test-utf8.case1.php', 'test-utf8.case1-bom.php'); @@ -42,7 +42,7 @@ public function provideFixCases() yield ['getTestFile(__DIR__.'/../../Fixtures/FixerTest/encoding/'.$expectedFilename); $inputFile = $inputFilename ? $this->getTestFile(__DIR__.'/../../Fixtures/FixerTest/encoding/'.$inputFilename) : null; diff --git a/tests/Fixer/Basic/NonPrintableCharacterFixerTest.php b/tests/Fixer/Basic/NonPrintableCharacterFixerTest.php index 911950aa555..5cdc794bfcf 100644 --- a/tests/Fixer/Basic/NonPrintableCharacterFixerTest.php +++ b/tests/Fixer/Basic/NonPrintableCharacterFixerTest.php @@ -50,7 +50,7 @@ public function testFixWithoutEscapeSequences(string $expected, ?string $input = $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -119,7 +119,7 @@ public function testFixWithEscapeSequencesInStrings(string $expected, ?string $i $this->doTest($expected, $input); } - public function provideFixWithEscapeSequencesInStringsCases() + public function provideFixWithEscapeSequencesInStringsCases(): array { return [ [ diff --git a/tests/Fixer/Basic/PsrAutoloadingFixerTest.php b/tests/Fixer/Basic/PsrAutoloadingFixerTest.php index 26c2c35a979..9dc7ebc6be7 100644 --- a/tests/Fixer/Basic/PsrAutoloadingFixerTest.php +++ b/tests/Fixer/Basic/PsrAutoloadingFixerTest.php @@ -40,7 +40,7 @@ public function testFixNew(string $expected, ?string $input = null, ?string $dir $this->doTest($expected, $input, $this->getTestFile(__FILE__)); } - public static function provideFixNewCases() + public static function provideFixNewCases(): \Generator { foreach (['class', 'interface', 'trait'] as $element) { yield sprintf('%s with originally short name', $element) => [ @@ -174,7 +174,7 @@ public function testFix(string $expected, ?string $input = null, ?\SplFileInfo $ $this->doTest($expected, $input, $file); } - public function provideFixCases() + public function provideFixCases(): \Generator { $fileProphecy = $this->prophesize(); $fileProphecy->willExtend(\SplFileInfo::class); @@ -363,7 +363,7 @@ class PsrAutoloadingFixer {} ]; } - public function provideIgnoredCases() + public function provideIgnoredCases(): array { $cases = ['.php', 'Foo.class.php', '4Foo.php', '$#.php']; diff --git a/tests/Fixer/Casing/ConstantCaseFixerTest.php b/tests/Fixer/Casing/ConstantCaseFixerTest.php index 10304281a8f..4a42e7173ff 100644 --- a/tests/Fixer/Casing/ConstantCaseFixerTest.php +++ b/tests/Fixer/Casing/ConstantCaseFixerTest.php @@ -44,50 +44,44 @@ public function testFixUpperGeneratedCases(string $expected, ?string $input = nu $this->doTest($expected, $input); } - public function provideLowerGeneratedCases() + public function provideLowerGeneratedCases(): \Generator { - $cases = []; foreach (['true', 'false', 'null'] as $case) { - $cases[] = [ + yield [ sprintf('doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -166,7 +160,7 @@ public function testFix56(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix56Cases() + public function provideFix56Cases(): array { return [ ['doTest($expected, $input); } - public static function provideFix80Cases() + public static function provideFix80Cases(): array { return [ ['False; } }'], diff --git a/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php b/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php index 2360a96ee0c..a5ae2e37bbd 100644 --- a/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php +++ b/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ [ @@ -76,7 +76,7 @@ public function testFix80(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -168,7 +168,7 @@ public function testFix71(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix71Cases() + public function provideFix71Cases(): array { return [ [ diff --git a/tests/Fixer/Casing/MagicConstantCasingFixerTest.php b/tests/Fixer/Casing/MagicConstantCasingFixerTest.php index 7779ec01730..991db2095df 100644 --- a/tests/Fixer/Casing/MagicConstantCasingFixerTest.php +++ b/tests/Fixer/Casing/MagicConstantCasingFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -96,7 +96,7 @@ public function testFix74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ [ diff --git a/tests/Fixer/Casing/MagicMethodCasingFixerTest.php b/tests/Fixer/Casing/MagicMethodCasingFixerTest.php index d2c2f66921c..589519137cf 100644 --- a/tests/Fixer/Casing/MagicMethodCasingFixerTest.php +++ b/tests/Fixer/Casing/MagicMethodCasingFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { $fixerReflection = new \ReflectionClass(MagicMethodCasingFixer::class); $property = $fixerReflection->getProperty('magicNames'); @@ -270,7 +270,7 @@ public function testDoNotFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideDoNotFixCases() + public function provideDoNotFixCases(): array { return [ [ diff --git a/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php b/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php index 4abf419e6af..cd5798a88e5 100644 --- a/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php +++ b/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -176,7 +176,7 @@ public function testFix73(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ diff --git a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php index 634d9c066b7..1239d47366e 100644 --- a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php +++ b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -122,7 +122,7 @@ public function testFix71(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix71Cases() + public function provideFix71Cases(): array { return [ [ @@ -153,7 +153,7 @@ public function testFix72(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix72Cases() + public function provideFix72Cases(): array { return [ [ @@ -172,7 +172,7 @@ public function testFix80(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCastsCases() + public function provideFixCastsCases(): array { return [ [ @@ -120,7 +120,7 @@ public function testFixCastsNoneSpace(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideNoneSpaceFixCases() + public function provideNoneSpaceFixCases(): array { return [ [ diff --git a/tests/Fixer/CastNotation/LowercaseCastFixerTest.php b/tests/Fixer/CastNotation/LowercaseCastFixerTest.php index f3c8cbd4b9b..0ea96fd5a3e 100644 --- a/tests/Fixer/CastNotation/LowercaseCastFixerTest.php +++ b/tests/Fixer/CastNotation/LowercaseCastFixerTest.php @@ -60,7 +60,7 @@ public function testFix74Deprecated(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { $types = ['boolean', 'bool', 'integer', 'int', 'double', 'float', 'float', 'string', 'array', 'object', 'binary']; @@ -75,12 +75,12 @@ public function provideFixCases() } } - public function provideFixDeprecatedCases() + public function provideFixDeprecatedCases(): \Generator { return $this->createCasesFor('real'); } - private function createCasesFor(string $type) + private function createCasesFor(string $type): \Generator { yield [ sprintf('doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { $multiLinePatternToFix = <<<'FIX' doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ diff --git a/tests/Fixer/CastNotation/NoShortBoolCastFixerTest.php b/tests/Fixer/CastNotation/NoShortBoolCastFixerTest.php index c60a4368e14..40118f74c0f 100644 --- a/tests/Fixer/CastNotation/NoShortBoolCastFixerTest.php +++ b/tests/Fixer/CastNotation/NoShortBoolCastFixerTest.php @@ -31,7 +31,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/CastNotation/NoUnsetCastFixerTest.php b/tests/Fixer/CastNotation/NoUnsetCastFixerTest.php index 654c1fc8691..5a73ff98e03 100644 --- a/tests/Fixer/CastNotation/NoUnsetCastFixerTest.php +++ b/tests/Fixer/CastNotation/NoUnsetCastFixerTest.php @@ -32,7 +32,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'simple form I' => [ diff --git a/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php b/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php index 1bff2d470c0..7ebe12e859e 100644 --- a/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php +++ b/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php @@ -60,7 +60,7 @@ public function testFix74Deprecated(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { foreach (['boolean' => 'bool', 'integer' => 'int', 'double' => 'float', 'binary' => 'string'] as $from => $to) { foreach ($this->createCasesFor($from, $to) as $case) { @@ -69,7 +69,7 @@ public function provideFixCases() } } - public function provideFixDeprecatedCases() + public function provideFixDeprecatedCases(): \Generator { return $this->createCasesFor('real', 'float'); } @@ -82,7 +82,7 @@ public function testNoFix(string $expected): void $this->doTest($expected); } - public function provideNoFixCases() + public function provideNoFixCases(): array { $cases = []; $types = ['string', 'array', 'object']; @@ -101,7 +101,7 @@ public function provideNoFixCases() return $cases; } - private function createCasesFor(string $from, string $to) + private function createCasesFor(string $from, string $to): \Generator { yield [ sprintf('doTest($expected, $input); } - public function provideFixClassesCases() + public function provideFixClassesCases(): array { $cases = []; @@ -965,7 +965,7 @@ public function testFixTraits(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixTraitsCases() + public function provideFixTraitsCases(): array { $cases = []; @@ -1059,7 +1059,7 @@ public function testFixInterface(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixInterfaceCases() + public function provideFixInterfaceCases(): array { $cases = []; $cases[] = [ @@ -1144,7 +1144,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ @@ -1167,7 +1167,7 @@ public function testWithConfig(string $expected, string $input, array $config): $this->doTest($expected, $input); } - public function provideConfigCases() + public function provideConfigCases(): array { return [ 'multi line property' => [ @@ -1767,7 +1767,7 @@ public function testFix71(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix71Cases() + public function provideFix71Cases(): array { return [ [ @@ -1813,7 +1813,7 @@ public function testFix74(string $expected, ?string $input = null, array $config $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixPhp80Cases() + public function provideFixPhp80Cases(): \Generator { yield 'attributes' => [ 'configure(['single_line' => 'z']); } - public function provideAnonymousClassesCases() + public function provideAnonymousClassesCases(): array { return [ [ @@ -291,7 +291,7 @@ class# ]; } - public function provideClassesCases() + public function provideClassesCases(): array { return array_merge( $this->provideClassyCases('class'), @@ -300,7 +300,7 @@ public function provideClassesCases() ); } - public function provideClassesWithConfigCases() + public function provideClassesWithConfigCases(): array { return [ [ @@ -350,7 +350,7 @@ public function provideClassesWithConfigCases() ]; } - public function provideInterfacesCases() + public function provideInterfacesCases(): array { $cases = array_merge( $this->provideClassyCases('interface'), @@ -387,7 +387,7 @@ interface Test return $cases; } - public function provideTraitsCases() + public function provideTraitsCases(): array { return $this->provideClassyCases('trait'); } @@ -410,7 +410,7 @@ public function testClassyDefinitionInfo(string $source, array $expected): void static::assertSame($expected, $result); } - public function provideClassyDefinitionInfoCases() + public function provideClassyDefinitionInfoCases(): array { return [ [ @@ -489,7 +489,7 @@ public function testClassyInheritanceInfo(string $source, string $label, array $ $this->doTestClassyInheritanceInfo($source, $label, $expected); } - public function provideClassyImplementsInfoCases() + public function provideClassyImplementsInfoCases(): \Generator { yield from [ '1' => [ @@ -605,7 +605,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -651,7 +651,7 @@ public function testFixPHP73(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function providePHP73Cases() + public function providePHP73Cases(): array { return [ [ @@ -680,7 +680,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ @@ -711,7 +711,7 @@ private function doTestClassyInheritanceInfo(string $source, string $label, arra static::assertSame($expected, $result); } - private function provideClassyCases(string $classy) + private function provideClassyCases(string $classy): array { return [ [ @@ -779,7 +779,7 @@ private function provideClassyCases(string $classy) ]; } - private function provideClassyExtendingCases(string $classy) + private function provideClassyExtendingCases(string $classy): array { return [ [ @@ -809,7 +809,7 @@ private function provideClassyExtendingCases(string $classy) ]; } - private function provideClassyImplementsCases() + private function provideClassyImplementsCases(): array { return [ [ diff --git a/tests/Fixer/ClassNotation/FinalClassFixerTest.php b/tests/Fixer/ClassNotation/FinalClassFixerTest.php index f0517011d19..39eb90d9fff 100644 --- a/tests/Fixer/ClassNotation/FinalClassFixerTest.php +++ b/tests/Fixer/ClassNotation/FinalClassFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $input = $expected = 'doTest($expected, $input); } - public function provideFixWithConfigCases() + public function provideFixWithConfigCases(): array { return [ [ @@ -283,7 +284,7 @@ public function testAnonymousClassesCases(string $expected, ?string $input = nul $this->doTest($expected, $input); } - public function provideAnonymousClassesCases() + public function provideAnonymousClassesCases(): array { return [ [ diff --git a/tests/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixerTest.php b/tests/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixerTest.php index 46293ddcded..22a2ab44ebf 100644 --- a/tests/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixerTest.php +++ b/tests/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $original = $fixed = $this->getClassElementStubs(); $fixed = str_replace('public function f1', 'final public function f1', $fixed); @@ -121,7 +121,7 @@ public function testFix72(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix72Cases() + public function provideFix72Cases(): array { return [ 'constant visibility' => [ diff --git a/tests/Fixer/ClassNotation/NoBlankLinesAfterClassOpeningFixerTest.php b/tests/Fixer/ClassNotation/NoBlankLinesAfterClassOpeningFixerTest.php index b8b44e80d74..3f5f92e51aa 100644 --- a/tests/Fixer/ClassNotation/NoBlankLinesAfterClassOpeningFixerTest.php +++ b/tests/Fixer/ClassNotation/NoBlankLinesAfterClassOpeningFixerTest.php @@ -42,7 +42,7 @@ public function testFixTraits(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $cases = []; @@ -65,6 +65,7 @@ public function firstMethod() } }', ]; + $cases[] = [ 'doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php b/tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php index 1fb6b30148f..68d42b78e10 100644 --- a/tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php +++ b/tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -285,7 +285,7 @@ public function testFixPhp71(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function providePhp71Cases() + public function providePhp71Cases(): array { return [ [ @@ -303,7 +303,7 @@ public function testFix74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixPrePHP80Cases() + public function provideFixPrePHP80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -71,7 +71,7 @@ public function testSimpleClass(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideSimpleCases() + public function provideSimpleCases(): array { return [ [ @@ -1139,7 +1139,7 @@ public function testFixPhp80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp80Cases() + public function provideFixPhp80Cases(): \Generator { yield [ <<<'EOF' diff --git a/tests/Fixer/ClassNotation/NoUnneededFinalMethodFixerTest.php b/tests/Fixer/ClassNotation/NoUnneededFinalMethodFixerTest.php index d7d18b69ec4..3f08cbbf55e 100644 --- a/tests/Fixer/ClassNotation/NoUnneededFinalMethodFixerTest.php +++ b/tests/Fixer/ClassNotation/NoUnneededFinalMethodFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'default' => [ @@ -301,7 +301,7 @@ public function testFixConfig(string $expected, string $input, array $config): v $this->doTest($expected, $input); } - public function provideFixConfigCases() + public function provideFixConfigCases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -374,7 +374,7 @@ public function testFix71(array $configuration, string $expected, ?string $input $this->doTest($expected, $input); } - public function provideFix71Cases() + public function provideFix71Cases(): array { return [ [ @@ -443,7 +443,7 @@ public function testFixWithConfiguration(array $configuration, string $expected, $this->doTest($expected, $input); } - public function provideConfigurationCases() + public function provideConfigurationCases(): array { return [ [ @@ -974,7 +974,7 @@ public function testFixWithSortingAlgorithm(array $configuration, string $expect $this->doTest($expected, $input); } - public function provideSortingConfigurationCases() + public function provideSortingConfigurationCases(): array { return [ [ @@ -1259,7 +1259,7 @@ public function testFix74(string $expected, ?string $input = null, ?array $confi $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixAlphaCases() + public function provideFixAlphaCases(): array { return [ 'single' => [ @@ -128,7 +128,7 @@ public function testFixAlphaDescend(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixAlphaDescendCases() + public function provideFixAlphaDescendCases(): array { return [ 'single' => [ @@ -154,7 +154,7 @@ public function testFixLength(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixLengthCases() + public function provideFixLengthCases(): array { return [ 'single' => [ @@ -197,7 +197,7 @@ public function testFixLengthDescend(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideFixLengthDescendCases() + public function provideFixLengthDescendCases(): array { return [ 'single' => [ diff --git a/tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php b/tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php index 689ab6ada48..ebd711dea38 100644 --- a/tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php +++ b/tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $attributesAndMethodsOriginal = $this->getAttributesAndMethods(true); $attributesAndMethodsFixed = $this->getAttributesAndMethods(false); @@ -127,7 +127,7 @@ public function test74Fix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -170,7 +170,7 @@ public function testFix71(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix71Cases() + public function provideFix71Cases(): array { return [ [ @@ -193,7 +193,7 @@ public function testFixPhp80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp80Cases() + public function provideFixPhp80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'simple' => [ diff --git a/tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php b/tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php index 6c69a70fc75..29a2c231a20 100644 --- a/tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php +++ b/tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -635,7 +635,7 @@ class Foo $this->doTest($expected, $input); } - public function provideConfigurationCases() + public function provideConfigurationCases(): array { return [ [ @@ -698,7 +698,7 @@ public function testPHP71(string $expected, string $input): void $this->doTest($expected, $input); } - public function providePHP71Cases() + public function providePHP71Cases(): array { return [ [ @@ -733,7 +733,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ @@ -798,7 +798,7 @@ public function testFix74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFix74Cases() + public function provideTestFix74Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'simple' => [ diff --git a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php index 300a5927a92..aa7d927bc51 100644 --- a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php +++ b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php @@ -541,7 +541,7 @@ public function testFixClassConst(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFixClassConstCases() + public function provideFixClassConstCases(): array { return [ [ @@ -746,7 +746,7 @@ public function testFix74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield ['DateTime();']; yield ['date_create();']; diff --git a/tests/Fixer/Comment/CommentToPhpdocFixerTest.php b/tests/Fixer/Comment/CommentToPhpdocFixerTest.php index b835be48be5..6ad3eb1906f 100644 --- a/tests/Fixer/Comment/CommentToPhpdocFixerTest.php +++ b/tests/Fixer/Comment/CommentToPhpdocFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideTestCases() + public function provideTestCases(): array { return [ [ diff --git a/tests/Fixer/Comment/HeaderCommentFixerTest.php b/tests/Fixer/Comment/HeaderCommentFixerTest.php index 885e64d36ae..93ad9bf8310 100644 --- a/tests/Fixer/Comment/HeaderCommentFixerTest.php +++ b/tests/Fixer/Comment/HeaderCommentFixerTest.php @@ -36,7 +36,7 @@ public function testFix(array $configuration, string $expected, string $input): $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -577,7 +577,7 @@ public function testMisconfiguration(?array $configuration, string $exceptionMes $this->fixer->configure($configuration); } - public function provideMisconfigurationCases() + public function provideMisconfigurationCases(): array { return [ [[], 'Missing required configuration: The required option "header" is missing.'], @@ -636,7 +636,7 @@ public function testHeaderGeneration(string $expected, string $header, string $t ); } - public function provideHeaderGenerationCases() + public function provideHeaderGenerationCases(): array { return [ [ @@ -668,7 +668,7 @@ public function testDoNotTouch(string $expected): void $this->doTest($expected); } - public function provideDoNotTouchCases() + public function provideDoNotTouchCases(): array { return [ ["\ndoTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/Comment/MultilineCommentOpeningClosingFixerTest.php b/tests/Fixer/Comment/MultilineCommentOpeningClosingFixerTest.php index e6e9023d240..dccc45dedad 100644 --- a/tests/Fixer/Comment/MultilineCommentOpeningClosingFixerTest.php +++ b/tests/Fixer/Comment/MultilineCommentOpeningClosingFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ // fix cases @@ -274,7 +274,7 @@ public function testGetCommentBlock(string $source, int $startIndex, int $endInd static::assertSame($isEmpty, $foundIsEmpty, 'Is empty comment block detection failed.'); } - public function provideCommentBlockCases() + public function provideCommentBlockCases(): array { $cases = [ [ diff --git a/tests/Fixer/Comment/NoTrailingWhitespaceInCommentFixerTest.php b/tests/Fixer/Comment/NoTrailingWhitespaceInCommentFixerTest.php index cb5877890ec..25a34852b1a 100644 --- a/tests/Fixer/Comment/NoTrailingWhitespaceInCommentFixerTest.php +++ b/tests/Fixer/Comment/NoTrailingWhitespaceInCommentFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Comment/SingleLineCommentStyleFixerTest.php b/tests/Fixer/Comment/SingleLineCommentStyleFixerTest.php index 7cd244193cf..2b6b1c5c6d3 100644 --- a/tests/Fixer/Comment/SingleLineCommentStyleFixerTest.php +++ b/tests/Fixer/Comment/SingleLineCommentStyleFixerTest.php @@ -42,7 +42,7 @@ public function testAsterisk(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideAsteriskCases() + public function provideAsteriskCases(): array { return [ [ @@ -225,7 +225,7 @@ public function testHashCases(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideHashCases() + public function provideHashCases(): array { return [ [ @@ -294,7 +294,7 @@ public function testAllCases(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideAllCases() + public function provideAllCases(): array { return [ [ diff --git a/tests/Fixer/ControlStructure/ElseifFixerTest.php b/tests/Fixer/ControlStructure/ElseifFixerTest.php index 47f81fa139c..c7b6aaebf26 100644 --- a/tests/Fixer/ControlStructure/ElseifFixerTest.php +++ b/tests/Fixer/ControlStructure/ElseifFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ [' [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $template = 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php index 2450cd4953c..ea315d75d21 100644 --- a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php +++ b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php @@ -45,7 +45,7 @@ public function testFixWithExplicitDefaultConfiguration(string $expected, ?strin $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -995,7 +995,7 @@ public function testFixWithDifferentCommentText(string $expected, ?string $input $this->doTest($expected, $input); } - public function provideTestFixWithDifferentCommentTextCases() + public function provideTestFixWithDifferentCommentTextCases(): array { $cases = $this->provideFixCases(); @@ -1054,19 +1054,17 @@ public function testFixWithDifferentLineEnding(string $expected, ?string $input $this->doTest($expected, $input); } - public function provideTestFixWithDifferentLineEndingCases() + public function provideTestFixWithDifferentLineEndingCases(): \Generator { - $cases = []; foreach ($this->provideFixCases() as $case) { $case[0] = str_replace("\n", "\r\n", $case[0]); + if (isset($case[1])) { $case[1] = str_replace("\n", "\r\n", $case[1]); } - $cases[] = $case; + yield $case; } - - return $cases; } public function testFixWithCommentTextWithSpecialRegexpCharacters(): void @@ -1138,7 +1136,7 @@ public function testFixWithCommentTextContainingNewLines(string $text): void ]); } - public function provideFixWithCommentTextContainingNewLinesCases() + public function provideFixWithCommentTextContainingNewLinesCases(): array { return [ ["No\nbreak"], @@ -1164,7 +1162,7 @@ public function testFix80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -271,7 +271,7 @@ public function testFix80(string $expected): void $this->doTest($expected); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php b/tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php index cfe293a68c0..4bf04e45612 100644 --- a/tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php +++ b/tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php @@ -51,7 +51,7 @@ public function testFix(string $expected, ?string $input = null, ?string $fixSta $this->fixerTest($expected, $input, $fixStatement); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -437,7 +437,7 @@ public function testFixYieldFrom(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixYieldFromCases() + public function provideFixYieldFromCases(): array { return [ [ diff --git a/tests/Fixer/ControlStructure/NoUnneededCurlyBracesFixerTest.php b/tests/Fixer/ControlStructure/NoUnneededCurlyBracesFixerTest.php index ee663bb80de..701f2bdc9eb 100644 --- a/tests/Fixer/ControlStructure/NoUnneededCurlyBracesFixerTest.php +++ b/tests/Fixer/ControlStructure/NoUnneededCurlyBracesFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ 'simple sample, last token candidate' => [ @@ -133,7 +133,7 @@ public function testNoFix7(string $expected): void $this->doTest($expected); } - public function provideNoFix7Cases() + public function provideNoFix7Cases(): array { return [ [ @@ -162,7 +162,7 @@ public function testFixNamespace(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixNamespaceCases() + public function provideFixNamespaceCases(): \Generator { yield [ 'doTest($expected, $input); } - public function providePHPCloseTagCases() + public function providePHPCloseTagCases(): array { return [ [ @@ -135,7 +135,7 @@ public function testFixIfElseIfElse(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixIfElseIfElseCases() + public function provideFixIfElseIfElseCases(): array { $expected = 'doTest($expected, $input); } - public function provideFixIfElseCases() + public function provideFixIfElseCases(): \Generator { $expected = 'doTest($expected, $input); } - public function provideFixNestedIfCases() + public function provideFixNestedIfCases(): array { return [ [ @@ -355,7 +355,7 @@ public function testFixEmptyElse(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixEmptyElseCases() + public function provideFixEmptyElseCases(): array { return [ [ @@ -447,7 +447,7 @@ public function testNegativeCases(string $expected): void $this->doTest($expected); } - public function provideNegativeCases() + public function provideNegativeCases(): \Generator { yield from [ [ @@ -652,7 +652,7 @@ public function testBlockDetection(array $expected, string $source, int $index): static::assertSame($expected, $result); } - public function provideBlockDetectionCases() + public function provideBlockDetectionCases(): array { $cases = []; @@ -700,7 +700,7 @@ public function testConditionsWithoutBraces(string $expected, ?string $input = n $this->doTest($expected, $input); } - public function provideConditionsWithoutBracesCases() + public function provideConditionsWithoutBracesCases(): array { $cases = []; $statements = [ @@ -810,7 +810,7 @@ public function testIsInConditionWithoutBraces(array $indexes, string $input): v } } - public function provideIsInConditionWithoutBracesCases() + public function provideIsInConditionWithoutBracesCases(): array { return [ [ diff --git a/tests/Fixer/ControlStructure/SimplifiedIfReturnFixerTest.php b/tests/Fixer/ControlStructure/SimplifiedIfReturnFixerTest.php index 0ad16ba04a7..5c76576b0e4 100644 --- a/tests/Fixer/ControlStructure/SimplifiedIfReturnFixerTest.php +++ b/tests/Fixer/ControlStructure/SimplifiedIfReturnFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'simple' => [ diff --git a/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php b/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php index 0d45f2cf299..93d2aed1e2f 100644 --- a/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php +++ b/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ [ @@ -264,7 +264,7 @@ public function testFix80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): array { return [ 'Simple match' => [ diff --git a/tests/Fixer/ControlStructure/SwitchCaseSpaceFixerTest.php b/tests/Fixer/ControlStructure/SwitchCaseSpaceFixerTest.php index f1bff946012..3efd9e46676 100644 --- a/tests/Fixer/ControlStructure/SwitchCaseSpaceFixerTest.php +++ b/tests/Fixer/ControlStructure/SwitchCaseSpaceFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ [ diff --git a/tests/Fixer/ControlStructure/SwitchContinueToBreakFixerTest.php b/tests/Fixer/ControlStructure/SwitchContinueToBreakFixerTest.php index f6cde0a9ea5..da36b1e622d 100644 --- a/tests/Fixer/ControlStructure/SwitchContinueToBreakFixerTest.php +++ b/tests/Fixer/ControlStructure/SwitchContinueToBreakFixerTest.php @@ -31,7 +31,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): \Generator { yield from [ 'alternative syntax |' => [ @@ -503,7 +503,7 @@ public function testFix74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ 'numeric literal separator' => [ diff --git a/tests/Fixer/ControlStructure/TrailingCommaInMultilineFixerTest.php b/tests/Fixer/ControlStructure/TrailingCommaInMultilineFixerTest.php index b14f284073b..1597f6f7c72 100644 --- a/tests/Fixer/ControlStructure/TrailingCommaInMultilineFixerTest.php +++ b/tests/Fixer/ControlStructure/TrailingCommaInMultilineFixerTest.php @@ -43,7 +43,7 @@ public function testInvalidConfiguration($exceptionMessega, $configuration): voi $this->fixer->configure($configuration); } - public static function provideInvalidConfigurationCases() + public static function provideInvalidConfigurationCases(): \Generator { if (\PHP_VERSION_ID < 70300) { yield [ @@ -71,7 +71,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public static function provideFixCases() + public static function provideFixCases(): array { return [ // long syntax tests @@ -410,7 +410,7 @@ public function testFix73(string $expected, ?string $input = null, array $config $this->doTest($expected, $input); } - public static function provideFix73Cases() + public static function provideFix73Cases(): array { return [ [ @@ -573,7 +573,7 @@ public function testFix80(string $expected, ?string $input = null, array $config $this->doTest($expected, $input); } - public static function provideFix80Cases() + public static function provideFix80Cases(): array { return [ [ diff --git a/tests/Fixer/ControlStructure/YodaStyleFixerTest.php b/tests/Fixer/ControlStructure/YodaStyleFixerTest.php index 5d171b3cbd2..bb929f2c713 100644 --- a/tests/Fixer/ControlStructure/YodaStyleFixerTest.php +++ b/tests/Fixer/ControlStructure/YodaStyleFixerTest.php @@ -51,7 +51,7 @@ public function testFixInverse(string $expected, ?string $input = null, array $e } } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ [ @@ -732,7 +732,7 @@ public function testFixLessGreaterInverse(string $expected, string $input): void $this->doTest($input, $expected); } - public function provideLessGreaterCases() + public function provideLessGreaterCases(): array { return [ [ @@ -823,7 +823,7 @@ public function testPHP71CasesInverse(string $expected, ?string $input = null): } } - public function providePHP71Cases() + public function providePHP71Cases(): array { return [ // no fix cases @@ -876,7 +876,7 @@ public function testWithConfig(array $config, string $expected): void $this->doTest($expected); } - public function provideFixWithConfigCases() + public function provideFixWithConfigCases(): array { return [ [ @@ -916,7 +916,7 @@ public function testFixPhp74(string $expected, ?string $input): void $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function providePHP74Cases() + public function providePHP74Cases(): array { return [ [ @@ -966,7 +966,7 @@ public function testFixPrePHP80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPrePHP80Cases() + public function provideFixPrePHP80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'testFixWithSpaceBeforeArgumentAssignmentOnly($expected, $input); } - public function provideFixWithSpaceBeforeArgumentAssignmentOnlyCases() + public function provideFixWithSpaceBeforeArgumentAssignmentOnlyCases(): array { return $this->createTestCases([ [' @@ -940,7 +940,7 @@ public function testFixWithoutSpaceBeforeArgumentAssignmentOnlyWithDifferentLine $this->testFixWithoutSpaceBeforeArgumentAssignmentOnly($expected, $input); } - public function provideFixWithoutSpaceBeforeArgumentAssignmentOnlyCases() + public function provideFixWithoutSpaceBeforeArgumentAssignmentOnlyCases(): array { return $this->createTestCases([ [' @@ -988,7 +988,7 @@ public function testFixWithSpaceAfterArgumentAssignmentOnlyWithDifferentLineEndi $this->testFixWithSpaceAfterArgumentAssignmentOnly($expected, $input); } - public function provideFixWithSpaceAfterArgumentAssignmentOnlyCases() + public function provideFixWithSpaceAfterArgumentAssignmentOnlyCases(): array { return $this->createTestCases([ [' @@ -1036,7 +1036,7 @@ public function testFixWithoutSpaceAfterArgumentAssignmentOnlyWithDifferentLineE $this->testFixWithoutSpaceAfterArgumentAssignmentOnly($expected, $input); } - public function provideFixWithoutSpaceAfterArgumentAssignmentOnlyCases() + public function provideFixWithoutSpaceAfterArgumentAssignmentOnlyCases(): array { return $this->createTestCases([ [' @@ -1084,7 +1084,7 @@ public function testFixWithSpaceBeforeArrayAssignmentEqualOnlyWithDifferentLineE $this->testFixWithSpaceBeforeArrayAssignmentEqualOnly($expected, $input); } - public function provideFixWithSpaceBeforeArrayAssignmentEqualOnlyCases() + public function provideFixWithSpaceBeforeArrayAssignmentEqualOnlyCases(): array { return $this->createTestCases([ [' @@ -1132,7 +1132,7 @@ public function testFixWithoutSpaceBeforeArrayAssignmentEqualOnlyWithDifferentLi $this->testFixWithoutSpaceBeforeArrayAssignmentEqualOnly($expected, $input); } - public function provideFixWithoutSpaceBeforeArrayAssignmentEqualOnlyCases() + public function provideFixWithoutSpaceBeforeArrayAssignmentEqualOnlyCases(): array { return $this->createTestCases([ [' @@ -1180,7 +1180,7 @@ public function testFixWithSpaceAfterArrayAssignmentEqualOnlyWithDifferentLineEn $this->testFixWithSpaceAfterArrayAssignmentEqualOnly($expected, $input); } - public function provideFixWithSpaceAfterArrayAssignmentEqualOnlyCases() + public function provideFixWithSpaceAfterArrayAssignmentEqualOnlyCases(): array { return $this->createTestCases([ [' @@ -1228,7 +1228,7 @@ public function testFixWithoutSpaceAfterArrayAssignmentEqualOnlyWithDifferentLin $this->testFixWithoutSpaceAfterArrayAssignmentEqualOnly($expected, $input); } - public function provideFixWithoutSpaceAfterArrayAssignmentEqualOnlyCases() + public function provideFixWithoutSpaceAfterArrayAssignmentEqualOnlyCases(): array { return $this->createTestCases([ [' @@ -1276,7 +1276,7 @@ public function testFixWithSpaceBeforeArrayAssignmentColonOnlyWithDifferentLineE $this->testFixWithSpaceBeforeArrayAssignmentColonOnly($expected, $input); } - public function provideFixWithSpaceBeforeArrayAssignmentColonOnlyCases() + public function provideFixWithSpaceBeforeArrayAssignmentColonOnlyCases(): array { return $this->createTestCases([ [' @@ -1324,7 +1324,7 @@ public function testFixWithoutSpaceBeforeArrayAssignmentColonOnlyWithDifferentLi $this->testFixWithoutSpaceBeforeArrayAssignmentColonOnly($expected, $input); } - public function provideFixWithoutSpaceBeforeArrayAssignmentColonOnlyCases() + public function provideFixWithoutSpaceBeforeArrayAssignmentColonOnlyCases(): array { return $this->createTestCases([ [' @@ -1372,7 +1372,7 @@ public function testFixWithSpaceAfterArrayAssignmentColonOnlyWithDifferentLineEn $this->testFixWithSpaceAfterArrayAssignmentColonOnly($expected, $input); } - public function provideFixWithSpaceAfterArrayAssignmentColonOnlyCases() + public function provideFixWithSpaceAfterArrayAssignmentColonOnlyCases(): array { return $this->createTestCases([ [' @@ -1420,7 +1420,7 @@ public function testFixWithoutSpaceAfterArrayAssignmentColonOnlyWithDifferentLin $this->testFixWithoutSpaceAfterArrayAssignmentColonOnly($expected, $input); } - public function provideFixWithoutSpaceAfterArrayAssignmentColonOnlyCases() + public function provideFixWithoutSpaceAfterArrayAssignmentColonOnlyCases(): array { return $this->createTestCases([ [' @@ -1465,7 +1465,7 @@ class Foo ); } - public static function provideElementDiscoveringCases() + public static function provideElementDiscoveringCases(): \Generator { yield ['private $foo;']; yield ['private string $foo;']; diff --git a/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php b/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php index 49d28c87946..f4d5136dba8 100644 --- a/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php +++ b/tests/Fixer/FunctionNotation/CombineNestedDirnameFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -113,7 +113,7 @@ public function testFix73(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ diff --git a/tests/Fixer/FunctionNotation/FopenFlagOrderFixerTest.php b/tests/Fixer/FunctionNotation/FopenFlagOrderFixerTest.php index a5f23cf6dc7..d0701baf194 100644 --- a/tests/Fixer/FunctionNotation/FopenFlagOrderFixerTest.php +++ b/tests/Fixer/FunctionNotation/FopenFlagOrderFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'most simple fix case' => [ diff --git a/tests/Fixer/FunctionNotation/FopenFlagsFixerTest.php b/tests/Fixer/FunctionNotation/FopenFlagsFixerTest.php index b980ed4e46f..b1ce62185c1 100644 --- a/tests/Fixer/FunctionNotation/FopenFlagsFixerTest.php +++ b/tests/Fixer/FunctionNotation/FopenFlagsFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, string $input, array $config = []): vo $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'missing "b"' => [ @@ -111,7 +111,7 @@ public function testDoNotFix(string $expected): void $this->doTest($expected); } - public function provideDoNotFixCases() + public function provideDoNotFixCases(): array { return [ 'not simple flags' => [ diff --git a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php index b6e3482e178..fab4ba1b1c2 100644 --- a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php +++ b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php @@ -49,7 +49,7 @@ public function testFix(string $expected, ?string $input = null, array $configur $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -374,7 +374,7 @@ public function test74(string $expected, ?string $input = null, array $configura $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ [ @@ -446,7 +446,7 @@ public function testFixPhp80(string $expected, ?string $input = null, array $con $this->doTest($expected, $input); } - public function provideFixPhp80Cases() + public function provideFixPhp80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -197,7 +197,7 @@ public function testFix74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ [ @@ -255,7 +255,7 @@ public function testFix80(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield ["doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'simple' => [ @@ -124,7 +124,7 @@ public function testDoNotFix(string $expected): void $this->doTest($expected); } - public function provideDoNotFixCases() + public function provideDoNotFixCases(): \Generator { yield from [ 'reference' => [ @@ -201,7 +201,7 @@ public function testFix80(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield 'simple' => [ 'doTest($expected, $input); } - public function provideFix56Cases() + public function provideFix56Cases(): array { return [ [ @@ -871,7 +871,7 @@ public function testFix73(string $expected, ?string $input = null, array $config $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ @@ -943,7 +943,7 @@ public function testFix74(string $expected, ?string $input = null, array $config $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ [ diff --git a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php index 1dd399cf9e9..a0381576592 100644 --- a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php +++ b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php @@ -99,7 +99,7 @@ public function testConfigureIncludeSets( } } - public function provideConfigureIncludeSetsCases() + public function provideConfigureIncludeSetsCases(): array { return [ [['foo', 'bar']], @@ -302,7 +302,7 @@ public function testFixWithNamespaceConfiguration(string $expected, ?string $inp $this->doTest($expected, $input); } - public function provideFixWithNamespaceConfigurationCases() + public function provideFixWithNamespaceConfigurationCases(): array { return [ [ @@ -471,7 +471,7 @@ public function testFixWithConfiguredInclude(string $expected, ?string $input = $this->doTest($expected, $input); } - public function provideFixWithConfiguredIncludeCases() + public function provideFixWithConfiguredIncludeCases(): \Generator { yield from [ 'include set + 1, exclude 1' => [ diff --git a/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php b/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php index e87cab73a12..883d86d1d12 100644 --- a/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php +++ b/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ 'test function call' => [ diff --git a/tests/Fixer/FunctionNotation/NoUselessSprintfFixerTest.php b/tests/Fixer/FunctionNotation/NoUselessSprintfFixerTest.php index 14605085cd3..fa664d51a9a 100644 --- a/tests/Fixer/FunctionNotation/NoUselessSprintfFixerTest.php +++ b/tests/Fixer/FunctionNotation/NoUselessSprintfFixerTest.php @@ -31,7 +31,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield 'simple' => [ 'doTest($expected); } - public function provideDoNotFixCases() + public function provideDoNotFixCases(): \Generator { yield ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): \Generator { yield [ ' null;', @@ -417,7 +417,7 @@ public function testFixInverse80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield 'trailing comma' => [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'typehint already defined' => [ diff --git a/tests/Fixer/FunctionNotation/PhpdocToPropertyTypeFixerTest.php b/tests/Fixer/FunctionNotation/PhpdocToPropertyTypeFixerTest.php index b0390d96da6..61e5f6fee04 100644 --- a/tests/Fixer/FunctionNotation/PhpdocToPropertyTypeFixerTest.php +++ b/tests/Fixer/FunctionNotation/PhpdocToPropertyTypeFixerTest.php @@ -38,7 +38,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'no phpdoc return' => [ diff --git a/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php b/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php index 9b12a77fb48..c6be7e5072d 100644 --- a/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php +++ b/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php @@ -46,7 +46,7 @@ public function testFix(string $expected, ?string $input = null, ?int $versionSp $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ 'no phpdoc return' => [ @@ -363,7 +363,7 @@ public function testFixPhp74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ 'arrow function' => [ @@ -383,7 +383,7 @@ public function testFixPhp80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp80Cases() + public function provideFixPhp80Cases(): \Generator { yield 'static' => [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield 'call by name - list' => [ 'doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixWithSpaceBeforeNoneCases() + public function provideFixWithSpaceBeforeNoneCases(): array { return [ [ @@ -123,7 +123,7 @@ public function testFixWithSpaceBeforeOne(string $expected, ?string $input = nul $this->doTest($expected, $input); } - public function provideFixWithSpaceBeforeOneCases() + public function provideFixWithSpaceBeforeOneCases(): array { return [ [ @@ -156,7 +156,7 @@ public function testFixWithDefaultConfigurationPhp74(string $expected, ?string $ $this->doTest($expected, $input); } - public function provideFixWithSpaceBeforeNonePhp74Cases() + public function provideFixWithSpaceBeforeNonePhp74Cases(): array { return [ [ @@ -175,7 +175,7 @@ public function testFix80(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'sample' => [ @@ -67,7 +67,7 @@ public function testDoNotFix(string $expected): void $this->doTest($expected); } - public function provideDoNotFixCases() + public function provideDoNotFixCases(): array { return [ [ @@ -249,7 +249,7 @@ public function testFixPhp74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ [ diff --git a/tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php b/tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php index d1e3d6c1603..197158497fe 100644 --- a/tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php +++ b/tests/Fixer/FunctionNotation/UseArrowFunctionsFixerTest.php @@ -42,7 +42,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/FunctionNotation/VoidReturnFixerTest.php b/tests/Fixer/FunctionNotation/VoidReturnFixerTest.php index 95acfc7c267..a0e10cb5a42 100644 --- a/tests/Fixer/FunctionNotation/VoidReturnFixerTest.php +++ b/tests/Fixer/FunctionNotation/VoidReturnFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ [ diff --git a/tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php b/tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php index 12e789d2687..942d5ed611d 100644 --- a/tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php +++ b/tests/Fixer/Import/FullyQualifiedStrictTypesFixerTest.php @@ -51,7 +51,7 @@ public function testCodeWithoutReturnTypes(string $expected, ?string $input = nu $this->doTest($expected, $input); } - public function provideCodeWithReturnTypesCases() + public function provideCodeWithReturnTypesCases(): array { return [ 'Import common strict types' => [ @@ -236,7 +236,7 @@ public function doSomething(\Foo\Bar $foo, array $bar): \Foo\Bar\Baz ]; } - public function provideCodeWithoutReturnTypesCases() + public function provideCodeWithoutReturnTypesCases(): array { return [ 'Import common strict types' => [ @@ -438,7 +438,7 @@ function withReference(\Exception &$e) {}', ]; } - public function provideCodeWithReturnTypesCasesWithNullableCases() + public function provideCodeWithReturnTypesCasesWithNullableCases(): array { return [ 'Test namespace fixes with nullable types' => [ diff --git a/tests/Fixer/Import/GlobalNamespaceImportFixerTest.php b/tests/Fixer/Import/GlobalNamespaceImportFixerTest.php index c608183c0da..df2a49f3f85 100644 --- a/tests/Fixer/Import/GlobalNamespaceImportFixerTest.php +++ b/tests/Fixer/Import/GlobalNamespaceImportFixerTest.php @@ -34,7 +34,7 @@ public function testFixImportConstants(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideFixImportConstantsCases() + public function provideFixImportConstantsCases(): array { return [ 'non-global names' => [ @@ -235,7 +235,7 @@ public function testFixImportFunctions(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideFixImportFunctionsCases() + public function provideFixImportFunctionsCases(): array { return [ 'non-global names' => [ @@ -439,7 +439,7 @@ public function testFixImportClasses(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideFixImportClassesCases() + public function provideFixImportClassesCases(): array { return [ 'non-global names' => [ @@ -708,7 +708,7 @@ public function testFixImportClasses71(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideFixImportClasses71Cases() + public function provideFixImportClasses71Cases(): array { return [ 'handle typehints' => [ @@ -742,7 +742,7 @@ public function testFixFullyQualifyConstants(string $expected, ?string $input = $this->doTest($expected, $input); } - public function provideFixFullyQualifyConstantsCases() + public function provideFixFullyQualifyConstantsCases(): array { return [ 'already fqn or sub namespace' => [ @@ -801,7 +801,7 @@ public function testFixFullyQualifyFunctions(string $expected, ?string $input = $this->doTest($expected, $input); } - public function provideFixFullyQualifyFunctionsCases() + public function provideFixFullyQualifyFunctionsCases(): array { return [ 'already fqn or sub namespace' => [ @@ -867,7 +867,7 @@ public function testFixFullyQualifyClasses(string $expected, ?string $input = nu $this->doTest($expected, $input); } - public function provideFixFullyQualifyClassesCases() + public function provideFixFullyQualifyClassesCases(): array { return [ 'already fqn or sub namespace' => [ @@ -956,7 +956,7 @@ public function testMultipleNamespaces(string $expected): void $this->doTest($expected); } - public function provideMultipleNamespacesCases() + public function provideMultipleNamespacesCases(): \Generator { yield [ <<<'INPUT' diff --git a/tests/Fixer/Import/GroupImportFixerTest.php b/tests/Fixer/Import/GroupImportFixerTest.php index 8d8e9812d9f..8e116cbd6f0 100644 --- a/tests/Fixer/Import/GroupImportFixerTest.php +++ b/tests/Fixer/Import/GroupImportFixerTest.php @@ -50,7 +50,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -194,7 +194,7 @@ public function testFix72(string $expected, string $input = null): void $this->doTest($expected, $input); } - public function provideFix72Cases() + public function provideFix72Cases(): array { return [ [ @@ -230,7 +230,7 @@ public function testFixPrePHP80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPrePHP80Cases() + public function provideFixPrePHP80Cases(): \Generator { yield [ 'fixer->configure($configuration); } - public function provideInvalidSortAlgorithmCases() + public function provideInvalidSortAlgorithmCases(): array { return [ [ @@ -1639,7 +1639,7 @@ public function testFixByLength(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixByLengthCases() + public function provideFixByLengthCases(): array { return [ [ @@ -1785,7 +1785,7 @@ public function testFixTypesOrderAndLength(string $expected, ?string $input = nu $this->doTest($expected, $input); } - public function provideFixTypesOrderAndLengthCases() + public function provideFixTypesOrderAndLengthCases(): array { return [ [ @@ -1910,7 +1910,7 @@ public function testFixTypesOrderAndNone(string $expected, ?string $input = null $this->doTest($expected, $input); } - public function provideFixTypesOrderAndNoneCases() + public function provideFixTypesOrderAndNoneCases(): array { return [ [ @@ -1974,7 +1974,7 @@ public function testFix72(string $expected, ?string $input = null, array $config $this->doTest($expected, $input); } - public function provideFix72Cases() + public function provideFix72Cases(): array { $input = 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -291,7 +291,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ @@ -310,7 +310,7 @@ public function testFix72(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix72Cases() + public function provideFix72Cases(): array { return [ [ diff --git a/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php b/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php index 23d4e4e4d31..84f54e40ce7 100644 --- a/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php +++ b/tests/Fixer/Import/SingleLineAfterImportsFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -438,7 +438,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ @@ -461,7 +461,7 @@ public function testFix72(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix72Cases() + public function provideFix72Cases(): array { $imports = [ 'some\a\{ClassA, ClassB, ClassC as C,};', diff --git a/tests/Fixer/LanguageConstruct/ClassKeywordRemoveFixerTest.php b/tests/Fixer/LanguageConstruct/ClassKeywordRemoveFixerTest.php index 50cbdb925b3..acdac03e663 100644 --- a/tests/Fixer/LanguageConstruct/ClassKeywordRemoveFixerTest.php +++ b/tests/Fixer/LanguageConstruct/ClassKeywordRemoveFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixerTest.php b/tests/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixerTest.php index 8488c080dd9..58fe30fe13b 100644 --- a/tests/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixerTest.php +++ b/tests/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php b/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php index d381afd2a58..08bb4ef5ead 100644 --- a/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php +++ b/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ [ diff --git a/tests/Fixer/LanguageConstruct/DeclareEqualNormalizeFixerTest.php b/tests/Fixer/LanguageConstruct/DeclareEqualNormalizeFixerTest.php index a54146830e2..1c3ca84c4b4 100644 --- a/tests/Fixer/LanguageConstruct/DeclareEqualNormalizeFixerTest.php +++ b/tests/Fixer/LanguageConstruct/DeclareEqualNormalizeFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input, array $config): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'minimal case remove whitespace (default config)' => [ @@ -101,7 +101,7 @@ public function testInvalidConfig(array $config, string $expectedMessage): void $this->fixer->configure($config); } - public function provideInvalidConfigCases() + public function provideInvalidConfigCases(): array { return [ [ diff --git a/tests/Fixer/LanguageConstruct/DeclareParenthesesFixerTest.php b/tests/Fixer/LanguageConstruct/DeclareParenthesesFixerTest.php index caf3802695b..a6194a6ae11 100644 --- a/tests/Fixer/LanguageConstruct/DeclareParenthesesFixerTest.php +++ b/tests/Fixer/LanguageConstruct/DeclareParenthesesFixerTest.php @@ -31,7 +31,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield 'spaces around parentheses' => [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $multiLinePatternToFix = <<<'FIX' doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ diff --git a/tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php b/tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php index f0845feb6ad..7ccee41120f 100644 --- a/tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php +++ b/tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php @@ -37,7 +37,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ [ diff --git a/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php b/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php index c7177446a51..b7b0fd89117 100644 --- a/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php +++ b/tests/Fixer/LanguageConstruct/ExplicitIndirectVariableFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ [ @@ -81,7 +81,7 @@ public function testFix80($expected, $input): void $this->doTest($expected, $input); } - public function provideTestFix80Cases() + public function provideTestFix80Cases(): array { return [ [ diff --git a/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php b/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php index 2d64b320a01..bf49eb6a684 100644 --- a/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php +++ b/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideTestCases() + public function provideTestCases(): array { return [ 'Minimal case, alternative casing, alternative statement end.' => [ @@ -254,7 +254,7 @@ public function testInvalidConfigurationKeys(array $config): void $this->fixer->configure($config); } - public function provideInvalidConfigurationKeysCases() + public function provideInvalidConfigurationKeysCases(): array { return [ [['functions' => ['a']]], diff --git a/tests/Fixer/LanguageConstruct/IsNullFixerTest.php b/tests/Fixer/LanguageConstruct/IsNullFixerTest.php index 2057d71ad47..5422ffa8eb2 100644 --- a/tests/Fixer/LanguageConstruct/IsNullFixerTest.php +++ b/tests/Fixer/LanguageConstruct/IsNullFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $multiLinePatternToFix = <<<'FIX' doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ diff --git a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php index a775b65b785..d61c903d83b 100644 --- a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php +++ b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ 'It replaces an unset on a property with = null' => [ @@ -139,7 +139,7 @@ public function testFix73(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): \Generator { yield from [ 'It replaces an unset on a property with = null' => [ diff --git a/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php b/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php index 6631110fadd..4ab03325669 100644 --- a/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php +++ b/tests/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixerTest.php @@ -70,7 +70,7 @@ public function testFixWithAbstract(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixWithAbstractCases() + public function provideFixWithAbstractCases(): array { return [ [ @@ -166,7 +166,7 @@ public function testFixWithBreak(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithBreakCases() + public function provideFixWithBreakCases(): array { return [ [ @@ -215,7 +215,7 @@ public function testFixWithAs(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithAsCases() + public function provideFixWithAsCases(): array { return [ [ @@ -331,7 +331,7 @@ public function testFixWithCase(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithCaseCases() + public function provideFixWithCaseCases(): array { return [ [ @@ -401,7 +401,7 @@ public function testFixWithCatch(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithCatchCases() + public function provideFixWithCatchCases(): array { return [ [ @@ -443,7 +443,7 @@ public function testFixWithClass(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithClassCases() + public function provideFixWithClassCases(): array { return [ [ @@ -517,7 +517,7 @@ public function testFixWithContinue(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixWithContinueCases() + public function provideFixWithContinueCases(): array { return [ [ @@ -562,7 +562,7 @@ public function testFixWithConst(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithConstCases() + public function provideFixWithConstCases(): array { return [ [ @@ -600,7 +600,7 @@ public function testFixWithConstImport(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideFixWithConstImportCases() + public function provideFixWithConstImportCases(): array { return [ [ @@ -638,7 +638,7 @@ public function testFixWithClone(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithCloneCases() + public function provideFixWithCloneCases(): array { return [ [ @@ -676,7 +676,7 @@ public function testFixWithDo(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithDoCases() + public function provideFixWithDoCases(): array { return [ [ @@ -718,7 +718,7 @@ public function testFixWithEcho(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithEchoCases() + public function provideFixWithEchoCases(): array { return [ [ @@ -756,7 +756,7 @@ public function testFixWithElse(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithElseCases() + public function provideFixWithElseCases(): array { return [ [ @@ -794,7 +794,7 @@ public function testFixWithElseIf(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithElseIfCases() + public function provideFixWithElseIfCases(): array { return [ [ @@ -832,7 +832,7 @@ public function testFixWithExtends(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideFixWithExtendsCases() + public function provideFixWithExtendsCases(): array { return [ [ @@ -931,7 +931,7 @@ public function testFixWithFinal(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithFinalCases() + public function provideFixWithFinalCases(): array { return [ [ @@ -1027,7 +1027,7 @@ public function testFixWithFinally(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideFixWithFinallyCases() + public function provideFixWithFinallyCases(): array { return [ [ @@ -1069,7 +1069,7 @@ public function testFixWithFor(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithForCases() + public function provideFixWithForCases(): array { return [ [ @@ -1111,7 +1111,7 @@ public function testFixWithForeach(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideFixWithForeachCases() + public function provideFixWithForeachCases(): array { return [ [ @@ -1153,7 +1153,7 @@ public function testFixWithFunction(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixWithFunctionCases() + public function provideFixWithFunctionCases(): array { return [ [ @@ -1249,7 +1249,7 @@ public function testFixWithFunctionImport(string $expected, ?string $input = nul $this->doTest($expected, $input); } - public function provideFixWithFunctionImportCases() + public function provideFixWithFunctionImportCases(): array { return [ [ @@ -1287,7 +1287,7 @@ public function testFixWithGlobal(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithGlobalCases() + public function provideFixWithGlobalCases(): array { return [ [ @@ -1329,7 +1329,7 @@ public function testFixWithGoto(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithGotoCases() + public function provideFixWithGotoCases(): array { return [ [ @@ -1363,7 +1363,7 @@ public function testFixWithIf(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithIfCases() + public function provideFixWithIfCases(): array { return [ [ @@ -1401,7 +1401,7 @@ public function testFixWithImplements(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideFixWithImplementsCases() + public function provideFixWithImplementsCases(): array { return [ [ @@ -1464,7 +1464,7 @@ public function testFixWithInclude(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideFixWithIncludeCases() + public function provideFixWithIncludeCases(): array { return [ [ @@ -1502,7 +1502,7 @@ public function testFixWithIncludeOnce(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideFixWithIncludeOnceCases() + public function provideFixWithIncludeOnceCases(): array { return [ [ @@ -1540,7 +1540,7 @@ public function testFixWithInstanceof(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideFixWithInstanceofCases() + public function provideFixWithInstanceofCases(): array { return [ [ @@ -1582,7 +1582,7 @@ public function testFixWithInsteadof(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideFixWithInsteadofCases() + public function provideFixWithInsteadofCases(): array { return [ [ @@ -1676,7 +1676,7 @@ public function testFixWithInterface(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideFixWithInterfaceCases() + public function provideFixWithInterfaceCases(): array { return [ [ @@ -1714,7 +1714,7 @@ public function testFixWithNew(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithNewCases() + public function provideFixWithNewCases(): array { return [ [ @@ -1752,7 +1752,7 @@ public function testFixWithOpenTagWithEcho(string $expected, ?string $input = nu $this->doTest($expected, $input); } - public function provideFixWithOpenTagWithEchoCases() + public function provideFixWithOpenTagWithEchoCases(): array { return [ [ @@ -1794,7 +1794,7 @@ public function testFixWithPrint(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithPrintCases() + public function provideFixWithPrintCases(): array { return [ [ @@ -1832,7 +1832,7 @@ public function testFixWithPrivate(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideFixWithPrivateCases() + public function provideFixWithPrivateCases(): array { return [ [ @@ -1894,7 +1894,7 @@ public function testFixWithPrivatePhp71(string $expected, ?string $input = null) $this->doTest($expected, $input); } - public function provideFixWithPrivatePhp71Cases() + public function provideFixWithPrivatePhp71Cases(): array { return [ [ @@ -1932,7 +1932,7 @@ public function testFixWithProtected(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideFixWithProtectedCases() + public function provideFixWithProtectedCases(): array { return [ [ @@ -1994,7 +1994,7 @@ public function testFixWithProtectedPhp71(string $expected, ?string $input = nul $this->doTest($expected, $input); } - public function provideFixWithProtectedPhp71Cases() + public function provideFixWithProtectedPhp71Cases(): array { return [ [ @@ -2032,7 +2032,7 @@ public function testFixWithPublic(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithPublicCases() + public function provideFixWithPublicCases(): array { return [ [ @@ -2094,7 +2094,7 @@ public function testFixWithPublicPhp71(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideFixWithPublicPhp71Cases() + public function provideFixWithPublicPhp71Cases(): array { return [ [ @@ -2132,7 +2132,7 @@ public function testFixWithRequire(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideFixWithRequireCases() + public function provideFixWithRequireCases(): array { return [ [ @@ -2170,7 +2170,7 @@ public function testFixWithRequireOnce(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideFixWithRequireOnceCases() + public function provideFixWithRequireOnceCases(): array { return [ [ @@ -2208,7 +2208,7 @@ public function testFixWithReturn(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithReturnCases() + public function provideFixWithReturnCases(): array { return [ [ @@ -2342,7 +2342,7 @@ public function testFixWithStatic(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithStaticCases() + public function provideFixWithStaticCases(): array { return [ [ @@ -2408,7 +2408,7 @@ public function testFixWithThrow(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithThrowCases() + public function provideFixWithThrowCases(): array { return [ [ @@ -2446,7 +2446,7 @@ public function testFixWithTrait(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithTraitCases() + public function provideFixWithTraitCases(): array { return [ [ @@ -2484,7 +2484,7 @@ public function testFixWithTry(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithTryCases() + public function provideFixWithTryCases(): array { return [ [ @@ -2526,7 +2526,7 @@ public function testFixWithUse(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithUseCases() + public function provideFixWithUseCases(): array { return [ [ @@ -2600,7 +2600,7 @@ public function testFixWithUseLambda(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideFixWithUseLambdaCases() + public function provideFixWithUseLambdaCases(): array { return [ [ @@ -2642,7 +2642,7 @@ public function testFixWithUseTrait(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixWithUseTraitCases() + public function provideFixWithUseTraitCases(): array { return [ [ @@ -2680,7 +2680,7 @@ public function testFixWithVar(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithVarCases() + public function provideFixWithVarCases(): array { return [ [ @@ -2722,7 +2722,7 @@ public function testFixWithWhile(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithWhileCases() + public function provideFixWithWhileCases(): array { return [ [ @@ -2764,7 +2764,7 @@ public function testFixWithYield(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithYieldCases() + public function provideFixWithYieldCases(): array { return [ [ @@ -2802,7 +2802,7 @@ public function testFixWithYieldFrom(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideFixWithYieldFromCases() + public function provideFixWithYieldFromCases(): array { return [ [ @@ -2876,7 +2876,7 @@ public function testFixWithPhpOpen(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideFixWithPhpOpenCases() + public function provideFixWithPhpOpenCases(): array { return [ [ @@ -2913,7 +2913,7 @@ public function testComments(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideCommentsCases() + public function provideCommentsCases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield 'match 1' => [ 'doTest($expected, $input); } - public function provideToLongCases() + public function provideToLongCases(): array { // reverse testing $shortCases = $this->provideToShortCases(); @@ -100,7 +100,7 @@ public function updateAttributeKey($key, $value) return $cases; } - public function provideToShortCases() + public function provideToShortCases(): array { return [ [ @@ -194,7 +194,7 @@ public function testFixToLongSyntaxPhp72(string $input, string $expected): void $this->doTest($expected, $input); } - public function providePhp72Cases() + public function providePhp72Cases(): array { return [ [ @@ -224,7 +224,7 @@ public function testFixToLongSyntaxPhp73(string $input, string $expected): void $this->doTest($expected, $input); } - public function providePhp73Cases() + public function providePhp73Cases(): array { return [ [ diff --git a/tests/Fixer/NamespaceNotation/BlankLineAfterNamespaceFixerTest.php b/tests/Fixer/NamespaceNotation/BlankLineAfterNamespaceFixerTest.php index c84a6d23bfd..10b85f2b937 100644 --- a/tests/Fixer/NamespaceNotation/BlankLineAfterNamespaceFixerTest.php +++ b/tests/Fixer/NamespaceNotation/BlankLineAfterNamespaceFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -226,7 +226,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/NamespaceNotation/CleanNamespaceFixerTest.php b/tests/Fixer/NamespaceNotation/CleanNamespaceFixerTest.php index 900196e051b..f69e241aca7 100644 --- a/tests/Fixer/NamespaceNotation/CleanNamespaceFixerTest.php +++ b/tests/Fixer/NamespaceNotation/CleanNamespaceFixerTest.php @@ -32,7 +32,7 @@ public function testFix(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield [ '', diff --git a/tests/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixerTest.php b/tests/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixerTest.php index 108f19cda43..8faae3110dd 100644 --- a/tests/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixerTest.php +++ b/tests/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixerTest.php @@ -35,9 +35,10 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $manySpaces = []; + for ($i = 1; $i <= 100; ++$i) { $manySpaces[] = 'namespace Test'.$i.';'; } @@ -149,7 +150,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/Naming/NoHomoglyphNamesFixerTest.php b/tests/Fixer/Naming/NoHomoglyphNamesFixerTest.php index 8ec846aa8c6..d1b0793d36c 100644 --- a/tests/Fixer/Naming/NoHomoglyphNamesFixerTest.php +++ b/tests/Fixer/Naming/NoHomoglyphNamesFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ [ diff --git a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php index 7ad3513643b..6370919c325 100644 --- a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php +++ b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php @@ -38,7 +38,7 @@ public function testWithTabs(string $expected, ?string $input = null, array $con $this->doTest($expected, $input); } - public function provideWithTabsCases() + public function provideWithTabsCases(): array { return [ [ @@ -83,7 +83,7 @@ public function testConfigured(string $expected, ?string $input = null, array $c $this->doTest($expected, $input); } - public function provideConfiguredCases() + public function provideConfiguredCases(): array { return [ [ @@ -483,7 +483,7 @@ public function testFixDefaults(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -681,7 +681,7 @@ public function testUnalignEquals(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideUnalignEqualsCases() + public function provideUnalignEqualsCases(): array { return [ [ @@ -857,7 +857,7 @@ public function testUnalignDoubleArrow(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideUnalignDoubleArrowCases() + public function provideUnalignDoubleArrowCases(): array { return [ [ @@ -1252,7 +1252,7 @@ public function testFixAlignEquals(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideAlignEqualsCases() + public function provideAlignEqualsCases(): array { return [ [ @@ -1375,7 +1375,7 @@ public function testFixAlignDoubleArrow(string $expected, ?string $input = null) $this->doTest($expected, $input); } - public function provideAlignDoubleArrowCases() + public function provideAlignDoubleArrowCases(): array { return [ [ @@ -1952,7 +1952,7 @@ public function testPHP71Cases(string $expected, ?string $input = null, array $c $this->doTest($expected, $input); } - public function providePHP71Cases() + public function providePHP71Cases(): array { return [ 'align array destruction' => [ @@ -2009,7 +2009,7 @@ public function testFixPhp74(string $expected, ?string $input = null, ?array $co $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ [ diff --git a/tests/Fixer/Operator/ConcatSpaceFixerTest.php b/tests/Fixer/Operator/ConcatSpaceFixerTest.php index 3d34dabe851..98215d6a7f6 100644 --- a/tests/Fixer/Operator/ConcatSpaceFixerTest.php +++ b/tests/Fixer/Operator/ConcatSpaceFixerTest.php @@ -51,7 +51,7 @@ public function testFixWithoutSpace(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideWithoutSpaceCases() + public function provideWithoutSpaceCases(): array { return [ [ @@ -150,7 +150,7 @@ public function testFixWithSpace(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideWithSpaceCases() + public function provideWithSpaceCases(): array { return [ [ diff --git a/tests/Fixer/Operator/IncrementStyleFixerTest.php b/tests/Fixer/Operator/IncrementStyleFixerTest.php index 5237908e7b0..e271beabf10 100644 --- a/tests/Fixer/Operator/IncrementStyleFixerTest.php +++ b/tests/Fixer/Operator/IncrementStyleFixerTest.php @@ -46,14 +46,14 @@ public function testFixPostIncrement(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideFixPostIncrementCases() + public function provideFixPostIncrementCases(): array { return array_map(static function (array $case) { return array_reverse($case); }, $this->provideFixPreIncrementCases()); } - public function provideFixPreIncrementCases() + public function provideFixPreIncrementCases(): array { $cases = [ [ diff --git a/tests/Fixer/Operator/LogicalOperatorsFixerTest.php b/tests/Fixer/Operator/LogicalOperatorsFixerTest.php index 5bc24a8e505..b001c8cf829 100644 --- a/tests/Fixer/Operator/LogicalOperatorsFixerTest.php +++ b/tests/Fixer/Operator/LogicalOperatorsFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Operator/NewWithBracesFixerTest.php b/tests/Fixer/Operator/NewWithBracesFixerTest.php index 986b053629a..4e47b1143aa 100644 --- a/tests/Fixer/Operator/NewWithBracesFixerTest.php +++ b/tests/Fixer/Operator/NewWithBracesFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ [ @@ -318,7 +318,7 @@ public function testFix80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Operator/NotOperatorWithSuccessorSpaceFixerTest.php b/tests/Fixer/Operator/NotOperatorWithSuccessorSpaceFixerTest.php index ececc65f884..83839ecd004 100644 --- a/tests/Fixer/Operator/NotOperatorWithSuccessorSpaceFixerTest.php +++ b/tests/Fixer/Operator/NotOperatorWithSuccessorSpaceFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Operator/ObjectOperatorWithoutWhitespaceFixerTest.php b/tests/Fixer/Operator/ObjectOperatorWithoutWhitespaceFixerTest.php index 3bf3a86f348..686097218ed 100644 --- a/tests/Fixer/Operator/ObjectOperatorWithoutWhitespaceFixerTest.php +++ b/tests/Fixer/Operator/ObjectOperatorWithoutWhitespaceFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -87,7 +87,7 @@ public function testFix80(string $expected, string $input): void $this->doTest($expected, $input); } - public static function provideFix80Cases() + public static function provideFix80Cases(): \Generator { yield [ 'method();', diff --git a/tests/Fixer/Operator/OperatorLinebreakFixerTest.php b/tests/Fixer/Operator/OperatorLinebreakFixerTest.php index 8a340205dd6..3ae2ddf9f00 100644 --- a/tests/Fixer/Operator/OperatorLinebreakFixerTest.php +++ b/tests/Fixer/Operator/OperatorLinebreakFixerTest.php @@ -37,7 +37,7 @@ public function testFix(string $expected, ?string $input = null, ?array $configu $this->doTest($expected, $input); } - public static function provideFixCases() + public static function provideFixCases(): \Generator { foreach (static::pairs() as $key => $value) { yield sprintf('%s when position is "beginning"', $key) => $value; @@ -205,7 +205,7 @@ public function testFix71(string $expected, ?string $input = null, ?array $confi $this->doTest($expected, $input); } - public static function provideFix71Cases() + public static function provideFix71Cases(): \Generator { yield 'nullable type when position is "end"' => [ ' [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ [ @@ -617,7 +617,7 @@ public function testFix74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ [ diff --git a/tests/Fixer/Operator/StandardizeNotEqualsFixerTest.php b/tests/Fixer/Operator/StandardizeNotEqualsFixerTest.php index 343303add28..3a17cc099e1 100644 --- a/tests/Fixer/Operator/StandardizeNotEqualsFixerTest.php +++ b/tests/Fixer/Operator/StandardizeNotEqualsFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'handle goto labels 1' => [ @@ -206,7 +206,7 @@ public function testFix80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): array { return [ 'nullable types in constructor property promotion' => [ diff --git a/tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php b/tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php index 2fa8a570985..d69a9843d4e 100644 --- a/tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php +++ b/tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { $operators = ['+=', '-=', '*=', '**=', '/=', '.=', '%=', '&=', '|=', '^=', '<<=', '>>=']; @@ -492,7 +492,7 @@ public function test80DoNotFix(string $input): void $this->doTest($input); } - public function provideDoNotFix80Cases() + public function provideDoNotFix80Cases(): array { return [ ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ // Do not fix cases. diff --git a/tests/Fixer/Operator/UnaryOperatorSpacesFixerTest.php b/tests/Fixer/Operator/UnaryOperatorSpacesFixerTest.php index 4e065ad7c19..e509218b37a 100644 --- a/tests/Fixer/Operator/UnaryOperatorSpacesFixerTest.php +++ b/tests/Fixer/Operator/UnaryOperatorSpacesFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/PhpTag/BlankLineAfterOpeningTagFixerTest.php b/tests/Fixer/PhpTag/BlankLineAfterOpeningTagFixerTest.php index ed337b775c5..7b262e8ee3f 100644 --- a/tests/Fixer/PhpTag/BlankLineAfterOpeningTagFixerTest.php +++ b/tests/Fixer/PhpTag/BlankLineAfterOpeningTagFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -141,7 +141,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/PhpTag/EchoTagSyntaxFixerTest.php b/tests/Fixer/PhpTag/EchoTagSyntaxFixerTest.php index 0a90d098bce..2de38b64804 100644 --- a/tests/Fixer/PhpTag/EchoTagSyntaxFixerTest.php +++ b/tests/Fixer/PhpTag/EchoTagSyntaxFixerTest.php @@ -35,7 +35,7 @@ public function testLongToShortFormat(string $expected, ?string $input = null, b $this->doTest($expected, $input); } - public function provideLongToShortFormatCases() + public function provideLongToShortFormatCases(): array { return [ ['doTest($expected, $input); } - public function provideShortToLongFormatCases() + public function provideShortToLongFormatCases(): array { $cases = [ [' 1;', 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFixLT70Cases() + public function provideFixLT70Cases(): array { return [ [ diff --git a/tests/Fixer/PhpTag/LinebreakAfterOpeningTagFixerTest.php b/tests/Fixer/PhpTag/LinebreakAfterOpeningTagFixerTest.php index 0f23f91478a..55a46eba00a 100644 --- a/tests/Fixer/PhpTag/LinebreakAfterOpeningTagFixerTest.php +++ b/tests/Fixer/PhpTag/LinebreakAfterOpeningTagFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -98,7 +98,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/PhpTag/NoClosingTagFixerTest.php b/tests/Fixer/PhpTag/NoClosingTagFixerTest.php index a75c5b3ccf4..97113cf856e 100644 --- a/tests/Fixer/PhpTag/NoClosingTagFixerTest.php +++ b/tests/Fixer/PhpTag/NoClosingTagFixerTest.php @@ -43,7 +43,7 @@ public function testWithShortOpenTag(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideWithFullOpenTagCases() + public function provideWithFullOpenTagCases(): array { return [ [ @@ -141,7 +141,7 @@ function bar() ]; } - public function provideWithShortOpenTagCases() + public function provideWithShortOpenTagCases(): array { return [ [ diff --git a/tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php index 74972f8bc78..d259a52742e 100644 --- a/tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php @@ -47,7 +47,7 @@ public function testFix(string $expected, ?string $input = null): void } } - public function provideTestFixCases() + public function provideTestFixCases(): array { $cases = [ ['$sth->assertSame(true, $foo);'], @@ -165,7 +165,7 @@ public function testFix73(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ @@ -185,10 +185,11 @@ public function testEmptyAssertions(): void $this->doTest(self::generateTest('$this->assertSame(null, $a);')); } - private function generateCases(string $expectedTemplate, string $inputTemplate) + private function generateCases(string $expectedTemplate, string $inputTemplate): array { - $cases = []; $functionTypes = ['Same' => true, 'NotSame' => false, 'Equals' => true, 'NotEquals' => false]; + $cases = []; + foreach (['true', 'false', 'null'] as $type) { foreach ($functionTypes as $method => $positive) { $cases[] = [ diff --git a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php index 4b42acb0510..065e4d83444 100644 --- a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { $cases = [ [ @@ -234,7 +234,7 @@ public function testNotFix(string $expected): void $this->doTest($expected); } - public function provideNotFixCases() + public function provideNotFixCases(): array { return [ [ @@ -293,7 +293,7 @@ public function testAssertCountFromSizeOf(string $expected, ?string $input = nul $this->doTest($expected, $input); } - public function provideTestAssertCountCases() + public function provideTestAssertCountCases(): array { return [ // positive fixing @@ -434,7 +434,7 @@ public function testAssertCountFromSizeOfCasing(string $expected, string $input) $this->doTest($expected, $input); } - public function provideTestAssertCountCasingCases() + public function provideTestAssertCountCasingCases(): array { return [ [ @@ -457,7 +457,7 @@ public function testFix73(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ diff --git a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixerTest.php index eea9f63ae49..4000147f7d3 100644 --- a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixerTest.php @@ -33,7 +33,7 @@ public function testFixInternalType(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideTestFixInternalTypeCases() + public function provideTestFixInternalTypeCases(): array { return [ 'skip cases' => [ diff --git a/tests/Fixer/PhpUnit/PhpUnitExpectationFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitExpectationFixerTest.php index df171105f3f..fa686e82ba4 100644 --- a/tests/Fixer/PhpUnit/PhpUnitExpectationFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitExpectationFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ [ @@ -361,7 +361,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { $expectedTemplate = ' @@ -409,7 +409,7 @@ public function testFix73(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ diff --git a/tests/Fixer/PhpUnit/PhpUnitInternalClassFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitInternalClassFixerTest.php index 13de2fbbc47..64fcf3b0274 100644 --- a/tests/Fixer/PhpUnit/PhpUnitInternalClassFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitInternalClassFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'It does not change normal classes' => [ diff --git a/tests/Fixer/PhpUnit/PhpUnitMockFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitMockFixerTest.php index a6902acfa30..47557d42753 100644 --- a/tests/Fixer/PhpUnit/PhpUnitMockFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitMockFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ [ diff --git a/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php index 72b087ffd25..a256ff6940a 100644 --- a/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ 'class_mapping' => [ @@ -267,7 +267,7 @@ public function testClassIsFixed(string $class): void static::assertStringNotContainsString('_', $tokens->generateCode()); } - public static function provideClassIsFixedCases() + public static function provideClassIsFixedCases(): \Generator { $classmap = require __DIR__.'/../../../vendor/composer/autoload_classmap.php'; diff --git a/tests/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixerTest.php index d357fe68c1e..05f05f14a0f 100644 --- a/tests/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ 'empty exception message' => [ @@ -688,7 +688,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/PhpUnit/PhpUnitSizeClassFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitSizeClassFixerTest.php index c4ee1c9892d..23d3947683c 100644 --- a/tests/Fixer/PhpUnit/PhpUnitSizeClassFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitSizeClassFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'It does not change normal classes' => [ diff --git a/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php index 882af3ada4d..05c24a4db16 100644 --- a/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { $cases = [ ['foo();'], @@ -47,34 +47,42 @@ public function provideTestFixCases() $cases[] = [self::generateTest("\$sth->{$methodBefore}(1, 1);")]; $cases[] = [self::generateTest("\$sth->{$methodAfter}(1, 1);")]; $cases[] = [self::generateTest("\$this->{$methodBefore}(1, 2, 'message', \$toMuch);")]; + $cases[] = [ self::generateTest("\$this->{$methodAfter}(1, 2);"), self::generateTest("\$this->{$methodBefore}(1, 2);"), ]; + $cases[] = [ self::generateTest("\$this->{$methodAfter}(1, 2); \$this->{$methodAfter}(1, 2);"), self::generateTest("\$this->{$methodBefore}(1, 2); \$this->{$methodBefore}(1, 2);"), ]; + $cases[] = [ self::generateTest("\$this->{$methodAfter}(1, 2, 'descr');"), self::generateTest("\$this->{$methodBefore}(1, 2, 'descr');"), ]; + $cases[] = [ self::generateTest("\$this->/*aaa*/{$methodAfter} \t /**bbb*/ ( /*ccc*/1 , 2);"), self::generateTest("\$this->/*aaa*/{$methodBefore} \t /**bbb*/ ( /*ccc*/1 , 2);"), ]; + $cases[] = [ self::generateTest("\$this->{$methodAfter}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');"), self::generateTest("\$this->{$methodBefore}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');"), ]; + $cases[] = [ self::generateTest("self::{$methodAfter}(1, 2);"), self::generateTest("self::{$methodBefore}(1, 2);"), ]; + $cases[] = [ self::generateTest("static::{$methodAfter}(1, 2);"), self::generateTest("static::{$methodBefore}(1, 2);"), ]; + $cases[] = [ self::generateTest("STATIC::{$methodAfter}(1, 2);"), self::generateTest("STATIC::{$methodBefore}(1, 2);"), @@ -95,9 +103,10 @@ public function testNoFixWithWrongNumberOfArguments(string $expected): void $this->doTest($expected); } - public function provideTestNoFixWithWrongNumberOfArgumentsCases() + public function provideTestNoFixWithWrongNumberOfArgumentsCases(): array { $cases = []; + foreach ($this->getMethodsMap() as $candidate => $fix) { $cases[sprintf('do not change call to "%s" without arguments.', $candidate)] = [ self::generateTest(sprintf('$this->%s();', $candidate)), @@ -136,7 +145,7 @@ public function testFix73(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): \Generator { foreach ($this->getMethodsMap() as $methodBefore => $methodAfter) { yield [ diff --git a/tests/Fixer/PhpUnit/PhpUnitTargetVersionTest.php b/tests/Fixer/PhpUnit/PhpUnitTargetVersionTest.php index 3b16183b7bf..2ecb1189049 100644 --- a/tests/Fixer/PhpUnit/PhpUnitTargetVersionTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitTargetVersionTest.php @@ -41,7 +41,7 @@ public function testFulfills(bool $expected, string $candidate, string $target, ); } - public function provideTestFulfillsCases() + public function provideTestFulfillsCases(): array { return [ [true, PhpUnitTargetVersion::VERSION_NEWEST, PhpUnitTargetVersion::VERSION_5_6], diff --git a/tests/Fixer/PhpUnit/PhpUnitTestAnnotationFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitTestAnnotationFixerTest.php index dd78946b72b..930ff5df902 100644 --- a/tests/Fixer/PhpUnit/PhpUnitTestAnnotationFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitTestAnnotationFixerTest.php @@ -988,7 +988,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null, ar $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php index 62bffab9014..b08f85eca38 100644 --- a/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php @@ -71,7 +71,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ [ diff --git a/tests/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixerTest.php index 05a8f9d45fb..4e4573889d7 100644 --- a/tests/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'already with annotation: @covers' => [ @@ -247,7 +247,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/AlignMultilineCommentFixerTest.php b/tests/Fixer/Phpdoc/AlignMultilineCommentFixerTest.php index 97794e50121..cff6bd58b48 100644 --- a/tests/Fixer/Phpdoc/AlignMultilineCommentFixerTest.php +++ b/tests/Fixer/Phpdoc/AlignMultilineCommentFixerTest.php @@ -41,7 +41,7 @@ public function testDefaults(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideDefaultCases() + public function provideDefaultCases(): array { return [ [ @@ -179,7 +179,7 @@ public function testDocLikeMultilineComments(string $expected, ?string $input = $this->doTest($expected, $input); } - public function provideDocLikeMultilineCommentsCases() + public function provideDocLikeMultilineCommentsCases(): array { return [ [ @@ -227,7 +227,7 @@ public function testMixedContentMultilineComments(string $expected, ?string $inp $this->doTest($expected, $input); } - public function provideMixedContentMultilineCommentsCases() + public function provideMixedContentMultilineCommentsCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/GeneralPhpdocTagRenameFixerTest.php b/tests/Fixer/Phpdoc/GeneralPhpdocTagRenameFixerTest.php index ca88a7ee594..1ca6b60fb24 100644 --- a/tests/Fixer/Phpdoc/GeneralPhpdocTagRenameFixerTest.php +++ b/tests/Fixer/Phpdoc/GeneralPhpdocTagRenameFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null, ?array $configu $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -275,7 +275,7 @@ public function testConfigureWithInvalidReplacements(array $replacements, bool $ ]); } - public function provideConfigureWithInvalidReplacementsCases() + public function provideConfigureWithInvalidReplacementsCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php b/tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php index fc619d99fc9..3af6e13cf01 100644 --- a/tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php +++ b/tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php @@ -324,7 +324,7 @@ public function testInlineTypehintingDocsBeforeFlowBreak(string $expected, ?stri $this->doTest($expected, $input); } - public function provideInlineTypehintingDocsBeforeFlowBreakCases() + public function provideInlineTypehintingDocsBeforeFlowBreakCases(): array { $cases = []; diff --git a/tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php b/tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php index 6a7abede202..4cb955b3fb5 100644 --- a/tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php +++ b/tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php b/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php index bf981bc2a98..70215abed28 100644 --- a/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php +++ b/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php @@ -32,7 +32,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'no typehint' => [ @@ -1246,7 +1246,7 @@ public function testFixPhp71(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp71Cases() + public function provideFixPhp71Cases(): array { return [ 'same nullable type hint' => [ @@ -1421,7 +1421,7 @@ public function testFixPhp74(string $expected, ?string $input = null, array $con $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ 'some typed static public property' => [ @@ -1697,7 +1697,7 @@ public function testFixPhp80(string $expected, ?string $input = null, array $con $this->doTest($expected, $input); } - public function provideFixPhp80Cases() + public function provideFixPhp80Cases(): array { return [ 'static return' => [ diff --git a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php index a8df8754e1f..75261d7d086 100644 --- a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php @@ -97,7 +97,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -340,7 +340,7 @@ public function testFix71(string $expected, ?string $input, array $config): void $this->doTest($expected, $input); } - public function provideFix71Cases() + public function provideFix71Cases(): array { return [ [ @@ -395,7 +395,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null, ar $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ @@ -414,7 +414,7 @@ public function testByReference(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideByReferenceCases() + public function provideByReferenceCases(): array { return [ [ @@ -459,7 +459,7 @@ public function testVariableNumberOfArguments(string $expected, string $input): $this->doTest($expected, $input); } - public function provideVariableNumberOfArgumentsCases() + public function provideVariableNumberOfArgumentsCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php index 9b8772ee229..44adf788872 100644 --- a/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAlignFixerTest.php @@ -785,7 +785,7 @@ public function testMessyWhitespaces(array $config, string $expected, string $in $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ @@ -1133,7 +1133,7 @@ public function testVariadicParams(array $config, string $expected, string $inpu $this->doTest($expected, $input); } - public function provideVariadicCases() + public function provideVariadicCases(): array { return [ [ @@ -1255,7 +1255,7 @@ public function testInvalidPhpdocsAreUnchanged(array $config, string $input): vo $this->doTest($input); } - public function provideInvalidPhpdocCases() + public function provideInvalidPhpdocCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php index 0041cd7ee47..37c2151c875 100644 --- a/tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocIndentFixerTest.php b/tests/Fixer/Phpdoc/PhpdocIndentFixerTest.php index 4aef4c66d8e..6a2a45bfdbd 100644 --- a/tests/Fixer/Phpdoc/PhpdocIndentFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocIndentFixerTest.php @@ -33,7 +33,7 @@ public function testFixIndent(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixIndentCases() + public function provideFixIndentCases(): array { $cases = []; diff --git a/tests/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixerTest.php b/tests/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixerTest.php index bcad4dba748..1b8c1885c01 100644 --- a/tests/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null, ?array $configu $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $cases = [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php b/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php index 0d0304f9dc3..50dee9bcb6e 100644 --- a/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php @@ -434,7 +434,7 @@ public function testFix71(string $expected, string $input = null, array $config $this->doTest($expected, $input); } - public function provideFix71Cases() + public function provideFix71Cases(): array { return [ 'It can handle constants with visibility' => [ @@ -481,7 +481,7 @@ public function testFixPhp74(string $expected, string $input = null, array $conf $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ 'It can handle properties with type declaration' => [ diff --git a/tests/Fixer/Phpdoc/PhpdocNoAliasTagFixerTest.php b/tests/Fixer/Phpdoc/PhpdocNoAliasTagFixerTest.php index a59665fd0c5..254e02193f8 100644 --- a/tests/Fixer/Phpdoc/PhpdocNoAliasTagFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocNoAliasTagFixerTest.php @@ -99,7 +99,7 @@ public function testPropertyFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function providePropertyCases() + public function providePropertyCases(): array { return [ [ @@ -137,7 +137,7 @@ public function testTypeToVarFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTypeToVarCases() + public function provideTypeToVarCases(): array { return [ [ @@ -195,7 +195,7 @@ public function testVarToTypeFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideVarToTypeCases() + public function provideVarToTypeCases(): array { return [ [ @@ -261,7 +261,7 @@ public function testDefaultConfig(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideDefaultConfigCases() + public function provideDefaultConfigCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixerTest.php b/tests/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixerTest.php index 24780f71fb5..37e71c4f60c 100644 --- a/tests/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocOrderByValueFixerTest.php b/tests/Fixer/Phpdoc/PhpdocOrderByValueFixerTest.php index bfbae2c5850..2ccf72e6dbb 100644 --- a/tests/Fixer/Phpdoc/PhpdocOrderByValueFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocOrderByValueFixerTest.php @@ -79,7 +79,7 @@ public function testFixWithAuthor(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithAuthorCases() + public function provideFixWithAuthorCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -199,7 +199,7 @@ public function testFixWithCovers(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithCoversCases() + public function provideFixWithCoversCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -319,7 +319,7 @@ public function testFixWithCoversNothing(string $expected, ?string $input = null $this->doTest($expected, $input); } - public function provideFixWithCoversNothingCases() + public function provideFixWithCoversNothingCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -439,7 +439,7 @@ public function testFixWithDataProvider(string $expected, ?string $input = null) $this->doTest($expected, $input); } - public function provideFixWithDataProviderCases() + public function provideFixWithDataProviderCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -559,7 +559,7 @@ public function testFixWithDepends(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideFixWithDependsCases() + public function provideFixWithDependsCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -679,7 +679,7 @@ public function testFixWithGroup(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithGroupCases() + public function provideFixWithGroupCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -799,7 +799,7 @@ public function testFixWithInternal(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixWithInternalCases() + public function provideFixWithInternalCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -919,7 +919,7 @@ public function testFixWithMethod(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithMethodCases() + public function provideFixWithMethodCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -1043,7 +1043,7 @@ public function testFixWithProperty(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixWithPropertyCases() + public function provideFixWithPropertyCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -1151,7 +1151,7 @@ public function testFixWithPropertyRead(string $expected, ?string $input = null) $this->doTest($expected, $input); } - public function provideFixWithPropertyReadCases() + public function provideFixWithPropertyReadCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -1259,7 +1259,7 @@ public function testFixWithPropertyWrite(string $expected, ?string $input = null $this->doTest($expected, $input); } - public function provideFixWithPropertyWriteCases() + public function provideFixWithPropertyWriteCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -1367,7 +1367,7 @@ public function testFixWithRequires(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixWithRequiresCases() + public function provideFixWithRequiresCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -1487,7 +1487,7 @@ public function testFixWithThrows(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithThrowsCases() + public function provideFixWithThrowsCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -1623,7 +1623,7 @@ public function testFixWithUses(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithUsesCases() + public function provideFixWithUsesCases(): array { return [ 'skip on 1 or 0 occurrences' => [ @@ -1744,7 +1744,7 @@ public function testFixWithMultipleConfiguredAnnotations(string $expected, ?stri $this->doTest($expected, $input); } - public function provideFixWithMultipleConfiguredAnnotationsCases() + public function provideFixWithMultipleConfiguredAnnotationsCases(): array { return [ 'skip on 1 or 0 occurrences' => [ diff --git a/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php b/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php index de5f1e7d3cb..1b53ae65e91 100644 --- a/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php @@ -37,7 +37,7 @@ public function testFixWithDefaultConfiguration(string $expected, ?string $input $this->doTest($expected, $input); } - public function provideDefaultConfigurationTestCases() + public function provideDefaultConfigurationTestCases(): array { return [ [ @@ -69,7 +69,7 @@ public function testFix(string $expected, ?string $input = null, array $configur $this->doTest($expected, $input); } - public function provideTestCases() + public function provideTestCases(): array { return [ [ @@ -127,7 +127,7 @@ public function AB($self) $this->doTest($expected, $input); } - public function provideGeneratedFixCases() + public function provideGeneratedFixCases(): array { return [ ['$this', 'this'], @@ -150,7 +150,7 @@ public function testInvalidConfiguration(array $configuration, string $message): $this->fixer->configure($configuration); } - public function provideInvalidConfigurationCases() + public function provideInvalidConfigurationCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php b/tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php index 50c054cf2d2..5f78dd09ab5 100644 --- a/tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public static function provideFixCases() + public static function provideFixCases(): \Generator { yield 'basic fix' => [ 'doTest($expected, $input); } - public function provideInheritDocCases() + public function provideInheritDocCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixerTest.php b/tests/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixerTest.php index f754dbddfd6..a08303b812d 100644 --- a/tests/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php b/tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php index c09bf284439..683ab544976 100644 --- a/tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php @@ -367,7 +367,7 @@ public function testWithInheritDoc(string $expected): void $this->doTest($expected); } - public function provideInheritDocCases() + public function provideInheritDocCases(): array { return [ [ @@ -410,7 +410,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocTagCasingFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTagCasingFixerTest.php index 63143610887..c6ff88eb0ee 100644 --- a/tests/Fixer/Phpdoc/PhpdocTagCasingFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocTagCasingFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php index e1d4d7eb4ca..31276763e71 100644 --- a/tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocTagTypeFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null, ?array $configu $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php b/tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php index 7ab1c9ab9e3..1d7879c6777 100644 --- a/tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php @@ -36,7 +36,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideDocblocksCases() + public function provideDocblocksCases(): array { $cases = []; @@ -676,7 +676,7 @@ public function b() return $cases; } - public function provideTraitsCases() + public function provideTraitsCases(): array { return [ [ @@ -694,7 +694,7 @@ public function test() {} ]; } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -721,7 +721,7 @@ public function testFix71(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix71Cases() + public function provideFix71Cases(): array { return [ [ @@ -766,7 +766,7 @@ public function testFix74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ [ @@ -826,7 +826,7 @@ public function testFix80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocTrimConsecutiveBlankLineSeparationFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTrimConsecutiveBlankLineSeparationFixerTest.php index 8fcd6e395d9..6f016b1cbb1 100644 --- a/tests/Fixer/Phpdoc/PhpdocTrimConsecutiveBlankLineSeparationFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocTrimConsecutiveBlankLineSeparationFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'no changes' => ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php index aa3ff840663..e295215795f 100644 --- a/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocTypesOrderFixerTest.php @@ -44,7 +44,7 @@ public function testFixWithNullFirst(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -175,7 +175,7 @@ public function testFixWithNullLast(string $expected, ?string $input = null): vo $this->doTest($expected, $input); } - public function provideFixWithNullLastCases() + public function provideFixWithNullLastCases(): array { return [ [ @@ -293,7 +293,7 @@ public function testFixWithAlphaAlgorithm(string $expected, ?string $input = nul $this->doTest($expected, $input); } - public function provideFixWithAlphaAlgorithmCases() + public function provideFixWithAlphaAlgorithmCases(): array { return [ [ @@ -407,7 +407,7 @@ public function testFixWithAlphaAlgorithmAndNullAlwaysFirst(string $expected, ?s $this->doTest($expected, $input); } - public function provideFixWithAlphaAlgorithmAndNullAlwaysFirstCases() + public function provideFixWithAlphaAlgorithmAndNullAlwaysFirstCases(): array { return [ [ @@ -522,7 +522,7 @@ public function testFixWithAlphaAlgorithmAndNullAlwaysLast(string $expected, ?st $this->doTest($expected, $input); } - public function provideFixWithAlphaAlgorithmAndNullAlwaysLastCases() + public function provideFixWithAlphaAlgorithmAndNullAlwaysLastCases(): array { return [ [ diff --git a/tests/Fixer/Phpdoc/PhpdocVarAnnotationCorrectOrderFixerTest.php b/tests/Fixer/Phpdoc/PhpdocVarAnnotationCorrectOrderFixerTest.php index 8f2578def0a..ad63070c02b 100644 --- a/tests/Fixer/Phpdoc/PhpdocVarAnnotationCorrectOrderFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocVarAnnotationCorrectOrderFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield [ // It's @param, we care only about @var 'doTest($expected, $input); } - public function provideFixVarCases() + public function provideFixVarCases(): array { return [ 'testFixVar' => [ diff --git a/tests/Fixer/ReturnNotation/NoUselessReturnFixerTest.php b/tests/Fixer/ReturnNotation/NoUselessReturnFixerTest.php index 6ed84d57415..05a6efe8841 100644 --- a/tests/Fixer/ReturnNotation/NoUselessReturnFixerTest.php +++ b/tests/Fixer/ReturnNotation/NoUselessReturnFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/ReturnNotation/ReturnAssignmentFixerTest.php b/tests/Fixer/ReturnNotation/ReturnAssignmentFixerTest.php index ae74bcf2dd8..010f6a0273b 100644 --- a/tests/Fixer/ReturnNotation/ReturnAssignmentFixerTest.php +++ b/tests/Fixer/ReturnNotation/ReturnAssignmentFixerTest.php @@ -33,7 +33,7 @@ public function testFixNestedFunctions(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFixNestedFunctionsCases() + public function provideFixNestedFunctionsCases(): array { return [ [ @@ -193,7 +193,7 @@ public function testFix(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -473,7 +473,7 @@ public function testDoNotFix(string $expected): void $this->doTest($expected); } - public function provideDoNotFixCases() + public function provideDoNotFixCases(): array { return [ 'invalid reference stays invalid' => [ @@ -798,7 +798,7 @@ public function testRepetitiveFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideRepetitiveFixCases() + public function provideRepetitiveFixCases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ // check correct statements aren't changed @@ -64,7 +64,7 @@ public function test71ReturnTypes(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideNullableReturnTypeCases() + public function provideNullableReturnTypeCases(): array { return [ ['doTest($expected, $input); } - public function provideMultiLineWhitespaceFixCases() + public function provideMultiLineWhitespaceFixCases(): array { return [ [ @@ -212,7 +212,7 @@ public function testMessyWhitespacesMultiLineWhitespace(string $expected, ?strin $this->doTest($expected, $input); } - public function provideMessyWhitespacesMultiLineWhitespaceFixCases() + public function provideMessyWhitespacesMultiLineWhitespaceFixCases(): array { return [ [ @@ -230,7 +230,7 @@ public function testSemicolonForChainedCallsFix(string $expected, ?string $input $this->doTest($expected, $input); } - public function provideSemicolonForChainedCallsFixCases() + public function provideSemicolonForChainedCallsFixCases(): array { return [ [ @@ -852,7 +852,7 @@ public function testMessyWhitespacesSemicolonForChainedCalls(string $expected, ? $this->doTest($expected, $input); } - public function provideMessyWhitespacesSemicolonForChainedCallsFixCases() + public function provideMessyWhitespacesSemicolonForChainedCallsFixCases(): array { return [ [ @@ -880,7 +880,7 @@ public function testFix73(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): array { return [ [ diff --git a/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php b/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php index b9e9a571269..fd8ebdf7173 100644 --- a/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php +++ b/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php @@ -34,7 +34,7 @@ public function testNoEmptyStatements(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideNoEmptyStatementsCases() + public function provideNoEmptyStatementsCases(): \Generator { yield from [ [ @@ -434,7 +434,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -529,7 +529,7 @@ public function testCasesWithShortOpenTag(string $expected, ?string $input = nul $this->doTest($expected, $input); } - public function provideCasesWithShortOpenTagCases() + public function provideCasesWithShortOpenTagCases(): array { return [ [ @@ -547,7 +547,7 @@ public function testFixMultipleSemicolons(string $expected, ?string $input = nul $this->doTest($expected, $input); } - public function provideFixMultipleSemicolonsCases() + public function provideFixMultipleSemicolonsCases(): array { return [ [ diff --git a/tests/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixerTest.php b/tests/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixerTest.php index 7b040fadd99..26cfc24d8c1 100644 --- a/tests/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixerTest.php +++ b/tests/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixerTest.php @@ -35,7 +35,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php b/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php index 7e785a6250b..592ef0ca97a 100644 --- a/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php +++ b/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ 'comment' => [ diff --git a/tests/Fixer/Semicolon/SpaceAfterSemicolonFixerTest.php b/tests/Fixer/Semicolon/SpaceAfterSemicolonFixerTest.php index 60d02e96fc1..1161c10c866 100644 --- a/tests/Fixer/Semicolon/SpaceAfterSemicolonFixerTest.php +++ b/tests/Fixer/Semicolon/SpaceAfterSemicolonFixerTest.php @@ -44,7 +44,7 @@ public function testFixWithSpacesInEmptyForExpressions(string $expected, ?string $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -292,7 +292,7 @@ public function testFixWithoutSpacesInEmptyForExpressions(string $expected, ?str $this->doTest($expected, $input); } - public function provideFixWithoutSpacesInEmptyForExpressionsCases() + public function provideFixWithoutSpacesInEmptyForExpressionsCases(): array { return [ [ diff --git a/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php b/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php index d8b96cbc383..10b5ff8d62c 100644 --- a/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php +++ b/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -131,7 +131,7 @@ public function testDoNotFix(string $input): void $this->doTest($input); } - public function provideDoNotFixCases() + public function provideDoNotFixCases(): array { return [ [' doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/Strict/StrictComparisonFixerTest.php b/tests/Fixer/Strict/StrictComparisonFixerTest.php index a140e62b814..dc77e57e654 100644 --- a/tests/Fixer/Strict/StrictComparisonFixerTest.php +++ b/tests/Fixer/Strict/StrictComparisonFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -188,7 +188,7 @@ public function testFix73(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix73Cases() + public function provideFix73Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ [ diff --git a/tests/Fixer/StringNotation/ExplicitStringVariableFixerTest.php b/tests/Fixer/StringNotation/ExplicitStringVariableFixerTest.php index 27405efd94b..8334e3bc180 100644 --- a/tests/Fixer/StringNotation/ExplicitStringVariableFixerTest.php +++ b/tests/Fixer/StringNotation/ExplicitStringVariableFixerTest.php @@ -33,9 +33,10 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { $input = $expected = 'doTest($expected, $input); } - public function provideTestFix71Cases() + public function provideTestFix71Cases(): array { return [ [ diff --git a/tests/Fixer/StringNotation/HeredocToNowdocFixerTest.php b/tests/Fixer/StringNotation/HeredocToNowdocFixerTest.php index 4e4f48da39d..55761c95709 100644 --- a/tests/Fixer/StringNotation/HeredocToNowdocFixerTest.php +++ b/tests/Fixer/StringNotation/HeredocToNowdocFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ [<<<'EOF' diff --git a/tests/Fixer/StringNotation/NoBinaryStringFixerTest.php b/tests/Fixer/StringNotation/NoBinaryStringFixerTest.php index f39d001b8f0..9b0eafa2771 100644 --- a/tests/Fixer/StringNotation/NoBinaryStringFixerTest.php +++ b/tests/Fixer/StringNotation/NoBinaryStringFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ [ diff --git a/tests/Fixer/StringNotation/NoTrailingWhitespaceInStringFixerTest.php b/tests/Fixer/StringNotation/NoTrailingWhitespaceInStringFixerTest.php index 487cb0ac2fe..6cf5d890ae8 100644 --- a/tests/Fixer/StringNotation/NoTrailingWhitespaceInStringFixerTest.php +++ b/tests/Fixer/StringNotation/NoTrailingWhitespaceInStringFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/StringNotation/SingleQuoteFixerTest.php b/tests/Fixer/StringNotation/SingleQuoteFixerTest.php index bd2fc233363..6e03783a39d 100644 --- a/tests/Fixer/StringNotation/SingleQuoteFixerTest.php +++ b/tests/Fixer/StringNotation/SingleQuoteFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideTestFixCases() + public function provideTestFixCases(): array { return [ [ @@ -131,7 +131,7 @@ public function testSingleQuoteFix(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideTestSingleQuoteFixCases() + public function provideTestSingleQuoteFixCases(): array { return [ [ diff --git a/tests/Fixer/Whitespace/ArrayIndentationFixerTest.php b/tests/Fixer/Whitespace/ArrayIndentationFixerTest.php index 1b02f17c793..2b03ce2b5f1 100644 --- a/tests/Fixer/Whitespace/ArrayIndentationFixerTest.php +++ b/tests/Fixer/Whitespace/ArrayIndentationFixerTest.php @@ -32,7 +32,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return $this->withLongArraySyntaxCases([ [ @@ -845,7 +845,7 @@ public function testFixWithTabs(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithTabsCases() + public function provideFixWithTabsCases(): array { return $this->withLongArraySyntaxCases([ [ @@ -896,7 +896,7 @@ public function testFixPhp74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixPhp74Cases() + public function provideFixPhp74Cases(): array { return [ [ @@ -920,7 +920,7 @@ public function provideFixPhp74Cases() ]; } - private function withLongArraySyntaxCases(array $cases) + private function withLongArraySyntaxCases(array $cases): array { $longSyntaxCases = []; @@ -936,7 +936,7 @@ private function withLongArraySyntaxCases(array $cases) return array_merge($cases, $longSyntaxCases); } - private function toLongArraySyntax(string $php) + private function toLongArraySyntax(string $php): string { return strtr($php, [ '[' => 'array(', diff --git a/tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php b/tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php index c273fcbecf6..885e87d2f24 100644 --- a/tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php +++ b/tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php @@ -465,7 +465,7 @@ public function testFixWithFor(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixWithForCases() + public function provideFixWithForCases(): array { return [ [ @@ -594,7 +594,7 @@ public function testFixWithForEach(string $expected, ?string $input = null): voi $this->doTest($expected, $input); } - public function provideFixWithForEachCases() + public function provideFixWithForEachCases(): array { return [ [ @@ -1098,7 +1098,7 @@ public function testFixWithYield(string $expected, ?string $input = null): void /** * @yield array */ - public function provideFixWithYieldCases() + public function provideFixWithYieldCases(): array { return [ [ @@ -1220,7 +1220,7 @@ public function testFixWithYieldFrom(string $expected, ?string $input = null): v /** * @yield array */ - public function provideFixWithYieldFromCases() + public function provideFixWithYieldFromCases(): array { return [ [ @@ -1281,7 +1281,7 @@ public function testFixWithMultipleConfigStatements(array $statements, string $e $this->doTest($expected, $input); } - public function provideFixWithMultipleConfigStatementsCases() + public function provideFixWithMultipleConfigStatementsCases(): array { $statementsWithoutCaseOrDefault = [ 'break', diff --git a/tests/Fixer/Whitespace/CompactNullableTypehintFixerTest.php b/tests/Fixer/Whitespace/CompactNullableTypehintFixerTest.php index 2b98321c907..e94de149a37 100644 --- a/tests/Fixer/Whitespace/CompactNullableTypehintFixerTest.php +++ b/tests/Fixer/Whitespace/CompactNullableTypehintFixerTest.php @@ -35,7 +35,7 @@ public function testFix71(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix71Cases() + public function provideFix71Cases(): array { return [ [ @@ -120,7 +120,7 @@ public function testFix74(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix74Cases() + public function provideFix74Cases(): array { return [ [ diff --git a/tests/Fixer/Whitespace/HeredocIndentationFixerTest.php b/tests/Fixer/Whitespace/HeredocIndentationFixerTest.php index faefa87983e..f51ab2d4454 100644 --- a/tests/Fixer/Whitespace/HeredocIndentationFixerTest.php +++ b/tests/Fixer/Whitespace/HeredocIndentationFixerTest.php @@ -53,7 +53,7 @@ public function testFix(string $expected, ?string $input = null, array $config = $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ diff --git a/tests/Fixer/Whitespace/MethodChainingIndentationFixerTest.php b/tests/Fixer/Whitespace/MethodChainingIndentationFixerTest.php index 8ad8ff15488..8440ccce472 100644 --- a/tests/Fixer/Whitespace/MethodChainingIndentationFixerTest.php +++ b/tests/Fixer/Whitespace/MethodChainingIndentationFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -247,7 +247,7 @@ public function testWindowsWhitespaces(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideWindowsWhitespacesCases() + public function provideWindowsWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php index 4d81717b4f9..5856a97aa9f 100644 --- a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php +++ b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php @@ -103,7 +103,7 @@ public function testWithConfig(array $lineNumberRemoved, array $config): void $this->doTest($this->removeLinesFromString($this->template, $lineNumberRemoved), $this->template); } - public function provideWithConfigCases() + public function provideWithConfigCases(): array { $tests = [ [ @@ -362,7 +362,7 @@ public function testFixWithComments(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideCommentCases() + public function provideCommentCases(): array { return [ [ @@ -416,7 +416,7 @@ public function testFixWithLineBreaks(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideLineBreakCases() + public function provideLineBreakCases(): array { $input = 'doTest($expected, $input); } - public function provideBetweenUseCases() + public function provideBetweenUseCases(): array { return [ ['doTest($expected, $input); } - public function provideRemoveLinesBetweenUseStatementsCases() + public function provideRemoveLinesBetweenUseStatementsCases(): array { return [ [ @@ -600,7 +600,7 @@ public function testWithoutUses(string $expected): void $this->doTest($expected); } - public function provideWithoutUsesCases() + public function provideWithoutUsesCases(): array { return [ [ @@ -635,7 +635,7 @@ public function testRemoveBetweenUseTraits(string $expected, string $input): voi $this->doTest($expected, $input); } - public function provideRemoveBetweenUseTraitsCases() + public function provideRemoveBetweenUseTraitsCases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideOneAndInLineCases() + public function provideOneAndInLineCases(): \Generator { yield from [ [ @@ -788,7 +788,7 @@ public function testBraces(array $config, string $expected, ?string $input = nul $this->doTest($expected, $input); } - public function provideBraceCases() + public function provideBraceCases(): array { return [ [ @@ -887,7 +887,7 @@ public function testMessyWhitespaces(array $config, string $expected, ?string $i $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ @@ -922,7 +922,7 @@ public function testInSwitchStatement(array $config, string $expected, ?string $ $this->doTest($expected, $input); } - public function provideSwitchCases() + public function provideSwitchCases(): array { return [ [ @@ -1061,7 +1061,7 @@ public function testFix72(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix72Cases() + public function provideFix72Cases(): \Generator { yield [ 'doTest($expected); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideCommentCases() + public function provideCommentCases(): array { return [ [ @@ -114,7 +114,7 @@ function someFunc() { $someVar = []; } $this->doTest($expected); } - public function provideOutsideCases() + public function provideOutsideCases(): \Generator { yield from [ [ @@ -205,7 +205,7 @@ public function provideOutsideCases() } } - public function provideInsideCases() + public function provideInsideCases(): array { return [ [ @@ -300,7 +300,7 @@ public function testFixWithConfiguration(array $configuration, string $expected, $this->doTest($expected, $input); } - public function provideConfigurationCases() + public function provideConfigurationCases(): \Generator { $tests = [ [ @@ -374,7 +374,7 @@ public function testPHP71(array $configuration, string $expected, string $input) $this->doTest($expected, $input); } - public function providePHP71Cases() + public function providePHP71Cases(): array { return [ 'Config "default".' => [ diff --git a/tests/Fixer/Whitespace/NoSpacesInsideParenthesisFixerTest.php b/tests/Fixer/Whitespace/NoSpacesInsideParenthesisFixerTest.php index 937c12d2714..c9952224fad 100644 --- a/tests/Fixer/Whitespace/NoSpacesInsideParenthesisFixerTest.php +++ b/tests/Fixer/Whitespace/NoSpacesInsideParenthesisFixerTest.php @@ -56,7 +56,7 @@ private function bar() $this->doTest($expected); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -137,7 +137,7 @@ public function testFix80(string $expected, string $input): void $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ [ @@ -152,7 +152,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { return [ [ diff --git a/tests/Fixer/Whitespace/TypesSpacesFixerTest.php b/tests/Fixer/Whitespace/TypesSpacesFixerTest.php index 0ad3ba8fbab..26ef6573d15 100644 --- a/tests/Fixer/Whitespace/TypesSpacesFixerTest.php +++ b/tests/Fixer/Whitespace/TypesSpacesFixerTest.php @@ -32,7 +32,7 @@ public function testFix(string $expected, ?string $input = null, array $configur $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield [ 'doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield [ 'getName()); } - public function provideGetNameCases() + public function provideGetNameCases(): array { return [ ['foo'], @@ -55,7 +55,7 @@ public function testGetDescription(string $description): void static::assertSame($description, $option->getDescription()); } - public function provideGetDescriptionCases() + public function provideGetDescriptionCases(): array { return [ ['Foo.'], @@ -71,7 +71,7 @@ public function testHasDefault(bool $hasDefault, AliasedFixerOption $input): voi static::assertSame($hasDefault, $input->hasDefault()); } - public function provideHasDefaultCases() + public function provideHasDefaultCases(): array { return [ [ @@ -95,7 +95,7 @@ public function testGetDefault(string $default): void static::assertSame($default, $option->getDefault()); } - public function provideGetDefaultCases() + public function provideGetDefaultCases(): array { return [ ['baz'], @@ -122,7 +122,7 @@ public function testGetAllowedTypes(?array $allowedTypes): void static::assertSame($allowedTypes, $option->getAllowedTypes()); } - public function provideGetAllowedTypesCases() + public function provideGetAllowedTypesCases(): array { return [ [null], @@ -141,7 +141,7 @@ public function testGetAllowedValues(?array $allowedValues): void static::assertSame($allowedValues, $option->getAllowedValues()); } - public function provideGetAllowedValuesCases() + public function provideGetAllowedValuesCases(): array { return [ [null], @@ -179,7 +179,7 @@ public function testGetAlias(string $alias): void static::assertSame($alias, $options->getAlias()); } - public function provideGetAliasCases() + public function provideGetAliasCases(): array { return [ ['bar'], diff --git a/tests/FixerConfiguration/AllowedValueSubsetTest.php b/tests/FixerConfiguration/AllowedValueSubsetTest.php index 2ebebbb0af0..b243572c00b 100644 --- a/tests/FixerConfiguration/AllowedValueSubsetTest.php +++ b/tests/FixerConfiguration/AllowedValueSubsetTest.php @@ -41,7 +41,7 @@ public function testInvoke($inputValue, bool $expectedResult): void static::assertSame($expectedResult, $subset($inputValue)); } - public function provideInvokeCases() + public function provideInvokeCases(): array { return [ [ diff --git a/tests/FixerConfiguration/DeprecatedFixerOptionTest.php b/tests/FixerConfiguration/DeprecatedFixerOptionTest.php index 88d2c061145..682bd77d27e 100644 --- a/tests/FixerConfiguration/DeprecatedFixerOptionTest.php +++ b/tests/FixerConfiguration/DeprecatedFixerOptionTest.php @@ -71,7 +71,7 @@ public function testHasDefault(bool $isRequired): void static::assertSame(!$isRequired, $option->hasDefault()); } - public function provideHasDefaultCases() + public function provideHasDefaultCases(): array { return [ [true], @@ -94,7 +94,7 @@ public function testGetDefault($default): void static::assertSame($default, $option->getDefault()); } - public function provideGetDefaultCases() + public function provideGetDefaultCases(): array { return [ ['foo'], diff --git a/tests/FixerFactoryTest.php b/tests/FixerFactoryTest.php index 8b72ab31599..9369b707532 100644 --- a/tests/FixerFactoryTest.php +++ b/tests/FixerFactoryTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests; +use PhpCsFixer\Fixer\FixerInterface; use PhpCsFixer\FixerFactory; use PhpCsFixer\RuleSet\RuleSet; use PhpCsFixer\RuleSet\RuleSetInterface; @@ -39,12 +40,14 @@ public function testInterfaceIsFluent(): void $testInstance = $factory->registerCustomFixers( [$this->createFixerDouble('Foo/f1'), $this->createFixerDouble('Foo/f2')] ); + static::assertSame($factory, $testInstance); $testInstance = $factory->registerFixer( $this->createFixerDouble('f3'), false ); + static::assertSame($factory, $testInstance); $ruleSetProphecy = $this->prophesize(RuleSetInterface::class); @@ -52,6 +55,7 @@ public function testInterfaceIsFluent(): void $testInstance = $factory->useRuleSet( $ruleSetProphecy->reveal() ); + static::assertSame($factory, $testInstance); } @@ -63,7 +67,27 @@ public function testRegisterBuiltInFixers(): void $factory = new FixerFactory(); $factory->registerBuiltInFixers(); - static::assertGreaterThan(0, \count($factory->getFixers())); + $fixerClasses = array_filter( + get_declared_classes(), + static function (string $className): bool { + $class = new \ReflectionClass($className); + + return !$class->isAbstract() && $class->implementsInterface(FixerInterface::class) && 0 === strpos($class->getNamespaceName(), 'PhpCsFixer\\Fixer\\'); + } + ); + + sort($fixerClasses); + + $fixers = array_map( + static function (FixerInterface $fixer): string { + return \get_class($fixer); + }, + $factory->getFixers() + ); + + sort($fixers); + + static::assertSame($fixerClasses, $fixers); } /** @@ -133,12 +157,14 @@ public function testUseRuleSet(): void ->registerBuiltInFixers() ->useRuleSet(new RuleSet([])) ; + static::assertCount(0, $factory->getFixers()); $factory = (new FixerFactory()) ->registerBuiltInFixers() ->useRuleSet(new RuleSet(['strict_comparison' => true, 'blank_line_before_statement' => false])) ; + $fixers = $factory->getFixers(); static::assertCount(1, $fixers); static::assertSame('strict_comparison', $fixers[0]->getName()); @@ -156,6 +182,7 @@ public function testUseRuleSetWithNonExistingRule(): void ->registerBuiltInFixers() ->useRuleSet(new RuleSet(['non_existing_rule' => true])) ; + $fixers = $factory->getFixers(); static::assertCount(1, $fixers); static::assertSame('strict_comparison', $fixers[0]->getName()); @@ -206,7 +233,7 @@ public function testConflictingFixers(RuleSet $ruleSet): void ->registerBuiltInFixers()->useRuleSet($ruleSet); } - public function provideConflictingFixersCases() + public function provideConflictingFixersCases(): array { return [ [new RuleSet(['no_blank_lines_before_namespace' => true, 'single_blank_line_before_namespace' => true])], @@ -248,7 +275,6 @@ public function testSetWhitespacesConfig(): void $fixer->setWhitespacesConfig($config)->shouldBeCalled(); $factory->registerFixer($fixer->reveal(), false); - $factory->setWhitespacesConfig($config); } @@ -274,6 +300,7 @@ public function testConfigureNonConfigurableFixer(): void $this->expectException( \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class ); + $this->expectExceptionMessage( '[non_configurable] Is not configurable.' ); @@ -300,6 +327,7 @@ public function testConfigureFixerWithNonArray($value): void $this->expectException( \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class ); + $this->expectExceptionMessage( '[foo] Rule must be enabled (true), disabled (false) or configured (non-empty, assoc array). Other values are not allowed.' ); @@ -309,7 +337,7 @@ public function testConfigureFixerWithNonArray($value): void ])); } - public function provideConfigureFixerWithNonArrayCases() + public function provideConfigureFixerWithNonArrayCases(): array { return [ ['bar'], @@ -326,9 +354,7 @@ public function testConfigurableFixerIsConfigured(): void $fixer->configure(['bar' => 'baz'])->shouldBeCalled(); $factory = new FixerFactory(); - $factory->registerFixer($fixer->reveal(), false); - $factory->useRuleSet(new RuleSet([ 'foo' => ['bar' => 'baz'], ])); diff --git a/tests/FixerNameValidatorTest.php b/tests/FixerNameValidatorTest.php index 63e16fbb07d..4410724a424 100644 --- a/tests/FixerNameValidatorTest.php +++ b/tests/FixerNameValidatorTest.php @@ -35,7 +35,7 @@ public function testIsValid(string $name, bool $isCustom, bool $isValid): void static::assertSame($isValid, $validator->isValid($name, $isCustom)); } - public function provideIsValidCases() + public function provideIsValidCases(): array { return [ ['', true, false], diff --git a/tests/Indicator/PhpUnitTestCaseIndicatorTest.php b/tests/Indicator/PhpUnitTestCaseIndicatorTest.php index 83724996b35..1c3bc6aa3df 100644 --- a/tests/Indicator/PhpUnitTestCaseIndicatorTest.php +++ b/tests/Indicator/PhpUnitTestCaseIndicatorTest.php @@ -53,7 +53,7 @@ public function testIsPhpUnitClass(bool $expected, Tokens $tokens, int $index): static::assertSame($expected, $this->indicator->isPhpUnitClass($tokens, $index)); } - public function provideIsPhpUnitClassCases() + public function provideIsPhpUnitClassCases(): array { return [ 'Test class' => [ @@ -145,7 +145,7 @@ public function testFindPhpUnitClasses(array $expectedIndexes, string $code): vo static::assertSame($expectedIndexes, $classes); } - public function provideFindPhpUnitClassesCases() + public function provideFindPhpUnitClassesCases(): array { return [ 'empty' => [ diff --git a/tests/Linter/CachingLinterTest.php b/tests/Linter/CachingLinterTest.php index 7c2452ef30f..684a03e81b9 100644 --- a/tests/Linter/CachingLinterTest.php +++ b/tests/Linter/CachingLinterTest.php @@ -40,7 +40,7 @@ public function testIsAsync(bool $isAsync): void static::assertSame($isAsync, $linter->isAsync()); } - public function provideIsAsyncCases() + public function provideIsAsyncCases(): array { return [ [true], diff --git a/tests/PregTest.php b/tests/PregTest.php index ff51549de88..cdbedc3e329 100644 --- a/tests/PregTest.php +++ b/tests/PregTest.php @@ -46,7 +46,7 @@ public function testMatch(string $pattern, string $subject): void static::assertSame($expectedMatches, $actualMatches); } - public function providePatternValidationCases() + public function providePatternValidationCases(): array { return [ 'invalid_blank' => ['', null, PregException::class], @@ -211,7 +211,7 @@ public function testReplaceCallback($pattern, $subject): void static::assertSame($expectedResult, $actualResult); } - public function provideCommonCases() + public function provideCommonCases(): array { return [ ['/u/u', 'u'], @@ -222,7 +222,7 @@ public function provideCommonCases() ]; } - public function provideArrayOfPatternsCases() + public function provideArrayOfPatternsCases(): array { return [ [['/Ă /', '/Ă­/'], 'TĂ Ă­l'], diff --git a/tests/RuleSet/RuleSetTest.php b/tests/RuleSet/RuleSetTest.php index fa572ceeb50..7a527082342 100644 --- a/tests/RuleSet/RuleSetTest.php +++ b/tests/RuleSet/RuleSetTest.php @@ -115,21 +115,19 @@ public function testThatThereIsNoDeprecatedFixerInRuleSet(string $setName, strin static::assertNotInstanceOf(DeprecatedFixerInterface::class, $fixer, sprintf('RuleSet "%s" contains deprecated rule "%s".', $setName, $ruleName)); } - public function provideAllRulesFromSetsCases() + public function provideAllRulesFromSetsCases(): \Generator { - $cases = []; foreach (RuleSets::getSetDefinitionNames() as $setName) { $ruleSet = new RuleSet([$setName => true]); + foreach ($ruleSet->getRules() as $rule => $config) { - $cases[] = [ + yield $setName.':'.$rule => [ $setName, $rule, $config, ]; } } - - return $cases; } public function testGetBuildInSetDefinitionNames(): void @@ -289,26 +287,22 @@ public function testRiskyRulesInSet(array $set, bool $safe): void ); } - public function provideSafeSetCases() + public function provideSafeSetCases(): \Generator { - $sets = []; - foreach (RuleSets::getSetDefinitionNames() as $name) { - $sets[$name] = [ + yield $name => $sets[$name] = [ [$name => true], false === strpos($name, ':risky'), ]; } - $sets['@Symfony:risky_and_@Symfony'] = [ + yield '@Symfony:risky_and_@Symfony' => [ [ '@Symfony:risky' => true, '@Symfony' => false, ], false, ]; - - return $sets; } public function testInvalidConfigNestedSets(): void @@ -397,17 +391,18 @@ public function testPhpUnitTargetVersionHasSet(string $version): void ); } - public static function providePhpUnitTargetVersionHasSetCases() + public static function providePhpUnitTargetVersionHasSetCases(): \Generator { foreach ((new \ReflectionClass(PhpUnitTargetVersion::class))->getConstants() as $constant) { if ('newest' === $constant) { continue; } + yield [$constant]; } } - private function sortNestedArray(array $array) + private function sortNestedArray(array $array): array { foreach ($array as $key => $element) { if (!\is_array($element)) { @@ -426,7 +421,7 @@ private function sortNestedArray(array $array) return $array; } - private function findInSets(array $sets, string $ruleName, $config) + private function findInSets(array $sets, string $ruleName, $config): array { $duplicates = []; @@ -473,11 +468,11 @@ private function expendSet(array $setDefinitions, array $resolvedSets, string $s return $resolvedSets[$setName]; } - private static function assertSameRules(array $expected, array $actual, string $message = ''): void + private static function assertSameRules(array $expected, array $actual): void { ksort($expected); ksort($actual); - static::assertSame($expected, $actual, $message); + static::assertSame($expected, $actual); } } diff --git a/tests/RuleSet/Sets/AbstractSetTest.php b/tests/RuleSet/Sets/AbstractSetTest.php index 244d8b19c00..1a148b5557d 100644 --- a/tests/RuleSet/Sets/AbstractSetTest.php +++ b/tests/RuleSet/Sets/AbstractSetTest.php @@ -18,6 +18,7 @@ use PhpCsFixer\FixerFactory; use PhpCsFixer\RuleSet\RuleSet; use PhpCsFixer\RuleSet\RuleSetDescriptionInterface; +use PhpCsFixer\RuleSet\RuleSets; use PhpCsFixer\Tests\TestCase; /** @@ -41,8 +42,7 @@ public function testSet(): void static::assertSanityString($setName); static::assertSanityString($setDescription); static::assertSame('.', substr($setDescription, -1), sprintf('Ruleset description of "%s" must end with ".", got "%s".', $setName, $setDescription)); - static::assertIsBool($isRiskySet); - static::assertIsArray($setRules); + static::assertRules($setRules, $factory, $setName); if (1 === preg_match('/(\d)(\d)Migration/', \get_class($set), $matches)) { static::assertStringEndsWith( @@ -68,6 +68,28 @@ public function testSet(): void } } + private static function assertRules(array $setRules, FixerFactory $factory, string $setName): void + { + $sawRule = false; + + foreach ($setRules as $rule => $config) { + static::assertIsString($rule, $setName); + + if ('@' === substr($rule, 0, 1)) { + static::assertFalse($sawRule, sprintf('Ruleset "%s" should define all sets it extends first and than list by rule configuration overrides.', $setName)); + RuleSets::getSetDefinition($setName); + } else { + $sawRule = true; + static::assertTrue($factory->hasRule($rule)); + } + } + + $setRulesSorted = $setRules; + ksort($setRulesSorted); + + static::assertSame($setRulesSorted, $setRules); + } + private static function assertSanityString(string $string): void { static::assertSame(trim($string), $string); diff --git a/tests/Smoke/CiIntegrationTest.php b/tests/Smoke/CiIntegrationTest.php index 41375eb6eca..5cc8c544458 100644 --- a/tests/Smoke/CiIntegrationTest.php +++ b/tests/Smoke/CiIntegrationTest.php @@ -192,7 +192,7 @@ public function testIntegration( ); } - public function provideIntegrationCases() + public function provideIntegrationCases(): array { return [ 'random-changes' => [ diff --git a/tests/Test/AbstractFixerTestCase.php b/tests/Test/AbstractFixerTestCase.php index 64f8458b033..86ff90b87a1 100644 --- a/tests/Test/AbstractFixerTestCase.php +++ b/tests/Test/AbstractFixerTestCase.php @@ -151,7 +151,7 @@ final public function testFixerDefinitions(): void if ($fixerIsConfigurable) { // always re-configure as the fixer might have been configured with diff. configuration form previous sample - $this->fixer->configure(null === $config ? [] : $config); + $this->fixer->configure($config ?? []); } Tokens::clearCache(); @@ -466,7 +466,7 @@ private static function assertCorrectCasing(string $needle, string $haystack, st static::assertSame(substr_count(strtolower($haystack), strtolower($needle)), substr_count($haystack, $needle), $message); } - private function findAllTokenSequences($tokens, $sequence) + private function findAllTokenSequences($tokens, $sequence): array { $lastIndex = 0; $sequences = []; diff --git a/tests/Test/IntegrationCase.php b/tests/Test/IntegrationCase.php index 3de0d021f14..cc61f610e41 100644 --- a/tests/Test/IntegrationCase.php +++ b/tests/Test/IntegrationCase.php @@ -84,7 +84,7 @@ public function __construct( $this->inputCode = $inputCode; } - public function hasInputCode() + public function hasInputCode(): bool { return null !== $this->inputCode; } diff --git a/tests/TextDiffTest.php b/tests/TextDiffTest.php index f1acc02e1a2..e502eef6a17 100644 --- a/tests/TextDiffTest.php +++ b/tests/TextDiffTest.php @@ -63,7 +63,7 @@ public function testDiffReportingDecorated(string $expected, string $format, boo static::assertStringMatchesFormat($expected, $commandTester->getDisplay(false)); } - public function provideDiffReportingCases() + public function provideDiffReportingCases(): \Generator { $expected = <<<'TEST' %A$output->writeln(''.(int)$output.'');%A @@ -79,10 +79,9 @@ public function provideDiffReportingCases() } $expected = substr(json_encode($expected), 1, -1); - $cases[] = [$expected, 'json', true]; - $cases[] = [$expected, 'json', false]; - return $cases; + yield [$expected, 'json', true]; + yield [$expected, 'json', false]; } /** diff --git a/tests/Tokenizer/Analyzer/Analysis/TypeAnalysisTest.php b/tests/Tokenizer/Analyzer/Analysis/TypeAnalysisTest.php index d0782fbc6f0..e361be6ca55 100644 --- a/tests/Tokenizer/Analyzer/Analysis/TypeAnalysisTest.php +++ b/tests/Tokenizer/Analyzer/Analysis/TypeAnalysisTest.php @@ -65,7 +65,7 @@ public function testReserved(string $type, bool $expected): void static::assertSame($expected, $analysis->isReservedType()); } - public function provideReservedCases() + public function provideReservedCases(): array { return [ ['array', true], diff --git a/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php b/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php index e391d5d5cbe..af7d6e82af5 100644 --- a/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/ArgumentsAnalyzerTest.php @@ -70,7 +70,7 @@ public function testArgumentInfo80(string $code, int $openIndex, int $closeIndex ); } - public function provideArgumentsCases() + public function provideArgumentsCases(): array { return [ ['getArguments($tokens, $openIndex, $closeIndex)); } - public function provideArguments73Cases() + public function provideArguments73Cases(): array { return [ [' 3]], @@ -245,7 +245,7 @@ public function testArguments80(string $code, int $openIndex, int $closeIndex, a static::assertSame($arguments, $analyzer->getArguments($tokens, $openIndex, $closeIndex)); } - public function provideArguments80Cases() + public function provideArguments80Cases(): array { return [ [' 22]], diff --git a/tests/Tokenizer/Analyzer/BlocksAnalyzerTest.php b/tests/Tokenizer/Analyzer/BlocksAnalyzerTest.php index dab7e4daf2b..f6734d63e28 100644 --- a/tests/Tokenizer/Analyzer/BlocksAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/BlocksAnalyzerTest.php @@ -38,7 +38,7 @@ public function testBlocks(string $code, int $openIndex, int $closeIndex): void static::assertTrue($analyzer->isBlock($tokens, $openIndex, $closeIndex)); } - public function provideBlocksCases() + public function provideBlocksCases(): array { return [ ['isBlock($tokens, $openIndex, $closeIndex)); } - public function provideNonBlocksCases() + public function provideNonBlocksCases(): array { return [ ['isBlock($tokens, $openIndex, $closeIndex)); } - public function provideBlocksPhp74Cases() + public function provideBlocksPhp74Cases(): array { return [ [' $x + 10;', 6, 8], diff --git a/tests/Tokenizer/Analyzer/ClassyAnalyzerTest.php b/tests/Tokenizer/Analyzer/ClassyAnalyzerTest.php index 78c81d530f2..104a1af8e4d 100644 --- a/tests/Tokenizer/Analyzer/ClassyAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/ClassyAnalyzerTest.php @@ -35,7 +35,7 @@ public function testIsClassyInvocation(string $source, array $expected): void self::assertClassyInvocation($source, $expected); } - public function provideIsClassyInvocationCases() + public function provideIsClassyInvocationCases(): \Generator { yield from [ [ @@ -138,7 +138,7 @@ public function testIsClassyInvocation71(string $source, array $expected): void self::assertClassyInvocation($source, $expected); } - public function provideIsClassyInvocation71Cases() + public function provideIsClassyInvocation71Cases(): array { return [ [ @@ -171,7 +171,7 @@ public function testIsClassyInvocation80(string $source, array $expected): void self::assertClassyInvocation($source, $expected); } - public function provideIsClassyInvocation80Cases() + public function provideIsClassyInvocation80Cases(): \Generator { yield [ 'isHeaderComment($tokens, $index)); } - public function provideCommentsCases() + public function provideCommentsCases(): array { return [ 'discover all 4 comments for the 1st comment with slash' => [ @@ -167,7 +167,7 @@ public function testHeaderComment(string $code, int $index): void static::assertTrue($analyzer->isHeaderComment($tokens, $index)); } - public function provideHeaderCommentCases() + public function provideHeaderCommentCases(): array { return [ ['isHeaderComment($tokens, $index)); } - public function provideNotHeaderCommentCases() + public function provideNotHeaderCommentCases(): array { return [ ['isBeforeStructuralElement($tokens, $index)); } - public function providePhpdocCandidateCases() + public function providePhpdocCandidateCases(): array { return [ ['isBeforeStructuralElement($tokens, $index)); } - public function provideNotPhpdocCandidateCases() + public function provideNotPhpdocCandidateCases(): array { return [ ['isBeforeStructuralElement($tokens, $index)); } - public function providePhpdocCandidatePhp74Cases() + public function providePhpdocCandidatePhp74Cases(): array { return [ [' $x + 1;'], @@ -340,7 +340,7 @@ public function testPhpdocCandidatePhp80(string $code): void static::assertTrue($analyzer->isBeforeStructuralElement($tokens, $index)); } - public function providePhpdocCandidatePhp80Cases() + public function providePhpdocCandidatePhp80Cases(): array { return [ ['isGlobalFunctionCall($tokens, $index)); } - public function provideIsGlobalFunctionCallCases() + public function provideIsGlobalFunctionCallCases(): \Generator { yield '1' => [ false, @@ -313,7 +313,7 @@ public function testIsGlobalFunctionCallPhp74(bool $isFunctionIndex, string $cod static::assertSame($isFunctionIndex, $analyzer->isGlobalFunctionCall($tokens, $index)); } - public function provideIsGlobalFunctionCallPhp74Cases() + public function provideIsGlobalFunctionCallPhp74Cases(): \Generator { yield [ false, @@ -334,7 +334,7 @@ public function testIsGlobalFunctionCallPhp80(bool $isFunctionIndex, string $cod static::assertSame($isFunctionIndex, $analyzer->isGlobalFunctionCall($tokens, $index)); } - public function provideIsGlobalFunctionCallPhp80Cases() + public function provideIsGlobalFunctionCallPhp80Cases(): \Generator { yield [ true, @@ -388,7 +388,7 @@ public function testFunctionReturnTypeInfo(string $code, int $methodIndex, $expe static::assertSame(serialize($expected), serialize($actual)); } - public function provideFunctionsWithArgumentsCases() + public function provideFunctionsWithArgumentsCases(): \Generator { yield from [ ['getFunctionArguments($tokens, $methodIndex))); } - public function provideFunctionsWithArgumentsPhp74Cases() + public function provideFunctionsWithArgumentsPhp74Cases(): \Generator { yield from [ [' null;', 1, []], @@ -627,7 +627,7 @@ public function testFunctionReturnTypeInfoPhp74(string $code, int $methodIndex, static::assertSame(serialize($expected), serialize($actual)); } - public function provideFunctionsWithReturnTypePhp74Cases() + public function provideFunctionsWithReturnTypePhp74Cases(): \Generator { yield [' null;', 1, null]; yield [' null;', 1, null]; @@ -651,7 +651,7 @@ public function testIsTheSameClassCall(bool $isTheSameClassCall, string $code, i static::assertSame($isTheSameClassCall, $analyzer->isTheSameClassCall($tokens, $index)); } - public function provideIsTheSameClassCallCases() + public function provideIsTheSameClassCallCases(): \Generator { $template = 'getFunctionArguments($tokens, $methodIndex))); } - public function provideFunctionsWithArgumentsPhp80Cases() + public function provideFunctionsWithArgumentsPhp80Cases(): \Generator { yield [' new ArgumentAnalysis( diff --git a/tests/Tokenizer/Analyzer/GotoLabelAnalyzerTest.php b/tests/Tokenizer/Analyzer/GotoLabelAnalyzerTest.php index 750694c6121..8d592631168 100644 --- a/tests/Tokenizer/Analyzer/GotoLabelAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/GotoLabelAnalyzerTest.php @@ -43,7 +43,7 @@ public function testGotoLabelAnalyzerTest(string $source, array $expectedTrue): } } - public function provideIsClassyInvocationCases() + public function provideIsClassyInvocationCases(): \Generator { yield from [ 'no candidates' => [ diff --git a/tests/Tokenizer/Analyzer/NamespaceUsesAnalyzerTest.php b/tests/Tokenizer/Analyzer/NamespaceUsesAnalyzerTest.php index 103df2b475a..246728c1ee6 100644 --- a/tests/Tokenizer/Analyzer/NamespaceUsesAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/NamespaceUsesAnalyzerTest.php @@ -43,7 +43,7 @@ public function testUsesFromTokens(string $code, array $expected): void ); } - public function provideNamespaceUsesCases() + public function provideNamespaceUsesCases(): array { return [ ['doTestCode(true, $code); } - public static function provideReferenceCases() + public static function provideReferenceCases(): \Generator { yield ['doTestCode(false, $code); } - public static function provideNonReferenceCases() + public static function provideNonReferenceCases(): \Generator { yield ['getSwitchAnalysis($tokens, $index)))); } - public static function provideGettingSwitchAnalysisCases() + public static function provideGettingSwitchAnalysisCases(): \Generator { yield 'two cases' => [ new SwitchAnalysis(7, 46, [new CaseAnalysis(12), new CaseAnalysis(39)]), diff --git a/tests/Tokenizer/Analyzer/WhitespacesAnalyzerTest.php b/tests/Tokenizer/Analyzer/WhitespacesAnalyzerTest.php index f34761148d6..cfb0fd0d388 100644 --- a/tests/Tokenizer/Analyzer/WhitespacesAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/WhitespacesAnalyzerTest.php @@ -35,7 +35,7 @@ public function testIndent(string $code, string $indent, int $index): void static::assertSame($indent, WhitespacesAnalyzer::detectIndent($tokens, $index)); } - public function provideIndentCases() + public function provideIndentCases(): \Generator { yield ['getConstants() as $name => $value) { - $cases[] = [$name, $value]; + yield [$name, $value]; } - - return $cases; } private function getConstants() diff --git a/tests/Tokenizer/Generator/NamespacedStringTokenGeneratorTest.php b/tests/Tokenizer/Generator/NamespacedStringTokenGeneratorTest.php index bf4a531e8c7..293e785701c 100644 --- a/tests/Tokenizer/Generator/NamespacedStringTokenGeneratorTest.php +++ b/tests/Tokenizer/Generator/NamespacedStringTokenGeneratorTest.php @@ -42,7 +42,7 @@ static function (Token $token) { ); } - public function provideGeneratorCases() + public function provideGeneratorCases(): array { return [ ['test', ['test']], diff --git a/tests/Tokenizer/Resolver/TypeShortNameResolverTest.php b/tests/Tokenizer/Resolver/TypeShortNameResolverTest.php index c3bbd8c4ba0..f98e1a79bd7 100644 --- a/tests/Tokenizer/Resolver/TypeShortNameResolverTest.php +++ b/tests/Tokenizer/Resolver/TypeShortNameResolverTest.php @@ -36,7 +36,7 @@ public function testResolver(string $code, string $type, string $expected): void static::assertSame($expected, $resolver->resolve($tokens, $type)); } - public function provideResolverCases() + public function provideResolverCases(): array { return [ [ diff --git a/tests/Tokenizer/TokenTest.php b/tests/Tokenizer/TokenTest.php index 497f9cd6004..32b41896d8d 100644 --- a/tests/Tokenizer/TokenTest.php +++ b/tests/Tokenizer/TokenTest.php @@ -39,7 +39,7 @@ public function testConstructorValidation($input): void new Token($input); } - public function provideConstructorValidationCases() + public function provideConstructorValidationCases(): array { return [ [null], @@ -75,7 +75,7 @@ public function testIsCast(Token $token, bool $isCast): void static::assertSame($isCast, $token->isCast()); } - public function provideIsCastCases() + public function provideIsCastCases(): array { return [ [$this->getBraceToken(), false], @@ -98,7 +98,7 @@ public function testIsClassy(Token $token, bool $isClassy): void static::assertSame($isClassy, $token->isClassy()); } - public function provideIsClassyCases() + public function provideIsClassyCases(): array { return [ [$this->getBraceToken(), false], @@ -117,7 +117,7 @@ public function testIsComment(Token $token, bool $isComment): void static::assertSame($isComment, $token->isComment()); } - public function provideIsCommentCases() + public function provideIsCommentCases(): \Generator { yield from [ [$this->getBraceToken(), false], @@ -140,7 +140,7 @@ public function testIsObjectOperator(Token $token, bool $isObjectOperator): void static::assertSame($isObjectOperator, $token->isObjectOperator()); } - public function provideIsObjectOperatorCases() + public function provideIsObjectOperatorCases(): \Generator { yield from [ [$this->getBraceToken(), false], @@ -193,7 +193,7 @@ public function testIsMagicConstant(?int $tokenId, string $content, bool $isCons static::assertSame($isConstant, $token->isMagicConstant()); } - public function provideMagicConstantCases() + public function provideMagicConstantCases(): \Generator { $cases = [ [T_CLASS_C, '__CLASS__'], @@ -207,15 +207,13 @@ public function provideMagicConstantCases() ]; foreach ($cases as $case) { - $cases[] = [$case[0], strtolower($case[1])]; + yield [$case[0], strtolower($case[1])]; } foreach ([$this->getForeachToken(), $this->getBraceToken()] as $token) { - $cases[] = [$token->getId(), $token->getContent(), false]; - $cases[] = [$token->getId(), strtolower($token->getContent()), false]; + yield [$token->getId(), $token->getContent(), false]; + yield [$token->getId(), strtolower($token->getContent()), false]; } - - return $cases; } /** @@ -226,7 +224,7 @@ public function testIsNativeConstant(Token $token, bool $isNativeConstant): void static::assertSame($isNativeConstant, $token->isNativeConstant()); } - public function provideIsNativeConstantCases() + public function provideIsNativeConstantCases(): array { return [ [$this->getBraceToken(), false], @@ -252,7 +250,7 @@ public function testIsWhitespace(Token $token, bool $isWhitespace, ?string $whit } } - public function provideIsWhitespaceCases() + public function provideIsWhitespaceCases(): array { return [ [$this->getBraceToken(), false], @@ -285,7 +283,7 @@ public function testCreatingToken($prototype, ?int $expectedId, ?string $expecte static::assertSame($expectedIsArray, $token->isArray()); } - public function provideCreatingTokenCases() + public function provideCreatingTokenCases(): array { return [ [[T_FOREACH, 'foreach'], T_FOREACH, 'foreach', true], @@ -314,7 +312,7 @@ public function testEquals(Token $token, bool $equals, $other, bool $caseSensiti static::assertSame($equals, $token->equals($other, $caseSensitive)); } - public function provideEqualsCases() + public function provideEqualsCases(): array { $brace = $this->getBraceToken(); $function = new Token([T_FUNCTION, 'function', 1]); @@ -368,7 +366,7 @@ public function testEqualsAny(bool $equalsAny, array $other, bool $caseSensitive static::assertSame($equalsAny, $token->equalsAny($other, $caseSensitive)); } - public function provideEqualsAnyCases() + public function provideEqualsAnyCases(): array { $brace = $this->getBraceToken(); $foreach = $this->getForeachToken(); @@ -395,7 +393,7 @@ public function testIsKeyCaseSensitive(bool $isKeyCaseSensitive, $caseSensitive, static::assertSame($isKeyCaseSensitive, Token::isKeyCaseSensitive($caseSensitive, $key)); } - public function provideIsKeyCaseSensitiveCases() + public function provideIsKeyCaseSensitiveCases(): array { return [ [true, true, 0], @@ -422,7 +420,7 @@ public function testTokenGetNameForId(?string $expected, int $id): void static::assertSame($expected, Token::getNameForId($id)); } - public function provideTokenGetNameCases() + public function provideTokenGetNameCases(): array { return [ [ @@ -448,7 +446,7 @@ public function testGetName(Token $token, ?string $expected = null): void static::assertSame($expected, $token->getName()); } - public function provideGetNameCases() + public function provideGetNameCases(): \Generator { yield [ new Token([T_FUNCTION, 'function', 1]), @@ -474,7 +472,7 @@ public function testToArray(Token $token, array $expected): void static::assertSame($expected, $token->toArray()); } - public function provideToArrayCases() + public function provideToArrayCases(): \Generator { yield [ new Token([T_FUNCTION, 'function', 1]), @@ -510,22 +508,22 @@ public function provideToArrayCases() ]; } - private function getBraceToken() + private function getBraceToken(): Token { return new Token($this->getBraceTokenPrototype()); } - private function getBraceTokenPrototype() + private function getBraceTokenPrototype(): string { return '('; } - private function getForeachToken() + private function getForeachToken(): Token { return new Token($this->getForeachTokenPrototype()); } - private function getForeachTokenPrototype() + private function getForeachTokenPrototype(): array { static $prototype = [T_FOREACH, 'foreach']; diff --git a/tests/Tokenizer/TokensAnalyzerTest.php b/tests/Tokenizer/TokensAnalyzerTest.php index 71a5c8ccb17..b0db6ae48d8 100644 --- a/tests/Tokenizer/TokensAnalyzerTest.php +++ b/tests/Tokenizer/TokensAnalyzerTest.php @@ -53,7 +53,7 @@ public function testGetClassyElements(array $expectedElements, string $source): ); } - public function provideGetClassyElementsCases() + public function provideGetClassyElementsCases(): \Generator { yield 'trait import' => [ [ @@ -499,7 +499,7 @@ public function testIsAnonymousClass(string $source, array $expected): void } } - public function provideIsAnonymousClassCases() + public function provideIsAnonymousClassCases(): array { return [ [ @@ -541,7 +541,7 @@ public function testIsLambda(string $source, array $expected): void } } - public function provideIsLambdaCases() + public function provideIsLambdaCases(): array { return [ [ @@ -605,7 +605,7 @@ public function testIsLambda74(string $source, array $expected): void } } - public function provideIsLambda74Cases() + public function provideIsLambda74Cases(): array { return [ [ @@ -632,7 +632,7 @@ public function testIsLambda71(string $source, array $expected): void } } - public function provideIsLambda71Cases() + public function provideIsLambda71Cases(): array { return [ [ @@ -686,7 +686,7 @@ public function testIsLambda80(string $source, array $expected): void } } - public function provideIsLambda80Cases() + public function provideIsLambda80Cases(): array { return [ [ @@ -739,7 +739,7 @@ public function testIsConstantInvocation(string $source, array $expected): void $this->doIsConstantInvocationTest($source, $expected); } - public function provideIsConstantInvocationCases() + public function provideIsConstantInvocationCases(): array { return [ [ @@ -914,7 +914,7 @@ public function testIsConstantInvocation71(string $source, array $expected): voi $this->doIsConstantInvocationTest($source, $expected); } - public function provideIsConstantInvocation71Cases() + public function provideIsConstantInvocation71Cases(): array { return [ [ @@ -957,7 +957,7 @@ public function testIsConstantInvocationPhp80(string $source, array $expected): $this->doIsConstantInvocationTest($source, $expected); } - public function provideIsConstantInvocationPhp80Cases() + public function provideIsConstantInvocationPhp80Cases(): \Generator { yield [ 'b?->c;', @@ -1032,7 +1032,7 @@ public function testIsUnarySuccessorOperator(string $source, array $expected): v } } - public function provideIsUnarySuccessorOperatorCases() + public function provideIsUnarySuccessorOperatorCases(): array { return [ [ @@ -1090,7 +1090,7 @@ public function testIsUnaryPredecessorOperator(string $source, array $expected): } } - public function provideIsUnaryPredecessorOperatorCases() + public function provideIsUnaryPredecessorOperatorCases(): array { return [ [ @@ -1172,7 +1172,7 @@ public function testIsBinaryOperator(string $source, array $expected): void } } - public function provideIsBinaryOperatorCases() + public function provideIsBinaryOperatorCases(): \Generator { $cases = [ [ @@ -1332,7 +1332,7 @@ public function testIsArray(string $source, int $tokenIndex, bool $isMultiLineAr static::assertSame($isMultiLineArray, $tokensAnalyzer->isArrayMultiLine($tokenIndex), sprintf('Expected %sto be a multiline array', $isMultiLineArray ? '' : 'not ')); } - public function provideIsArrayCases() + public function provideIsArrayCases(): array { return [ [ @@ -1415,7 +1415,7 @@ public function testIsArray71(string $source, array $tokenIndexes): void } } - public function provideIsArray71Cases() + public function provideIsArray71Cases(): array { return [ [ @@ -1448,7 +1448,7 @@ public function testIsBinaryOperator71(string $source, array $expected): void } } - public function provideIsBinaryOperator71Cases() + public function provideIsBinaryOperator71Cases(): array { return [ [ @@ -1475,7 +1475,7 @@ public function testIsBinaryOperator74(string $source, array $expected): void } } - public function provideIsBinaryOperator74Cases() + public function provideIsBinaryOperator74Cases(): array { return [ [ @@ -1544,7 +1544,7 @@ public function testIsMultiLineArrayException(string $source, int $tokenIndex): $tokensAnalyzer->isArrayMultiLine($tokenIndex); } - public function provideArrayExceptionsCases() + public function provideArrayExceptionsCases(): array { return [ ['isBlockMultiline($tokens, $tokenIndex)); } - public static function provideIsBlockMultilineCases() + public static function provideIsBlockMultilineCases(): \Generator { yield [ false, @@ -1619,7 +1619,7 @@ public function testGetFunctionProperties(string $source, int $index, array $exp static::assertSame($expected, $attributes); } - public function provideGetFunctionPropertiesCases() + public function provideGetFunctionPropertiesCases(): array { $defaultAttributes = [ 'visibility' => null, @@ -1762,7 +1762,7 @@ public function testGetImportUseIndexes(array $expected, string $input, bool $pe static::assertSame($expected, $tokensAnalyzer->getImportUseIndexes($perNamespace)); } - public function provideGetImportUseIndexesCases() + public function provideGetImportUseIndexesCases(): array { return [ [ @@ -1852,7 +1852,7 @@ public function testGetImportUseIndexesPHP72(array $expected, string $input, boo static::assertSame($expected, $tokensAnalyzer->getImportUseIndexes($perNamespace)); } - public function provideGetImportUseIndexesPHP72Cases() + public function provideGetImportUseIndexesPHP72Cases(): array { return [ [ @@ -1963,7 +1963,7 @@ public function testIsSuperGlobal(bool $expected, string $source, int $index): v static::assertSame($expected, $tokensAnalyzer->isSuperGlobal($index)); } - public function provideIsSuperGlobalCases() + public function provideIsSuperGlobalCases(): array { $superNames = [ '$_COOKIE', diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index c85cfa39aa2..a8f7905ae33 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -49,7 +49,6 @@ public function testReadFromCacheAfterClearing(): void /** * @param Token[] $sequence - * @param int $start * @param null|array|bool $caseSensitive * * @dataProvider provideFindSequenceCases @@ -82,7 +81,7 @@ public function testFindSequence( ); } - public function provideFindSequenceCases() + public function provideFindSequenceCases(): array { return [ [ @@ -297,7 +296,7 @@ public function testFindSequenceException(string $message, array $sequence): voi $tokens->findSequence($sequence); } - public function provideFindSequenceExceptionCases() + public function provideFindSequenceExceptionCases(): array { $emptyToken = new Token(''); @@ -358,7 +357,7 @@ public function testMonolithicPhpDetection(string $source, bool $isMonolithic): static::assertSame($isMonolithic, $tokens->isMonolithicPhp()); } - public function provideMonolithicPhpDetectionCases() + public function provideMonolithicPhpDetectionCases(): array { return [ ["isMonolithicPhp()); } - public function provideShortOpenTagMonolithicPhpDetectionCases() + public function provideShortOpenTagMonolithicPhpDetectionCases(): array { return [ ["isMonolithicPhp()); } - public function provideShortOpenTagEchoMonolithicPhpDetectionCases() + public function provideShortOpenTagEchoMonolithicPhpDetectionCases(): array { return [ ["getId()); - /** @var array $found */ $found = $tokens->findGivenKind([T_CLASS, T_FUNCTION]); static::assertCount(2, $found); static::assertArrayHasKey(T_CLASS, $found); @@ -523,7 +521,7 @@ public function testClearTokenAndMergeSurroundingWhitespace(string $source, arra } } - public function provideGetClearTokenAndMergeSurroundingWhitespaceCases() + public function provideGetClearTokenAndMergeSurroundingWhitespaceCases(): array { $clearToken = new Token(''); @@ -644,7 +642,7 @@ public function testTokenOfKindSibling( static::assertSame($expectedIndex, $tokens->getTokenOfKindSibling($index, $direction, $findTokens, $caseSensitive)); } - public function provideTokenOfKindSiblingCases() + public function provideTokenOfKindSiblingCases(): array { return [ // find next cases @@ -681,7 +679,7 @@ public function testFindBlockEnd(int $expectedIndex, string $source, int $type, static::assertFindBlockEnd($expectedIndex, $source, $type, $searchIndex); } - public function provideFindBlockEndCases() + public function provideFindBlockEndCases(): array { return [ [4, 'isEmptyAt(0), $token->toJson()); } - public function provideIsEmptyCases() + public function provideIsEmptyCases(): array { return [ [new Token(''), true], @@ -883,7 +881,7 @@ public function testEnsureWhitespaceAtIndex(string $expected, string $input, int static::assertTokens(Tokens::fromCode($expected), $tokens); } - public function provideEnsureWhitespaceAtIndexCases() + public function provideEnsureWhitespaceAtIndexCases(): array { return [ [ @@ -1036,20 +1034,18 @@ public function __construct($name) /** * @dataProvider provideRemoveLeadingWhitespaceCases - * - * @param string $input */ public function testRemoveLeadingWhitespace(int $index, ?string $whitespaces, string $expected, string $input = null): void { Tokens::clearCache(); - $tokens = Tokens::fromCode(null === $input ? $expected : $input); + $tokens = Tokens::fromCode($input ?? $expected); $tokens->removeLeadingWhitespace($index, $whitespaces); static::assertSame($expected, $tokens->generateCode()); } - public function provideRemoveLeadingWhitespaceCases() + public function provideRemoveLeadingWhitespaceCases(): array { return [ [ @@ -1104,29 +1100,25 @@ public function provideRemoveLeadingWhitespaceCases() /** * @dataProvider provideRemoveTrailingWhitespaceCases - * - * @param string $input */ public function testRemoveTrailingWhitespace(int $index, ?string $whitespaces, string $expected, string $input = null): void { Tokens::clearCache(); - $tokens = Tokens::fromCode(null === $input ? $expected : $input); + $tokens = Tokens::fromCode($input ?? $expected); $tokens->removeTrailingWhitespace($index, $whitespaces); static::assertSame($expected, $tokens->generateCode()); } - public function provideRemoveTrailingWhitespaceCases() + public function provideRemoveTrailingWhitespaceCases(): \Generator { - $cases = []; $leadingCases = $this->provideRemoveLeadingWhitespaceCases(); + foreach ($leadingCases as $leadingCase) { $leadingCase[0] -= 2; - $cases[] = $leadingCase; + yield $leadingCase; } - - return $cases; } public function testRemovingLeadingWhitespaceWithEmptyTokenInCollection(): void @@ -1204,7 +1196,7 @@ public function testDetectBlockType(?array $expected, string $code, int $index): static::assertSame($expected, Tokens::detectBlockType($tokens[$index])); } - public function provideDetectBlockTypeCases() + public function provideDetectBlockTypeCases(): \Generator { yield [ [ @@ -1265,7 +1257,7 @@ public function testOverrideRange(array $expected, string $code, int $indexStart self::assertTokens(Tokens::fromArray($expected), $tokens); } - public function provideOverrideRangeCases() + public function provideOverrideRangeCases(): \Generator { // typically done by transformers, here we test the reverse @@ -1384,7 +1376,7 @@ public function testGetMeaningfulTokenSibling(?int $expectIndex, int $index, int static::assertSame($expectIndex, $tokens->getMeaningfulTokenSibling($index, $direction)); } - public function provideGetMeaningfulTokenSiblingCases() + public function provideGetMeaningfulTokenSiblingCases(): \Generator { yield [null, 0, 1, 'doTest($source, $expectedTokens); } - public function provideProcessCases() + public function provideProcessCases(): \Generator { yield [' [ @@ -216,7 +216,7 @@ public function testProcess80(string $source, array $expectedTokens = []): void ); } - public static function provideProcess80Cases() + public static function provideProcess80Cases(): array { return [ 'dynamic property brace open/close' => [ diff --git a/tests/Tokenizer/Transformer/ImportTransformerTest.php b/tests/Tokenizer/Transformer/ImportTransformerTest.php index bc6a48a7a92..1cff37a3fb4 100644 --- a/tests/Tokenizer/Transformer/ImportTransformerTest.php +++ b/tests/Tokenizer/Transformer/ImportTransformerTest.php @@ -43,7 +43,7 @@ public function testProcess(string $source, array $expectedTokens = []): void ); } - public function provideProcessCases() + public function provideProcessCases(): array { return [ [ diff --git a/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php b/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php index a793a8e4e7f..25d55ae5221 100644 --- a/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php +++ b/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php @@ -164,7 +164,7 @@ public function testPriority(array $expected, string $source): void self::assertTokens(Tokens::fromArray($expected), Tokens::fromCode($source)); } - public function providePriorityCases() + public function providePriorityCases(): array { return [ [ diff --git a/tests/Tokenizer/Transformer/NamedArgumentTransformerTest.php b/tests/Tokenizer/Transformer/NamedArgumentTransformerTest.php index 4adb18620da..ae6278afd98 100644 --- a/tests/Tokenizer/Transformer/NamedArgumentTransformerTest.php +++ b/tests/Tokenizer/Transformer/NamedArgumentTransformerTest.php @@ -34,7 +34,7 @@ public function testProcess(string $source, array $expectedTokens): void $this->doTest($source, $expectedTokens); } - public function provideProcessCases() + public function provideProcessCases(): \Generator { yield 'function call' => [ ' [ ' [ @@ -252,7 +252,7 @@ public function testProcess71(string $source, array $expectedTokens): void ); } - public function provideProcess71Cases() + public function provideProcess71Cases(): array { return [ [ @@ -368,7 +368,7 @@ public function testProcess72(string $source, array $expectedTokens): void ); } - public function provideProcess72Cases() + public function provideProcess72Cases(): array { return [ [ diff --git a/tests/Tokenizer/Transformer/TypeAlternationTransformerTest.php b/tests/Tokenizer/Transformer/TypeAlternationTransformerTest.php index 66bb5ac053b..c36c1c2437b 100644 --- a/tests/Tokenizer/Transformer/TypeAlternationTransformerTest.php +++ b/tests/Tokenizer/Transformer/TypeAlternationTransformerTest.php @@ -40,7 +40,7 @@ public function testProcess(string $source, array $expectedTokens = []): void ); } - public function provideProcessCases() + public function provideProcessCases(): array { return [ 'no namespace' => [ @@ -97,7 +97,7 @@ public function testProcess80(string $source, array $expectedTokens): void $this->doTest($source, $expectedTokens); } - public function provideProcess80Cases() + public function provideProcess80Cases(): \Generator { yield 'arrow function' => [ ' $item * 2;', diff --git a/tests/Tokenizer/Transformer/TypeColonTransformerTest.php b/tests/Tokenizer/Transformer/TypeColonTransformerTest.php index 4769ae9a6c6..a2bde32caf0 100644 --- a/tests/Tokenizer/Transformer/TypeColonTransformerTest.php +++ b/tests/Tokenizer/Transformer/TypeColonTransformerTest.php @@ -40,7 +40,7 @@ public function testProcess(string $source, array $expectedTokens = []): void ); } - public function provideProcessCases() + public function provideProcessCases(): array { return [ [ @@ -98,7 +98,7 @@ public function testProcessPhp74(string $source, array $expectedTokens = []): vo ); } - public function provideProcessPhp74Cases() + public function provideProcessPhp74Cases(): array { return [ [ diff --git a/tests/Tokenizer/Transformer/UseTransformerTest.php b/tests/Tokenizer/Transformer/UseTransformerTest.php index 97ce8eeaf13..14290ebc2e4 100644 --- a/tests/Tokenizer/Transformer/UseTransformerTest.php +++ b/tests/Tokenizer/Transformer/UseTransformerTest.php @@ -44,7 +44,7 @@ public function testProcess(string $source, array $expectedTokens = []): void ); } - public function provideProcessCases() + public function provideProcessCases(): array { return [ [ @@ -147,7 +147,7 @@ public function testFix72(string $source, array $expectedTokens = []): void ); } - public function provideFix72Cases() + public function provideFix72Cases(): array { return [ [ diff --git a/tests/Tokenizer/Transformer/WhitespacyCommentTransformerTest.php b/tests/Tokenizer/Transformer/WhitespacyCommentTransformerTest.php index 68894aaf59b..60dba6018d4 100644 --- a/tests/Tokenizer/Transformer/WhitespacyCommentTransformerTest.php +++ b/tests/Tokenizer/Transformer/WhitespacyCommentTransformerTest.php @@ -41,7 +41,7 @@ public function testProcess(string $source, array $expectedTokens): void } } - public function provideProcessCases() + public function provideProcessCases(): array { return [ [ diff --git a/tests/Tokenizer/TransformersTest.php b/tests/Tokenizer/TransformersTest.php index a4b37f94864..7f4b3c2b346 100644 --- a/tests/Tokenizer/TransformersTest.php +++ b/tests/Tokenizer/TransformersTest.php @@ -40,7 +40,7 @@ public function testTransform(string $input, array $expectedTokenKinds): void } } - public function provideTransformCases() + public function provideTransformCases(): array { return [ 'use trait after complex string variable' => [ diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 6fc776146f2..34b7c32778c 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -120,7 +120,7 @@ public function testCalculateTrailingWhitespaceIndent(string $spaces, $input): v static::assertSame($spaces, Utils::calculateTrailingWhitespaceIndent($token)); } - public function provideCalculateTrailingWhitespaceIndentCases() + public function provideCalculateTrailingWhitespaceIndentCases(): array { return [ [' ', [T_WHITESPACE, "\n\n "]], @@ -157,7 +157,7 @@ public function testStableSort( ); } - public function provideStableSortCases() + public function provideStableSortCases(): array { return [ [ @@ -222,7 +222,7 @@ public function testNaturalLanguageJoinWithBackticks(string $joined, array $name static::assertSame($joined, Utils::naturalLanguageJoinWithBackticks($names)); } - public function provideNaturalLanguageJoinWithBackticksCases() + public function provideNaturalLanguageJoinWithBackticksCases(): array { return [ [ diff --git a/tests/WhitespacesFixerConfigTest.php b/tests/WhitespacesFixerConfigTest.php index 2c20dff62df..b8a3bdc86d5 100644 --- a/tests/WhitespacesFixerConfigTest.php +++ b/tests/WhitespacesFixerConfigTest.php @@ -41,7 +41,7 @@ public function testCases(string $indent, string $lineEnding, ?string $exception static::assertSame($lineEnding, $config->getLineEnding()); } - public function provideTestCases() + public function provideTestCases(): array { return [ [' ', "\n"], From 98eed9f27b943ac28e811b0ca7b89f89a40d62c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Fri, 20 Aug 2021 16:05:00 +0200 Subject: [PATCH 40/80] Detect renamed rules in configuration resolver --- src/Console/ConfigurationResolver.php | 89 +++++++++++++++++++-- tests/Console/ConfigurationResolverTest.php | 52 ++++++++++-- 2 files changed, 125 insertions(+), 16 deletions(-) diff --git a/src/Console/ConfigurationResolver.php b/src/Console/ConfigurationResolver.php index 849ffd1ae4d..7f4129f067c 100644 --- a/src/Console/ConfigurationResolver.php +++ b/src/Console/ConfigurationResolver.php @@ -23,6 +23,7 @@ use PhpCsFixer\Cache\Signature; use PhpCsFixer\ConfigInterface; use PhpCsFixer\ConfigurationException\InvalidConfigurationException; +use PhpCsFixer\Console\Command\HelpCommand; use PhpCsFixer\Console\Report\FixReport\ReporterFactory; use PhpCsFixer\Console\Report\FixReport\ReporterInterface; use PhpCsFixer\Differ\DifferInterface; @@ -675,6 +676,7 @@ private function validateRules(array $rules): void * @see RuleSet::resolveSet() */ $ruleSet = []; + foreach ($rules as $key => $value) { if (\is_int($key)) { throw new InvalidConfigurationException(sprintf('Missing value for "%s" rule/set.', $value)); @@ -682,6 +684,7 @@ private function validateRules(array $rules): void $ruleSet[$key] = true; } + $ruleSet = new RuleSet($ruleSet); /** @var string[] $configuredFixers */ @@ -700,19 +703,89 @@ private function validateRules(array $rules): void ); if (\count($unknownFixers)) { - $matcher = new WordMatcher($availableFixers); + $renamedRules = [ + 'blank_line_before_return' => [ + 'new_name' => 'blank_line_before_statement', + 'config' => ['statements' => ['return']], + ], + 'final_static_access' => [ + 'new_name' => 'self_static_accessor', + ], + 'hash_to_slash_comment' => [ + 'new_name' => 'single_line_comment_style', + 'config' => ['comment_types' => ['hash']], + ], + 'lowercase_constants' => [ + 'new_name' => 'constant_case', + 'config' => ['case' => 'lower'], + ], + 'no_extra_consecutive_blank_lines' => [ + 'new_name' => 'no_extra_blank_lines', + ], + 'no_multiline_whitespace_before_semicolons' => [ + 'new_name' => 'multiline_whitespace_before_semicolons', + ], + 'no_short_echo_tag' => [ + 'new_name' => 'echo_tag_syntax', + 'config' => ['format' => 'long'], + ], + 'php_unit_ordered_covers' => [ + 'new_name' => 'phpdoc_order_by_value', + 'config' => ['annotations' => ['covers']], + ], + 'phpdoc_inline_tag' => [ + 'new_name' => 'general_phpdoc_tag_rename, phpdoc_inline_tag_normalizer and phpdoc_tag_type', + ], + 'pre_increment' => [ + 'new_name' => 'increment_style', + 'config' => ['style' => 'pre'], + ], + 'psr0' => [ + 'new_name' => 'psr_autoloading', + 'config' => ['dir' => 'x'], + ], + 'psr4' => [ + 'new_name' => 'psr_autoloading', + ], + 'silenced_deprecation_error' => [ + 'new_name' => 'error_suppression', + ], + 'trailing_comma_in_multiline_array' => [ + 'new_name' => 'trailing_comma_in_multiline', + 'config' => ['elements' => ['arrays']], + ], + ]; $message = 'The rules contain unknown fixers: '; + $hasOldRule = false; + foreach ($unknownFixers as $unknownFixer) { - $alternative = $matcher->match($unknownFixer); - $message .= sprintf( - '"%s"%s, ', - $unknownFixer, - null === $alternative ? '' : ' (did you mean "'.$alternative.'"?)' - ); + if (isset($renamedRules[$unknownFixer])) { // Check if present as old renamed rule + $hasOldRule = true; + $message .= sprintf( + '"%s" is renamed (did you mean "%s"?%s), ', + $unknownFixer, + $renamedRules[$unknownFixer]['new_name'], + isset($renamedRules[$unknownFixer]['config']) ? ' (note: use configuration "'.HelpCommand::toString($renamedRules[$unknownFixer]['config']).'")' : '' + ); + } else { // Go to normal matcher if it is not a renamed rule + $matcher = new WordMatcher($availableFixers); + $alternative = $matcher->match($unknownFixer); + $message .= sprintf( + '"%s"%s, ', + $unknownFixer, + null === $alternative ? '' : ' (did you mean "'.$alternative.'"?)' + ); + } + } + + $message = substr($message, 0, -2).'.'; + + if ($hasOldRule) { + $message .= "\nFor more info about updating see: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.0.0/UPGRADE-v3.md#renamed-ruless."; } - throw new InvalidConfigurationException(substr($message, 0, -2).'.'); + throw new InvalidConfigurationException($message); } foreach ($fixers as $fixer) { diff --git a/tests/Console/ConfigurationResolverTest.php b/tests/Console/ConfigurationResolverTest.php index 677778c979e..fb0f6e4936b 100644 --- a/tests/Console/ConfigurationResolverTest.php +++ b/tests/Console/ConfigurationResolverTest.php @@ -954,17 +954,53 @@ public function testResolveRulesWithOption(): void ); } + /** + * @param string[] $rules + * + * @dataProvider provideRenamedRulesCases + */ + public function testResolveRenamedRulesWithUnknownRules(string $expectedMessage, array $rules): void + { + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage($expectedMessage); + + $resolver = $this->createConfigurationResolver(['rules' => implode(',', $rules)]); + $resolver->getRules(); + } + + public function provideRenamedRulesCases(): \Generator + { + yield 'with config' => [ + 'The rules contain unknown fixers: "blank_line_before_return" is renamed (did you mean "blank_line_before_statement"? (note: use configuration "[\'statements\' => [\'return\']]")). +For more info about updating see: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.0.0/UPGRADE-v3.md#renamed-ruless.', + ['blank_line_before_return'], + ]; + + yield 'without config' => [ + 'The rules contain unknown fixers: "final_static_access" is renamed (did you mean "self_static_accessor"?). +For more info about updating see: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.0.0/UPGRADE-v3.md#renamed-ruless.', + ['final_static_access'], + ]; + + yield [ + 'The rules contain unknown fixers: "hash_to_slash_comment" is renamed (did you mean "single_line_comment_style"? (note: use configuration "[\'comment_types\' => [\'hash\']]")). +For more info about updating see: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.0.0/UPGRADE-v3.md#renamed-ruless.', + ['hash_to_slash_comment'], + ]; + + yield 'both renamed and unknown' => [ + 'The rules contain unknown fixers: "final_static_access" is renamed (did you mean "self_static_accessor"?), "binary_operator_space" (did you mean "binary_operator_spaces"?). +For more info about updating see: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v3.0.0/UPGRADE-v3.md#renamed-ruless.', + ['final_static_access', 'binary_operator_space'], + ]; + } + public function testResolveRulesWithUnknownRules(): void { - $this->expectException( - \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class - ); - $this->expectExceptionMessage( - 'The rules contain unknown fixers: "bar", "binary_operator_space" (did you mean "binary_operator_spaces"?).' - ); + $this->expectException(InvalidConfigurationException::class); + $this->expectExceptionMessage('The rules contain unknown fixers: "bar", "binary_operator_space" (did you mean "binary_operator_spaces"?).'); $resolver = $this->createConfigurationResolver(['rules' => 'braces,-bar,binary_operator_space']); - $resolver->getRules(); } @@ -1073,7 +1109,7 @@ public function testResolveConfigFileOverridesDefault(): void public function testDeprecationOfPassingOtherThanNoOrYes(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage('Expected "yes" or "no" for option "allow-risky", got "yes please".'); $resolver = $this->createConfigurationResolver(['allow-risky' => 'yes please']); From c905dc720d6200493b1272a792d23bbafd8241ee Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Tue, 31 Aug 2021 18:13:17 +0200 Subject: [PATCH 41/80] bump year --- logo.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logo.md b/logo.md index b08e6a818dd..16fc6d14e0e 100644 --- a/logo.md +++ b/logo.md @@ -1,3 +1,3 @@ -The logo is © 2010-2014 Sensio Labs. +The logo is © 2010-2021 Sensio Labs. Original resolution can be found at https://github.com/PHP-CS-Fixer/logo . From de18cb2b3f4fd3944c1f0e18373800029946750d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Guzm=C3=A1n=20Maeso?= Date: Tue, 31 Aug 2021 18:46:27 +0200 Subject: [PATCH 42/80] Reduce full path code for consistency in other parts with InvalidConfigurationException --- tests/ConfigTest.php | 3 ++- .../InvalidFixerConfigurationExceptionTest.php | 3 ++- tests/Console/Command/FixCommandTest.php | 5 +++-- .../ConstantNotation/NativeConstantInvocationFixerTest.php | 7 ++++--- .../FunctionNotation/NativeFunctionInvocationFixerTest.php | 5 +++-- .../Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php | 5 +++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 7e578a1267a..db597921458 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -15,6 +15,7 @@ namespace PhpCsFixer\Tests; use PhpCsFixer\Config; +use PhpCsFixer\ConfigurationException\InvalidConfigurationException; use PhpCsFixer\Console\Application; use PhpCsFixer\Console\Command\FixCommand; use PhpCsFixer\Console\ConfigurationResolver; @@ -80,7 +81,7 @@ public function testConfigRulesUsingJsonMethod(): void public function testConfigRulesUsingInvalidJson(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $config = new Config(); $configResolver = new ConfigurationResolver( diff --git a/tests/ConfigurationException/InvalidFixerConfigurationExceptionTest.php b/tests/ConfigurationException/InvalidFixerConfigurationExceptionTest.php index bfa39a7b8aa..13b99c218e9 100644 --- a/tests/ConfigurationException/InvalidFixerConfigurationExceptionTest.php +++ b/tests/ConfigurationException/InvalidFixerConfigurationExceptionTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\ConfigurationException; +use PhpCsFixer\ConfigurationException\InvalidConfigurationException; use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Console\Command\FixCommandExitStatusCalculator; use PhpCsFixer\Tests\TestCase; @@ -31,7 +32,7 @@ public function testIsInvalidArgumentException(): void { $exception = new InvalidFixerConfigurationException('foo', 'I cannot do that, Dave.'); - static::assertInstanceOf(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class, $exception); + static::assertInstanceOf(InvalidConfigurationException::class, $exception); } public function testDefaults(): void diff --git a/tests/Console/Command/FixCommandTest.php b/tests/Console/Command/FixCommandTest.php index c113e9cc491..76a7e01f55e 100644 --- a/tests/Console/Command/FixCommandTest.php +++ b/tests/Console/Command/FixCommandTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Console\Command; +use PhpCsFixer\ConfigurationException\InvalidConfigurationException; use PhpCsFixer\Console\Application; use PhpCsFixer\Console\Command\FixCommand; use PhpCsFixer\Tests\TestCase; @@ -31,7 +32,7 @@ final class FixCommandTest extends TestCase public function testEmptyRulesValue(): void { $this->expectException( - \PhpCsFixer\ConfigurationException\InvalidConfigurationException::class + InvalidConfigurationException::class ); $this->expectExceptionMessageMatches( '#^Empty rules value is not allowed\.$#' @@ -44,7 +45,7 @@ public function testEmptyRulesValue(): void public function testEmptyFormatValue(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage('Expected "yes" or "no" for option "using-cache", got "not today".'); $cmdTester = $this->doTestExecute( diff --git a/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php b/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php index 14734ac2b99..2f8cbed2a33 100644 --- a/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php +++ b/tests/Fixer/ConstantNotation/NativeConstantInvocationFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\ConstantNotation; +use PhpCsFixer\ConfigurationException\InvalidConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -29,7 +30,7 @@ public function testConfigureRejectsUnknownConfigurationKey(): void { $key = 'foo'; - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf('[native_constant_invocation] Invalid configuration: The option "%s" does not exist.', $key)); $this->fixer->configure([ @@ -44,7 +45,7 @@ public function testConfigureRejectsUnknownConfigurationKey(): void */ public function testConfigureRejectsInvalidExcludeConfigurationElement($element): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf( 'Each element must be a non-empty, trimmed string, got "%s" instead.', \is_object($element) ? \get_class($element) : \gettype($element) @@ -64,7 +65,7 @@ public function testConfigureRejectsInvalidExcludeConfigurationElement($element) */ public function testConfigureRejectsInvalidIncludeConfigurationElement($element): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf( 'Each element must be a non-empty, trimmed string, got "%s" instead.', \is_object($element) ? \get_class($element) : \gettype($element) diff --git a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php index beca7fb7813..ab7f8446ccc 100644 --- a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php +++ b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\FunctionNotation; +use PhpCsFixer\ConfigurationException\InvalidConfigurationException; use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; @@ -32,7 +33,7 @@ public function testConfigureRejectsUnknownConfigurationKey(): void { $key = 'foo'; - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf( '[native_function_invocation] Invalid configuration: The option "%s" does not exist.', $key @@ -50,7 +51,7 @@ public function testConfigureRejectsUnknownConfigurationKey(): void */ public function testConfigureRejectsInvalidConfigurationElement($element): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf( 'Each element must be a non-empty, trimmed string, got "%s" instead.', \is_object($element) ? \get_class($element) : \gettype($element) diff --git a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php index 75261d7d086..c79e27fcc27 100644 --- a/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\Phpdoc; +use PhpCsFixer\ConfigurationException\InvalidConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\WhitespacesFixerConfig; @@ -30,7 +31,7 @@ public function testConfigureRejectsUnknownConfigurationKey(): void { $key = 'foo'; - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessage(sprintf( '[phpdoc_add_missing_param_annotation] Invalid configuration: The option "%s" does not exist.', $key @@ -48,7 +49,7 @@ public function testConfigureRejectsUnknownConfigurationKey(): void */ public function testConfigureRejectsInvalidConfigurationValue($value, string $expectedMessage): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidConfigurationException::class); + $this->expectException(InvalidConfigurationException::class); $this->expectExceptionMessageMatches($expectedMessage); $this->fixer->configure([ From aeff4e3c4ed9cee172721c129ed90937adcd6b7a Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Wed, 1 Sep 2021 11:11:10 +0200 Subject: [PATCH 43/80] NoAliasFunctionsFixer - remove dir -> getdir mapping --- src/Fixer/Alias/NoAliasFunctionsFixer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Fixer/Alias/NoAliasFunctionsFixer.php b/src/Fixer/Alias/NoAliasFunctionsFixer.php index 2579b2509e8..3a18ee63962 100644 --- a/src/Fixer/Alias/NoAliasFunctionsFixer.php +++ b/src/Fixer/Alias/NoAliasFunctionsFixer.php @@ -36,7 +36,6 @@ final class NoAliasFunctionsFixer extends AbstractFixer implements ConfigurableF { private const SETS = [ '@internal' => [ - 'dir' => 'getdir', 'diskfreespace' => 'disk_free_space', 'checkdnsrr' => 'dns_check_record', From 3a18c3205eee02317b813d42833ca7d96f55dab8 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Wed, 1 Sep 2021 18:52:37 +0200 Subject: [PATCH 44/80] TokensAnalyzer - isConstantInvocation PHP 8 issue --- src/Fixer/Import/NoUnusedImportsFixer.php | 7 +++-- src/Tokenizer/TokensAnalyzer.php | 2 +- .../Fixer/Import/NoUnusedImportsFixerTest.php | 13 ++++++++++ tests/Tokenizer/TokensAnalyzerTest.php | 26 +++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/Fixer/Import/NoUnusedImportsFixer.php b/src/Fixer/Import/NoUnusedImportsFixer.php index 9142123180d..0d4bbaaed9e 100644 --- a/src/Fixer/Import/NoUnusedImportsFixer.php +++ b/src/Fixer/Import/NoUnusedImportsFixer.php @@ -104,12 +104,13 @@ private function isImportUsed(Tokens $tokens, NamespaceAnalysis $namespace, Name $gotoLabelAnalyzer = new GotoLabelAnalyzer(); $tokensNotBeforeFunctionCall = [T_NEW]; - // @TODO: drop condition when PHP 8.0+ is required - if (\defined('T_ATTRIBUTE')) { + + if (\defined('T_ATTRIBUTE')) { // @TODO: drop condition when PHP 8.0+ is required $tokensNotBeforeFunctionCall[] = T_ATTRIBUTE; } $namespaceEndIndex = $namespace->getScopeEndIndex(); + for ($index = $namespace->getScopeStartIndex(); $index <= $namespaceEndIndex; ++$index) { if (isset($ignoredIndexes[$index])) { $index = $ignoredIndexes[$index]; @@ -190,6 +191,7 @@ private function removeUseDeclaration(Tokens $tokens, NamespaceUseAnalysis $useD // when multi line white space keep the line feed if the previous token is a comment $prevIndex = $tokens->getPrevNonWhitespace($index); + if ($tokens[$prevIndex]->isComment()) { $content = $tokens[$index]->getContent(); $tokens[$index] = new Token([T_WHITESPACE, substr($content, strrpos($content, "\n"))]); // preserve indent only @@ -224,6 +226,7 @@ private function removeUseDeclaration(Tokens $tokens, NamespaceUseAnalysis $useD } $nextIndex = $tokens->getNonEmptySibling($useDeclaration->getEndIndex(), 1); + if (null === $nextIndex) { return; } diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index 01d7eacf383..58ec6050b5f 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -313,7 +313,7 @@ public function isConstantInvocation(int $index): bool $prevIndex = $this->tokens->getPrevMeaningfulToken($index); - if ($this->tokens[$prevIndex]->isGivenKind([T_AS, T_CLASS, T_CONST, T_DOUBLE_COLON, T_FUNCTION, T_GOTO, CT::T_GROUP_IMPORT_BRACE_OPEN, T_INTERFACE, T_TRAIT, CT::T_TYPE_COLON]) || $this->tokens[$prevIndex]->isObjectOperator()) { + if ($this->tokens[$prevIndex]->isGivenKind([T_AS, T_CLASS, T_CONST, T_DOUBLE_COLON, T_FUNCTION, T_GOTO, CT::T_GROUP_IMPORT_BRACE_OPEN, T_INTERFACE, T_TRAIT, CT::T_TYPE_COLON, CT::T_TYPE_ALTERNATION]) || $this->tokens[$prevIndex]->isObjectOperator()) { return false; } diff --git a/tests/Fixer/Import/NoUnusedImportsFixerTest.php b/tests/Fixer/Import/NoUnusedImportsFixerTest.php index 739f62226e1..a01c2efe89c 100644 --- a/tests/Fixer/Import/NoUnusedImportsFixerTest.php +++ b/tests/Fixer/Import/NoUnusedImportsFixerTest.php @@ -1394,5 +1394,18 @@ public function providePhp80Cases() use Bar; try {} catch (Foo | Bar) {}', ]; + + yield [ + ' false, 5 => false, 8 => false, 11 => false, 15 => false, 18 => false], ], + [ + ' false, 16 => false, 21 => false], + ], ]; } @@ -959,6 +969,22 @@ public function testIsConstantInvocationPhp80(string $source, array $expected): public function provideIsConstantInvocationPhp80Cases(): \Generator { + yield [ + ' false, 16 => false, 21 => false, 23 => false], + ]; + + yield [ + ' false, 8 => false, 10 => false], + ]; + yield [ 'b?->c;', [3 => false, 5 => false], From a65559994fbe5b6c5917b7b7041c15ec2bdbf1b4 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Wed, 1 Sep 2021 19:02:51 +0200 Subject: [PATCH 45/80] NoUnusedImportsFixer - use in attribute --- src/Fixer/Import/NoUnusedImportsFixer.php | 26 ++++++++++++++++--- .../Fixer/Import/NoUnusedImportsFixerTest.php | 17 +++++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/Fixer/Import/NoUnusedImportsFixer.php b/src/Fixer/Import/NoUnusedImportsFixer.php index 0d4bbaaed9e..359dbb849be 100644 --- a/src/Fixer/Import/NoUnusedImportsFixer.php +++ b/src/Fixer/Import/NoUnusedImportsFixer.php @@ -24,6 +24,7 @@ use PhpCsFixer\Tokenizer\Analyzer\GotoLabelAnalyzer; use PhpCsFixer\Tokenizer\Analyzer\NamespacesAnalyzer; use PhpCsFixer\Tokenizer\Analyzer\NamespaceUsesAnalyzer; +use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\Tokenizer\TokensAnalyzer; @@ -105,26 +106,45 @@ private function isImportUsed(Tokens $tokens, NamespaceAnalysis $namespace, Name $tokensNotBeforeFunctionCall = [T_NEW]; - if (\defined('T_ATTRIBUTE')) { // @TODO: drop condition when PHP 8.0+ is required + $attributeIsDefined = \defined('T_ATTRIBUTE'); + + if ($attributeIsDefined) { // @TODO: drop condition when PHP 8.0+ is required $tokensNotBeforeFunctionCall[] = T_ATTRIBUTE; } $namespaceEndIndex = $namespace->getScopeEndIndex(); + $inAttribute = false; for ($index = $namespace->getScopeStartIndex(); $index <= $namespaceEndIndex; ++$index) { + $token = $tokens[$index]; + + if ($attributeIsDefined && $token->isGivenKind(T_ATTRIBUTE)) { + $inAttribute = true; + + continue; + } + + if ($attributeIsDefined && $token->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { + $inAttribute = false; + + continue; + } + if (isset($ignoredIndexes[$index])) { $index = $ignoredIndexes[$index]; continue; } - $token = $tokens[$index]; - if ($token->isGivenKind(T_STRING)) { if (0 !== strcasecmp($import->getShortName(), $token->getContent())) { continue; } + if ($inAttribute) { + return true; + } + $prevMeaningfulToken = $tokens[$tokens->getPrevMeaningfulToken($index)]; if ($prevMeaningfulToken->isGivenKind(T_NAMESPACE)) { diff --git a/tests/Fixer/Import/NoUnusedImportsFixerTest.php b/tests/Fixer/Import/NoUnusedImportsFixerTest.php index a01c2efe89c..a998d36e208 100644 --- a/tests/Fixer/Import/NoUnusedImportsFixerTest.php +++ b/tests/Fixer/Import/NoUnusedImportsFixerTest.php @@ -1395,7 +1395,7 @@ public function providePhp80Cases() try {} catch (Foo | Bar) {}', ]; - yield [ + yield 'union return' => [ ' [ + " '%regex.uuid%'], methods: ['POST']), + IsGranted('ROLE_USER'), + JsonSchema('Public/Basket/addItem.json'), +] +class Foo {} +", + ]; } } From 6348e87c1ea2b00dafbe20fc1b16a2cb90b3ad66 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Wed, 1 Sep 2021 16:26:19 +0200 Subject: [PATCH 46/80] TokensAnalyzer - isAnonymousClass bug on PHP8 --- src/Runner/Runner.php | 2 +- src/Tokenizer/TokensAnalyzer.php | 15 ++-- tests/Fixtures/Integration/misc/PHP8_0.test | 3 +- tests/Tokenizer/TokensAnalyzerTest.php | 76 +++++++++++++-------- 4 files changed, 61 insertions(+), 35 deletions(-) diff --git a/src/Runner/Runner.php b/src/Runner/Runner.php index 337ee107b62..b96dc91b578 100644 --- a/src/Runner/Runner.php +++ b/src/Runner/Runner.php @@ -220,7 +220,7 @@ private function fixFile(\SplFileInfo $file, LintingResultInterface $lintingResu } // We need to check if content was changed and then applied changes. - // But we can't simple check $appliedFixers, because one fixer may revert + // But we can't simply check $appliedFixers, because one fixer may revert // work of other and both of them will mark collection as changed. // Therefore we need to check if code hashes changed. if ($oldHash !== $newHash) { diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index 58ec6050b5f..7818b366314 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -133,7 +133,7 @@ public function isArrayMultiLine(int $index): bool $tokens = $this->tokens; - // Skip only when its an array, for short arrays we need the brace for correct + // Skip only when it's an array, for short arrays we need the brace for correct // level counting if ($tokens[$index]->isGivenKind(T_ARRAY)) { $index = $tokens->getNextMeaningfulToken($index); @@ -266,7 +266,14 @@ public function isAnonymousClass(int $index): bool return false; } - return $this->tokens[$this->tokens->getPrevMeaningfulToken($index)]->isGivenKind(T_NEW); + $index = $this->tokens->getPrevMeaningfulToken($index); + + while ($this->tokens[$index]->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { + $index = $this->tokens->findBlockStart(Tokens::BLOCK_TYPE_ATTRIBUTE, $index); + $index = $this->tokens->getPrevMeaningfulToken($index); + } + + return $this->tokens[$index]->isGivenKind(T_NEW); } /** @@ -389,7 +396,7 @@ public function isConstantInvocation(int $index): bool } /** - * Checks if there is an unary successor operator under given index. + * Checks if there is a unary successor operator under given index. */ public function isUnarySuccessorOperator(int $index): bool { @@ -415,7 +422,7 @@ public function isUnarySuccessorOperator(int $index): bool } /** - * Checks if there is an unary predecessor operator under given index. + * Checks if there is a unary predecessor operator under given index. */ public function isUnaryPredecessorOperator(int $index): bool { diff --git a/tests/Fixtures/Integration/misc/PHP8_0.test b/tests/Fixtures/Integration/misc/PHP8_0.test index b2f80daaee3..2da5a153f9b 100644 --- a/tests/Fixtures/Integration/misc/PHP8_0.test +++ b/tests/Fixtures/Integration/misc/PHP8_0.test @@ -46,8 +46,7 @@ class PostsController } } -$object = new #[ExampleAttribute] class() -{ +$object = new #[ExampleAttribute] class() { #[ExampleAttribute] public function foo(#[ExampleAttribute] $bar): void { diff --git a/tests/Tokenizer/TokensAnalyzerTest.php b/tests/Tokenizer/TokensAnalyzerTest.php index 703e9452a9b..4866ab4affe 100644 --- a/tests/Tokenizer/TokensAnalyzerTest.php +++ b/tests/Tokenizer/TokensAnalyzerTest.php @@ -499,34 +499,54 @@ public function testIsAnonymousClass(string $source, array $expected): void } } - public function provideIsAnonymousClassCases(): array + public function provideIsAnonymousClassCases(): \Generator { - return [ - [ - ' false], - ], - [ - ' true], - ], - [ - ' true], - ], - [ - ' false, 19 => true], - ], - [ - 'a) implements B{}) extends C{};', - [7 => true, 11 => true], - ], - [ - ' false], - ], + yield [ + ' false], + ]; + + yield [ + ' true], ]; + + yield [ + ' true], + ]; + + yield [ + ' false, 19 => true], + ]; + + yield [ + 'a) implements B{}) extends C{};', + [7 => true, 11 => true], + ]; + + yield [ + ' false], + ]; + + yield [ + ' true], + ]; + + if (\PHP_VERSION_ID >= 80000) { + yield [ + ' true], + ]; + + yield [ + ' true], + ]; + } } /** @@ -1393,7 +1413,7 @@ public function provideIsArrayCases(): array ' array(5, 6, 7), -8 => new \Exception(\'Ellow\') +8 => new \Exception(\'Hello\') ); ', 2, true, @@ -1403,7 +1423,7 @@ public function provideIsArrayCases(): array ' [9, 10, 11], -12 => new \Exception(\'Ellow\') +12 => new \Exception(\'Hello\') ); ', 2, true, From 3db05b60c964efb10d50d6a44a506cd40bea37a4 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Fri, 6 Aug 2021 12:08:41 +0200 Subject: [PATCH 47/80] EmptyLoopConditionFixer - introduction --- .../empty_loop_condition.rst | 56 +++++ doc/rules/index.rst | 2 + .../EmptyLoopConditionFixer.php | 203 ++++++++++++++++++ .../Whitespace/NoExtraBlankLinesFixer.php | 2 +- .../Whitespace/NoTrailingWhitespaceFixer.php | 2 +- tests/AutoReview/FixerFactoryTest.php | 2 + .../EmptyLoopBodyFixerTest.php | 2 +- .../EmptyLoopConditionFixerTest.php | 148 +++++++++++++ .../PhpdocToParamTypeFixerTest.php | 3 +- ...y_loop_condition,no_extra_blank_lines.test | 25 +++ ...loop_condition,no_trailing_whitespace.test | 11 + 11 files changed, 452 insertions(+), 4 deletions(-) create mode 100644 doc/rules/control_structure/empty_loop_condition.rst create mode 100644 src/Fixer/ControlStructure/EmptyLoopConditionFixer.php create mode 100644 tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php create mode 100644 tests/Fixtures/Integration/priority/empty_loop_condition,no_extra_blank_lines.test create mode 100644 tests/Fixtures/Integration/priority/empty_loop_condition,no_trailing_whitespace.test diff --git a/doc/rules/control_structure/empty_loop_condition.rst b/doc/rules/control_structure/empty_loop_condition.rst new file mode 100644 index 00000000000..024bfc80d51 --- /dev/null +++ b/doc/rules/control_structure/empty_loop_condition.rst @@ -0,0 +1,56 @@ +============================= +Rule ``empty_loop_condition`` +============================= + +Empty loop-condition must be in configured style. + +Configuration +------------- + +``style`` +~~~~~~~~~ + +Style of empty loop-condition. + +Allowed values: ``'for'``, ``'while'`` + +Default value: ``'while'`` + +Examples +-------- + +Example #1 +~~~~~~~~~~ + +*Default* configuration. + +.. code-block:: diff + + --- Original + +++ New + 'for']``. + +.. code-block:: diff + + --- Original + +++ New + `_ Empty loop-body must be in configured style. +- `empty_loop_condition <./control_structure/empty_loop_condition.rst>`_ + Empty loop-condition must be in configured style. - `include <./control_structure/include.rst>`_ Include/Require and file path should be divided with a single space. File path should not be placed under brackets. - `no_alternative_syntax <./control_structure/no_alternative_syntax.rst>`_ diff --git a/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php b/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php new file mode 100644 index 00000000000..8d7a9f2a167 --- /dev/null +++ b/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php @@ -0,0 +1,203 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Fixer\ControlStructure; + +use PhpCsFixer\AbstractFixer; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; +use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; +use PhpCsFixer\FixerDefinition\CodeSample; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\Token; +use PhpCsFixer\Tokenizer\Tokens; + +/** + * @author SpacePossum + */ +final class EmptyLoopConditionFixer extends AbstractFixer implements ConfigurableFixerInterface +{ + private const STYLE_FOR = 'for'; + + private const STYLE_WHILE = 'while'; + + private const TOKEN_LOOP_KINDS = [T_FOR, T_WHILE]; + + /** + * {@inheritdoc} + */ + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition( + 'Empty loop-condition must be in configured style.', + [ + new CodeSample(" 'for']), + ] + ); + } + + /** + * {@inheritdoc} + * + * Must run before NoExtraBlankLinesFixer, NoTrailingWhitespaceFixer. + */ + public function getPriority(): int + { + return 1; + } + + /** + * {@inheritdoc} + */ + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isAnyTokenKindsFound(self::TOKEN_LOOP_KINDS); + } + + /** + * {@inheritdoc} + */ + protected function applyFix(\SplFileInfo $file, Tokens $tokens): void + { + if (self::STYLE_WHILE === $this->configuration['style']) { + $candidateLoopKinds = [T_FOR, T_WHILE]; + $replacement = [new Token([T_WHILE, 'while']), new Token('('), new Token([T_STRING, 'true']), new Token(')')]; + + $fixLoop = static function (int $index, int $openIndex, int $endIndex) use ($tokens, $replacement): void { + if (self::isForLoopWithEmptyCondition($tokens, $index, $openIndex, $endIndex)) { + self::clearNotCommentsInRange($tokens, $index, $endIndex); + self::cloneAndInsert($tokens, $index, $replacement); + } elseif (self::isWhileLoopWithEmptyCondition($tokens, $index, $openIndex, $endIndex)) { + $doIndex = self::getDoIndex($tokens, $index); + + if (null !== $doIndex) { + self::clearNotCommentsInRange($tokens, $index, $tokens->getNextMeaningfulToken($endIndex)); // clear including `;` + $tokens->clearAt($doIndex); + self::cloneAndInsert($tokens, $doIndex, $replacement); + } + } + }; + } else { // self::STYLE_FOR + $candidateLoopKinds = [T_WHILE]; + $replacement = [new Token([T_FOR, 'for']), new Token('('), new Token(';'), new Token(';'), new Token(')')]; + + $fixLoop = static function (int $index, int $openIndex, int $endIndex) use ($tokens, $replacement): void { + if (!self::isWhileLoopWithEmptyCondition($tokens, $index, $openIndex, $endIndex)) { + return; + } + + $doIndex = self::getDoIndex($tokens, $index); + + if (null === $doIndex) { + self::clearNotCommentsInRange($tokens, $index, $endIndex); + self::cloneAndInsert($tokens, $index, $replacement); + } else { + self::clearNotCommentsInRange($tokens, $index, $tokens->getNextMeaningfulToken($endIndex)); // clear including `;` + $tokens->clearAt($doIndex); + self::cloneAndInsert($tokens, $doIndex, $replacement); + } + }; + } + + for ($index = $tokens->count() - 1; $index > 0; --$index) { + if ($tokens[$index]->isGivenKind($candidateLoopKinds)) { + $openIndex = $tokens->getNextTokenOfKind($index, ['(']); // proceed to open '(' + $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); // proceed to close ')' + $fixLoop($index, $openIndex, $endIndex); // fix loop if needed + } + } + } + + /** + * {@inheritdoc} + */ + protected function createConfigurationDefinition(): FixerConfigurationResolverInterface + { + return new FixerConfigurationResolver([ + (new FixerOptionBuilder('style', 'Style of empty loop-condition.')) + ->setAllowedTypes(['string']) + ->setAllowedValues([self::STYLE_WHILE, self::STYLE_FOR]) + ->setDefault(self::STYLE_WHILE) + ->getOption(), + ]); + } + + private static function clearNotCommentsInRange(Tokens $tokens, int $indexStart, int $indexEnd): void + { + for ($i = $indexStart; $i <= $indexEnd; ++$i) { + if (!$tokens[$i]->isComment()) { + $tokens->clearTokenAndMergeSurroundingWhitespace($i); + } + } + } + + /** + * @param Token[] $replacement + */ + private static function cloneAndInsert(Tokens $tokens, int $index, array $replacement): void + { + $replacementClones = []; + + foreach ($replacement as $token) { + $replacementClones[] = clone $token; + } + + $tokens->insertAt($index, $replacementClones); + } + + private static function getDoIndex(Tokens $tokens, int $index): ?int + { + $endIndex = $tokens->getPrevMeaningfulToken($index); + + if (!$tokens[$endIndex]->equals('}')) { + return null; + } + + $startIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $endIndex); + $index = $tokens->getPrevMeaningfulToken($startIndex); + + return null === $index || !$tokens[$index]->isGivenKind(T_DO) ? null : $index; + } + + private static function isForLoopWithEmptyCondition(Tokens $tokens, int $index, int $openIndex, int $endIndex): bool + { + if (!$tokens[$index]->isGivenKind(T_FOR)) { + return false; + } + + $index = $tokens->getNextMeaningfulToken($openIndex); + + if (null === $index || !$tokens[$index]->equals(';')) { + return false; + } + + $index = $tokens->getNextMeaningfulToken($index); + + return null !== $index && $tokens[$index]->equals(';') && $endIndex === $tokens->getNextMeaningfulToken($index); + } + + private static function isWhileLoopWithEmptyCondition(Tokens $tokens, int $index, int $openIndex, int $endIndex): bool + { + if (!$tokens[$index]->isGivenKind(T_WHILE)) { + return false; + } + + $index = $tokens->getNextMeaningfulToken($openIndex); + + return null !== $index && $tokens[$index]->equals([T_STRING, 'true']) && $endIndex === $tokens->getNextMeaningfulToken($index); + } +} diff --git a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php index 283b5303359..5f043b2852d 100644 --- a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php +++ b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php @@ -272,7 +272,7 @@ class Bar * {@inheritdoc} * * Must run before BlankLineBeforeStatementFixer. - * Must run after ClassAttributesSeparationFixer, CombineConsecutiveUnsetsFixer, EmptyLoopBodyFixer, FunctionToConstantFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoEmptyStatementFixer, NoUnusedImportsFixer, NoUselessElseFixer, NoUselessReturnFixer, NoUselessSprintfFixer. + * Must run after ClassAttributesSeparationFixer, CombineConsecutiveUnsetsFixer, EmptyLoopBodyFixer, EmptyLoopConditionFixer, FunctionToConstantFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoEmptyStatementFixer, NoUnusedImportsFixer, NoUselessElseFixer, NoUselessReturnFixer, NoUselessSprintfFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php b/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php index ff132cf4a2d..e9ac58eee84 100644 --- a/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php +++ b/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php @@ -46,7 +46,7 @@ public function getDefinition(): FixerDefinitionInterface /** * {@inheritdoc} * - * Must run after CombineConsecutiveIssetsFixer, CombineConsecutiveUnsetsFixer, EmptyLoopBodyFixer, FunctionToConstantFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoEmptyStatementFixer, NoUnneededControlParenthesesFixer, NoUselessElseFixer, TernaryToElvisOperatorFixer. + * Must run after CombineConsecutiveIssetsFixer, CombineConsecutiveUnsetsFixer, EmptyLoopBodyFixer, EmptyLoopConditionFixer, FunctionToConstantFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoEmptyStatementFixer, NoUnneededControlParenthesesFixer, NoUselessElseFixer, TernaryToElvisOperatorFixer. */ public function getPriority(): int { diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 24e0134f70c..e71db1f3ded 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -102,6 +102,8 @@ public function provideFixersPriorityCases() [$fixers['empty_loop_body'], $fixers['braces']], [$fixers['empty_loop_body'], $fixers['no_extra_blank_lines']], [$fixers['empty_loop_body'], $fixers['no_trailing_whitespace']], + [$fixers['empty_loop_condition'], $fixers['no_extra_blank_lines']], + [$fixers['empty_loop_condition'], $fixers['no_trailing_whitespace']], [$fixers['escape_implicit_backslashes'], $fixers['heredoc_to_nowdoc']], [$fixers['escape_implicit_backslashes'], $fixers['single_quote']], [$fixers['explicit_string_variable'], $fixers['simple_to_complex_string_variable']], diff --git a/tests/Fixer/ControlStructure/EmptyLoopBodyFixerTest.php b/tests/Fixer/ControlStructure/EmptyLoopBodyFixerTest.php index b5532c9a99c..27a9b306d06 100644 --- a/tests/Fixer/ControlStructure/EmptyLoopBodyFixerTest.php +++ b/tests/Fixer/ControlStructure/EmptyLoopBodyFixerTest.php @@ -28,7 +28,7 @@ final class EmptyLoopBodyFixerTest extends AbstractFixerTestCase /** * @dataProvider provideFixCases */ - public function testFixConfig(string $expected, ?string $input = null, ?array $config = null): void + public function testFixConfig(string $expected, ?string $input = null, array $config = null): void { if (null === $config) { $this->doTest($expected, $input); diff --git a/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php b/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php new file mode 100644 index 00000000000..890b8e228fd --- /dev/null +++ b/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php @@ -0,0 +1,148 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Fixer\ControlStructure; + +use PhpCsFixer\Tests\Test\AbstractFixerTestCase; + +/** + * @author SpacePossum + * + * @internal + * + * @covers \PhpCsFixer\Fixer\ControlStructure\EmptyLoopConditionFixer + */ +final class EmptyLoopConditionFixerTest extends AbstractFixerTestCase +{ + /** + * @dataProvider provideFixCases + */ + public function testFixConfig(string $expected, ?string $input = null, array $config = null): void + { + if (null !== $config) { + $this->fixer->configure($config); + } + + $this->doTest($expected, $input); + } + + public function provideFixCases(): \Generator + { + yield 'from `for` to `while`' => [ + ' [ + ' [ + ' 'for'], + ]; + + yield 'from `do while` to `for`' => [ + ' 'for'], + ]; + + yield 'multiple `do while` to `while`' => [ + ' [ + ' [ + ' [ + ' 'for'], + ]; + + // space cases + yield 'lot of space' => [ + ' [ + ' 'for'], + ]; + + yield 'not empty `for` condition' => [ + ' [ + ' [ + ' 'for'], + ]; + } +} diff --git a/tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php b/tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php index e3a599a5f24..8327f60db4b 100644 --- a/tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php +++ b/tests/Fixer/FunctionNotation/PhpdocToParamTypeFixerTest.php @@ -28,7 +28,7 @@ final class PhpdocToParamTypeFixerTest extends AbstractFixerTestCase /** * @dataProvider provideFixCases */ - public function testFix(string $expected, ?string $input = null, ?int $versionSpecificFix = null, ?array $config = null): void + public function testFix(string $expected, ?string $input = null, ?int $versionSpecificFix = null, array $config = null): void { if ( null !== $input @@ -40,6 +40,7 @@ public function testFix(string $expected, ?string $input = null, ?int $versionSp $expected = $input; $input = null; } + if (null !== $config) { $this->fixer->configure($config); } diff --git a/tests/Fixtures/Integration/priority/empty_loop_condition,no_extra_blank_lines.test b/tests/Fixtures/Integration/priority/empty_loop_condition,no_extra_blank_lines.test new file mode 100644 index 00000000000..a8f21f0b690 --- /dev/null +++ b/tests/Fixtures/Integration/priority/empty_loop_condition,no_extra_blank_lines.test @@ -0,0 +1,25 @@ +--TEST-- +Integration of fixers: empty_loop_condition,no_extra_blank_lines. +--RULESET-- +{"empty_loop_condition": true, "no_extra_blank_lines": true} +--EXPECT-- + Date: Wed, 1 Sep 2021 08:50:44 +0200 Subject: [PATCH 48/80] Prepare for PHP8.1, clean ups, type hints, SCA --- src/AbstractDoctrineAnnotationFixer.php | 2 +- src/AbstractFopenFlagFixer.php | 2 - src/AbstractLinesBeforeNamespaceFixer.php | 2 +- src/AbstractNoUselessElseFixer.php | 3 - src/AbstractPhpdocTypesFixer.php | 2 +- .../InvalidConfigurationException.php | 2 - .../InvalidFixerConfigurationException.php | 2 - src/Console/Command/DescribeCommand.php | 25 +- .../Command/DescribeNameNotFoundException.php | 2 - src/Console/Command/HelpCommand.php | 5 +- src/Console/Command/SelfUpdateCommand.php | 1 - src/Console/ConfigurationResolver.php | 10 +- src/Console/Output/ErrorOutput.php | 2 - src/Console/Report/FixReport/JsonReporter.php | 14 +- .../Report/FixReport/JunitReporter.php | 4 +- .../Report/ListSetsReport/JsonReporter.php | 2 +- .../Report/ListSetsReport/TextReporter.php | 2 +- src/Differ/DiffConsoleFormatter.php | 4 +- src/Differ/UnifiedDiffer.php | 3 - src/DocBlock/Annotation.php | 4 +- src/DocBlock/DocBlock.php | 4 +- src/DocBlock/Line.php | 2 +- src/DocBlock/Tag.php | 2 +- src/DocBlock/TagComparator.php | 2 +- src/DocBlock/TypeExpression.php | 32 +- src/Documentation/DocumentationGenerator.php | 26 +- src/Error/ErrorsManager.php | 6 +- src/Fixer/Alias/ArrayPushFixer.php | 3 - src/Fixer/Alias/EregToPregFixer.php | 9 +- src/Fixer/Alias/MbStrFunctionsFixer.php | 6 +- .../NoAliasLanguageConstructCallFixer.php | 3 - src/Fixer/Alias/NoMixedEchoPrintFixer.php | 1 - src/Fixer/Alias/PowToExponentiationFixer.php | 3 - src/Fixer/Alias/RandomApiMigrationFixer.php | 6 +- src/Fixer/Alias/SetTypeToCastFixer.php | 3 - src/Fixer/ArrayNotation/ArraySyntaxFixer.php | 1 - ...tilineWhitespaceAroundDoubleArrowFixer.php | 2 +- src/Fixer/Basic/BracesFixer.php | 2 +- src/Fixer/Basic/PsrAutoloadingFixer.php | 4 +- src/Fixer/Casing/MagicMethodCasingFixer.php | 3 - .../Casing/NativeFunctionCasingFixer.php | 3 - ...tiveFunctionTypeDeclarationCasingFixer.php | 3 - src/Fixer/CastNotation/LowercaseCastFixer.php | 3 - .../ModernizeTypesCastingFixer.php | 20 +- .../CastNotation/NoShortBoolCastFixer.php | 3 - src/Fixer/CastNotation/NoUnsetCastFixer.php | 3 - .../CastNotation/ShortScalarCastFixer.php | 3 - .../ClassAttributesSeparationFixer.php | 12 +- .../ClassNotation/ClassDefinitionFixer.php | 2 - .../ClassNotation/FinalInternalClassFixer.php | 1 - ...FinalPublicMethodForAbstractClassFixer.php | 5 + .../ClassNotation/NoPhp4ConstructorFixer.php | 7 +- .../OrderedClassElementsFixer.php | 2 +- .../ClassNotation/OrderedInterfacesFixer.php | 2 +- .../ClassNotation/OrderedTraitsFixer.php | 5 +- .../ClassNotation/ProtectedToPrivateFixer.php | 3 +- .../SingleClassElementPerStatementFixer.php | 1 - .../SingleTraitInsertPerStatementFixer.php | 3 - .../ClassNotation/VisibilityRequiredFixer.php | 4 +- src/Fixer/Comment/CommentToPhpdocFixer.php | 4 +- src/Fixer/Comment/HeaderCommentFixer.php | 3 +- src/Fixer/Comment/NoEmptyCommentFixer.php | 3 - src/Fixer/ConfigurableFixerInterface.php | 1 - .../NativeConstantInvocationFixer.php | 2 +- .../ControlStructure/EmptyLoopBodyFixer.php | 3 - .../ControlStructure/NoBreakCommentFixer.php | 4 +- .../NoUnneededCurlyBracesFixer.php | 3 - .../ControlStructure/NoUselessElseFixer.php | 3 - .../SwitchCaseSemicolonToColonFixer.php | 2 - .../TrailingCommaInMultilineFixer.php | 1 + src/Fixer/ControlStructure/YodaStyleFixer.php | 12 +- .../CombineNestedDirnameFixer.php | 2 +- .../FunctionNotation/FopenFlagOrderFixer.php | 5 +- .../FunctionNotation/FopenFlagsFixer.php | 3 - .../LambdaNotUsedImportFixer.php | 3 - .../MethodArgumentSpaceFixer.php | 10 +- .../NativeFunctionInvocationFixer.php | 14 +- .../PhpdocToPropertyTypeFixer.php | 6 +- .../FunctionNotation/StaticLambdaFixer.php | 3 - .../UseArrowFunctionsFixer.php | 5 +- .../Import/GlobalNamespaceImportFixer.php | 16 +- src/Fixer/Import/GroupImportFixer.php | 8 +- src/Fixer/Import/OrderedImportsFixer.php | 3 +- .../Import/SingleImportPerStatementFixer.php | 1 - .../Import/SingleLineAfterImportsFixer.php | 2 +- .../ClassKeywordRemoveFixer.php | 4 +- .../CombineConsecutiveIssetsFixer.php | 5 +- .../CombineConsecutiveUnsetsFixer.php | 5 +- .../DeclareEqualNormalizeFixer.php | 1 - .../LanguageConstruct/DirConstantFixer.php | 8 +- .../ErrorSuppressionFixer.php | 7 +- .../FunctionToConstantFixer.php | 3 - src/Fixer/LanguageConstruct/IsNullFixer.php | 10 +- .../NoUnsetOnPropertyFixer.php | 11 +- src/Fixer/ListNotation/ListSyntaxFixer.php | 3 - .../NoBlankLinesBeforeNamespaceFixer.php | 2 +- .../SingleBlankLineBeforeNamespaceFixer.php | 2 +- src/Fixer/Naming/NoHomoglyphNamesFixer.php | 5 +- .../Operator/BinaryOperatorSpacesFixer.php | 5 +- src/Fixer/Operator/ConcatSpaceFixer.php | 1 - src/Fixer/Operator/NewWithBracesFixer.php | 2 +- src/Fixer/Operator/OperatorLinebreakFixer.php | 8 +- .../Operator/TernaryOperatorSpacesFixer.php | 2 +- .../Operator/TernaryToElvisOperatorFixer.php | 3 - .../PhpUnit/PhpUnitDedicateAssertFixer.php | 1 - .../PhpUnit/PhpUnitMethodCasingFixer.php | 2 +- src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php | 3 +- .../PhpUnit/PhpUnitTestAnnotationFixer.php | 3 - .../PhpUnitTestCaseStaticMethodCallsFixer.php | 2 +- .../Phpdoc/AlignMultilineCommentFixer.php | 3 + .../GeneralPhpdocAnnotationRemoveFixer.php | 2 +- .../Phpdoc/GeneralPhpdocTagRenameFixer.php | 4 +- .../Phpdoc/NoBlankLinesAfterPhpdocFixer.php | 2 +- src/Fixer/Phpdoc/NoEmptyPhpdocFixer.php | 3 - .../Phpdoc/NoSuperfluousPhpdocTagsFixer.php | 16 +- src/Fixer/Phpdoc/PhpdocAlignFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocIndentFixer.php | 2 +- .../Phpdoc/PhpdocInlineTagNormalizerFixer.php | 7 +- src/Fixer/Phpdoc/PhpdocLineSpanFixer.php | 19 +- src/Fixer/Phpdoc/PhpdocNoAccessFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php | 3 +- src/Fixer/Phpdoc/PhpdocNoEmptyReturnFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocNoPackageFixer.php | 2 +- .../Phpdoc/PhpdocNoUselessInheritdocFixer.php | 4 +- src/Fixer/Phpdoc/PhpdocOrderByValueFixer.php | 6 +- src/Fixer/Phpdoc/PhpdocOrderFixer.php | 2 +- .../Phpdoc/PhpdocReturnSelfReferenceFixer.php | 8 +- src/Fixer/Phpdoc/PhpdocScalarFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocSeparationFixer.php | 6 +- .../PhpdocSingleLineVarSpacingFixer.php | 2 - src/Fixer/Phpdoc/PhpdocSummaryFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocTagTypeFixer.php | 10 +- src/Fixer/Phpdoc/PhpdocToCommentFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocTrimFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocTypesFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php | 6 +- .../Phpdoc/PhpdocVarWithoutNameFixer.php | 8 +- .../ReturnNotation/NoUselessReturnFixer.php | 3 - .../ReturnNotation/ReturnAssignmentFixer.php | 5 +- .../SimplifiedNullReturnFixer.php | 2 +- ...ltilineWhitespaceBeforeSemicolonsFixer.php | 2 +- src/Fixer/Semicolon/NoEmptyStatementFixer.php | 1 - ...glelineWhitespaceBeforeSemicolonsFixer.php | 2 +- .../SemicolonAfterInstructionFixer.php | 3 - .../Semicolon/SpaceAfterSemicolonFixer.php | 3 - src/Fixer/Strict/DeclareStrictTypesFixer.php | 1 - .../Whitespace/ArrayIndentationFixer.php | 6 +- .../BlankLineBeforeStatementFixer.php | 1 - src/Fixer/Whitespace/IndentationTypeFixer.php | 4 +- src/Fixer/Whitespace/LineEndingFixer.php | 1 - .../Whitespace/NoExtraBlankLinesFixer.php | 1 - src/FixerFactory.php | 6 +- src/RuleSet/RuleSet.php | 7 +- src/RuleSet/RuleSetDescriptionInterface.php | 2 - src/RuleSet/RuleSets.php | 2 - .../Analyzer/Analysis/TypeAnalysis.php | 2 +- src/Tokenizer/Analyzer/CommentsAnalyzer.php | 1 - src/Tokenizer/Analyzer/FunctionsAnalyzer.php | 4 +- .../Analyzer/NamespaceUsesAnalyzer.php | 3 +- src/Tokenizer/Analyzer/NamespacesAnalyzer.php | 4 +- .../Resolver/TypeShortNameResolver.php | 2 +- src/Tokenizer/Token.php | 2 +- src/Tokenizer/Tokens.php | 12 +- src/Tokenizer/TokensAnalyzer.php | 9 +- .../Transformer/NameQualifiedTransformer.php | 2 - .../Transformer/NamedArgumentTransformer.php | 2 - .../Transformer/SquareBraceTransformer.php | 1 - src/Tokenizer/Transformers.php | 2 +- src/Utils.php | 10 +- src/WordMatcher.php | 1 - ...bstractDoctrineAnnotationFixerTestCase.php | 3 +- tests/AutoReview/CiConfigurationTest.php | 4 +- tests/AutoReview/CommandTest.php | 4 +- tests/AutoReview/DocumentationTest.php | 2 +- tests/AutoReview/FixerFactoryTest.php | 6 +- tests/AutoReview/ProjectCodeTest.php | 64 +-- tests/Cache/CacheTest.php | 3 +- tests/Cache/FileCacheManagerTest.php | 4 +- tests/Cache/FileHandlerTest.php | 7 +- ...dForEnvFixerConfigurationExceptionTest.php | 3 +- ...equiredFixerConfigurationExceptionTest.php | 3 +- .../Console/Command/SelfUpdateCommandTest.php | 4 +- tests/Console/ConfigurationResolverTest.php | 6 +- .../Report/FixReport/JsonReporterTest.php | 2 +- .../ListSetsReport/JsonReporterTest.php | 2 +- tests/DocBlock/AnnotationTest.php | 102 ++-- tests/DocBlock/DocBlockTest.php | 2 +- tests/DocBlock/LineTest.php | 2 +- tests/DocBlock/TagComparatorTest.php | 2 +- tests/DocBlock/TagTest.php | 2 +- tests/Fixer/Alias/ArrayPushFixerTest.php | 50 +- tests/Fixer/Alias/MbStrFunctionsFixerTest.php | 24 +- .../Fixer/Alias/NoMixedEchoPrintFixerTest.php | 3 +- .../Alias/PowToExponentiationFixerTest.php | 22 +- .../Alias/RandomApiMigrationFixerTest.php | 26 +- .../ArrayNotation/ArraySyntaxFixerTest.php | 3 +- ...neWhitespaceAroundDoubleArrowFixerTest.php | 2 +- tests/Fixer/Basic/BracesFixerTest.php | 3 +- tests/Fixer/Basic/PsrAutoloadingFixerTest.php | 4 +- .../CastNotation/CastSpacesFixerTest.php | 5 +- .../ModernizeTypesCastingFixerTest.php | 22 +- .../ClassDefinitionFixerTest.php | 18 +- .../FinalInternalClassFixerTest.php | 7 +- .../OrderedClassElementsFixerTest.php | 3 +- ...ingleClassElementPerStatementFixerTest.php | 17 +- .../VisibilityRequiredFixerTest.php | 10 +- .../Fixer/Comment/HeaderCommentFixerTest.php | 5 +- .../EmptyLoopBodyFixerTest.php | 2 +- .../NoBreakCommentFixerTest.php | 2 +- .../NoUnneededCurlyBracesFixerTest.php | 20 +- .../NoUselessElseFixerTest.php | 170 +++--- .../SwitchCaseSemicolonToColonFixerTest.php | 44 +- .../SwitchCaseSpaceFixerTest.php | 22 +- .../TrailingCommaInMultilineFixerTest.php | 3 +- .../ControlStructure/YodaStyleFixerTest.php | 51 +- ...rineAnnotationArrayAssignmentFixerTest.php | 12 +- .../FunctionDeclarationFixerTest.php | 3 +- .../MethodArgumentSpaceFixerTest.php | 18 +- .../NoSpacesAfterFunctionNameFixerTest.php | 34 +- .../NoUselessSprintfFixerTest.php | 77 ++- .../PhpdocToParamTypeFixerTest.php | 3 +- .../ReturnTypeDeclarationFixerTest.php | 3 +- .../SingleLineThrowFixerTest.php | 48 +- .../FunctionNotation/VoidReturnFixerTest.php | 2 +- tests/Fixer/Import/GroupImportFixerTest.php | 22 +- .../Import/NoLeadingImportSlashFixerTest.php | 2 - .../Fixer/Import/OrderedImportsFixerTest.php | 9 +- .../CombineConsecutiveUnsetsFixerTest.php | 20 +- .../DeclareEqualNormalizeFixerTest.php | 3 +- .../ErrorSuppressionFixerTest.php | 22 +- .../FunctionToConstantFixerTest.php | 5 +- .../NoUnsetOnPropertyFixerTest.php | 20 +- .../ListNotation/ListSyntaxFixerTest.php | 46 +- .../NoBlankLinesBeforeNamespaceFixerTest.php | 2 +- ...ingleBlankLineBeforeNamespaceFixerTest.php | 2 +- .../BinaryOperatorSpacesFixerTest.php | 9 +- tests/Fixer/Operator/ConcatSpaceFixerTest.php | 5 +- .../Operator/IncrementStyleFixerTest.php | 2 +- .../Fixer/Operator/NewWithBracesFixerTest.php | 50 +- .../StandardizeIncrementFixerTest.php | 109 ++-- .../TernaryToElvisOperatorFixerTest.php | 108 ++-- .../TernaryToNullCoalescingFixerTest.php | 40 +- .../PhpUnit/PhpUnitConstructFixerTest.php | 3 +- .../PhpUnitDedicateAssertFixerTest.php | 3 +- .../Fixer/PhpUnit/PhpUnitStrictFixerTest.php | 3 +- ...UnitTestCaseStaticMethodCallsFixerTest.php | 5 +- .../Phpdoc/AlignMultilineCommentFixerTest.php | 3 +- .../NoBlankLinesAfterPhpdocFixerTest.php | 2 +- .../NoSuperfluousPhpdocTagsFixerTest.php | 13 + .../Fixer/Phpdoc/PhpdocLineSpanFixerTest.php | 4 - .../Fixer/Phpdoc/PhpdocNoAccessFixerTest.php | 2 +- .../Phpdoc/PhpdocNoAliasTagFixerTest.php | 15 +- .../Phpdoc/PhpdocNoEmptyReturnFixerTest.php | 2 +- .../Fixer/Phpdoc/PhpdocNoPackageFixerTest.php | 2 +- tests/Fixer/Phpdoc/PhpdocOrderFixerTest.php | 2 +- .../PhpdocReturnSelfReferenceFixerTest.php | 3 +- tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php | 2 +- .../Phpdoc/PhpdocSeparationFixerTest.php | 10 +- tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php | 2 +- tests/Fixer/Phpdoc/PhpdocTrimFixerTest.php | 6 +- tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php | 5 +- .../Phpdoc/PhpdocVarWithoutNameFixerTest.php | 2 +- .../SimplifiedNullReturnFixerTest.php | 2 +- ...ineWhitespaceBeforeSemicolonsFixerTest.php | 2 +- ...ineWhitespaceBeforeSemicolonsFixerTest.php | 2 +- .../SemicolonAfterInstructionFixerTest.php | 22 +- .../Whitespace/IndentationTypeFixerTest.php | 2 +- .../Fixer/Whitespace/LineEndingFixerTest.php | 2 +- .../Whitespace/NoExtraBlankLinesFixerTest.php | 3 +- .../NoSpacesAroundOffsetFixerTest.php | 3 +- .../NoTrailingWhitespaceFixerTest.php | 22 +- .../FixerConfigurationResolverTest.php | 14 +- tests/FixerFactoryTest.php | 18 +- tests/Linter/AbstractLinterTestCase.php | 7 +- tests/PregTest.php | 6 +- tests/RuleSet/RuleSetTest.php | 2 +- tests/RuleSet/RuleSetsTest.php | 8 +- tests/Test/AbstractFixerTestCase.php | 6 +- tests/Test/AbstractIntegrationTestCase.php | 2 +- tests/Test/AbstractTransformerTestCase.php | 2 +- .../Analyzer/Analysis/TypeAnalysisTest.php | 4 +- .../Analyzer/FunctionsAnalyzerTest.php | 26 +- .../Analyzer/NamespacesAnalyzerTest.php | 112 ++-- .../NamespacedStringTokenGeneratorTest.php | 17 +- tests/Tokenizer/TokenTest.php | 2 +- tests/Tokenizer/TokensAnalyzerTest.php | 489 +++++++++--------- tests/Tokenizer/TokensTest.php | 5 - .../ConstructorPromotionTransformerTest.php | 14 +- tests/UtilsTest.php | 7 +- 289 files changed, 1632 insertions(+), 1457 deletions(-) diff --git a/src/AbstractDoctrineAnnotationFixer.php b/src/AbstractDoctrineAnnotationFixer.php index 3aa32cfe8b3..0399b0f71bb 100644 --- a/src/AbstractDoctrineAnnotationFixer.php +++ b/src/AbstractDoctrineAnnotationFixer.php @@ -79,7 +79,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn return new FixerConfigurationResolver([ (new FixerOptionBuilder('ignored_tags', 'List of tags that must not be treated as Doctrine Annotations.')) ->setAllowedTypes(['array']) - ->setAllowedValues([static function (array $values) { + ->setAllowedValues([static function (array $values): bool { foreach ($values as $value) { if (!\is_string($value)) { return false; diff --git a/src/AbstractFopenFlagFixer.php b/src/AbstractFopenFlagFixer.php index 5010cc877e1..e9d7a120cef 100644 --- a/src/AbstractFopenFlagFixer.php +++ b/src/AbstractFopenFlagFixer.php @@ -19,8 +19,6 @@ /** * @internal - * - * @author SpacePossum */ abstract class AbstractFopenFlagFixer extends AbstractFunctionReferenceFixer { diff --git a/src/AbstractLinesBeforeNamespaceFixer.php b/src/AbstractLinesBeforeNamespaceFixer.php index 0c6cf6ba7c2..9e38e6eb6bc 100644 --- a/src/AbstractLinesBeforeNamespaceFixer.php +++ b/src/AbstractLinesBeforeNamespaceFixer.php @@ -22,7 +22,7 @@ * This abstract fixer is responsible for ensuring that a certain number of * lines prefix a namespace declaration. * - * @author Graham Campbell + * @author Graham Campbell * * @internal */ diff --git a/src/AbstractNoUselessElseFixer.php b/src/AbstractNoUselessElseFixer.php index 2f6747d2b2a..7aeebb76676 100644 --- a/src/AbstractNoUselessElseFixer.php +++ b/src/AbstractNoUselessElseFixer.php @@ -16,9 +16,6 @@ use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ abstract class AbstractNoUselessElseFixer extends AbstractFixer { /** diff --git a/src/AbstractPhpdocTypesFixer.php b/src/AbstractPhpdocTypesFixer.php index 46bf4cb3cac..fa9b0bb250b 100644 --- a/src/AbstractPhpdocTypesFixer.php +++ b/src/AbstractPhpdocTypesFixer.php @@ -22,7 +22,7 @@ /** * This abstract fixer provides a base for fixers to fix types in PHPDoc. * - * @author Graham Campbell + * @author Graham Campbell * * @internal */ diff --git a/src/ConfigurationException/InvalidConfigurationException.php b/src/ConfigurationException/InvalidConfigurationException.php index 001c724ee96..ab1185f09b8 100644 --- a/src/ConfigurationException/InvalidConfigurationException.php +++ b/src/ConfigurationException/InvalidConfigurationException.php @@ -19,8 +19,6 @@ /** * Exceptions of this type are thrown on misconfiguration of the Fixer. * - * @author SpacePossum - * * @internal * @final Only internal extending this class is supported */ diff --git a/src/ConfigurationException/InvalidFixerConfigurationException.php b/src/ConfigurationException/InvalidFixerConfigurationException.php index b62ad0dd94e..0750eee86a9 100644 --- a/src/ConfigurationException/InvalidFixerConfigurationException.php +++ b/src/ConfigurationException/InvalidFixerConfigurationException.php @@ -19,8 +19,6 @@ /** * Exception thrown by Fixers on misconfiguration. * - * @author SpacePossum - * * @internal * @final Only internal extending this class is supported */ diff --git a/src/Console/Command/DescribeCommand.php b/src/Console/Command/DescribeCommand.php index 66464a025ce..4fa4e01cb5f 100644 --- a/src/Console/Command/DescribeCommand.php +++ b/src/Console/Command/DescribeCommand.php @@ -41,7 +41,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal */ @@ -193,7 +192,14 @@ private function describeRule(OutputInterface $output, string $name): void $line = '* '.OutputFormatter::escape($option->getName()).''; $allowed = HelpCommand::getDisplayableAllowedValues($option); - if (null !== $allowed) { + if (null === $allowed) { + $allowed = array_map( + static function (string $type): string { + return ''.$type.''; + }, + $option->getAllowedTypes() + ); + } else { foreach ($allowed as &$value) { if ($value instanceof AllowedValueSubset) { $value = 'a subset of '.HelpCommand::toString($value->getAllowedValues()).''; @@ -201,18 +207,9 @@ private function describeRule(OutputInterface $output, string $name): void $value = ''.HelpCommand::toString($value).''; } } - } else { - $allowed = array_map( - static function (string $type) { - return ''.$type.''; - }, - $option->getAllowedTypes() - ); } - if (null !== $allowed) { - $line .= ' ('.implode(', ', $allowed).')'; - } + $line .= ' ('.implode(', ', $allowed).')'; $description = Preg::replace('/(`.+?`)/', '$1', OutputFormatter::escape($option->getDescription())); $line .= ': '.lcfirst(Preg::replace('/\.$/', '', $description)).'; '; @@ -245,7 +242,7 @@ static function (string $type) { } /** @var CodeSampleInterface[] $codeSamples */ - $codeSamples = array_filter($definition->getCodeSamples(), static function (CodeSampleInterface $codeSample) { + $codeSamples = array_filter($definition->getCodeSamples(), static function (CodeSampleInterface $codeSample): bool { if ($codeSample instanceof VersionSpecificCodeSampleInterface) { return $codeSample->isSuitableFor(\PHP_VERSION_ID); } @@ -421,7 +418,7 @@ private function replaceRstLinks(string $content): string static function (array $matches) { return Preg::replaceCallback( '/`(.*)<(.*)>`_/', - static function (array $matches) { + static function (array $matches): string { return $matches[1].'('.$matches[2].')'; }, $matches[1] diff --git a/src/Console/Command/DescribeNameNotFoundException.php b/src/Console/Command/DescribeNameNotFoundException.php index b5a5355b610..8ddab2a308f 100644 --- a/src/Console/Command/DescribeNameNotFoundException.php +++ b/src/Console/Command/DescribeNameNotFoundException.php @@ -15,8 +15,6 @@ namespace PhpCsFixer\Console\Command; /** - * @author SpacePossum - * * @internal */ final class DescribeNameNotFoundException extends \InvalidArgumentException diff --git a/src/Console/Command/HelpCommand.php b/src/Console/Command/HelpCommand.php index 585dc69fb4c..a5f22047c21 100644 --- a/src/Console/Command/HelpCommand.php +++ b/src/Console/Command/HelpCommand.php @@ -25,7 +25,6 @@ /** * @author Fabien Potencier * @author Dariusz RumiƄski - * @author SpacePossum * * @internal */ @@ -55,11 +54,11 @@ public static function getDisplayableAllowedValues(FixerOptionInterface $option) $allowed = $option->getAllowedValues(); if (null !== $allowed) { - $allowed = array_filter($allowed, static function ($value) { + $allowed = array_filter($allowed, static function ($value): bool { return !($value instanceof \Closure); }); - usort($allowed, static function ($valueA, $valueB) { + usort($allowed, static function ($valueA, $valueB): int { if ($valueA instanceof AllowedValueSubset) { return -1; } diff --git a/src/Console/Command/SelfUpdateCommand.php b/src/Console/Command/SelfUpdateCommand.php index 5b242a71bf0..2039b04b643 100644 --- a/src/Console/Command/SelfUpdateCommand.php +++ b/src/Console/Command/SelfUpdateCommand.php @@ -29,7 +29,6 @@ * @author Stephane PY * @author GrĂ©goire Pineau * @author Dariusz RumiƄski - * @author SpacePossum * * @internal */ diff --git a/src/Console/ConfigurationResolver.php b/src/Console/ConfigurationResolver.php index 7f4129f067c..9a7b71e342f 100644 --- a/src/Console/ConfigurationResolver.php +++ b/src/Console/ConfigurationResolver.php @@ -331,12 +331,12 @@ public function getFixers(): array if (false === $this->getRiskyAllowed()) { $riskyFixers = array_map( - static function (FixerInterface $fixer) { + static function (FixerInterface $fixer): string { return $fixer->getName(); }, array_filter( $this->fixers, - static function (FixerInterface $fixer) { + static function (FixerInterface $fixer): bool { return $fixer->isRisky(); } ) @@ -375,7 +375,7 @@ public function getPath(): array $this->path = $this->options['path']; } else { $this->path = array_map( - static function (string $rawPath) use ($cwd, $filesystem) { + static function (string $rawPath) use ($cwd, $filesystem): string { $path = trim($rawPath); if ('' === $path) { @@ -693,7 +693,7 @@ private function validateRules(array $rules): void $fixers = $this->createFixerFactory()->getFixers(); /** @var string[] $availableFixers */ - $availableFixers = array_map(static function (FixerInterface $fixer) { + $availableFixers = array_map(static function (FixerInterface $fixer): string { return $fixer->getName(); }, $fixers); @@ -873,7 +873,7 @@ static function (string $path) { return new \CallbackFilterIterator( new \IteratorIterator($nestedFinder), - static function (\SplFileInfo $current) use ($pathsByType) { + static function (\SplFileInfo $current) use ($pathsByType): bool { $currentRealPath = $current->getRealPath(); if (\in_array($currentRealPath, $pathsByType['file'], true)) { diff --git a/src/Console/Output/ErrorOutput.php b/src/Console/Output/ErrorOutput.php index df7a5e77cf1..3d716364342 100644 --- a/src/Console/Output/ErrorOutput.php +++ b/src/Console/Output/ErrorOutput.php @@ -21,8 +21,6 @@ use Symfony\Component\Console\Output\OutputInterface; /** - * @author SpacePossum - * * @internal */ final class ErrorOutput diff --git a/src/Console/Report/FixReport/JsonReporter.php b/src/Console/Report/FixReport/JsonReporter.php index e99146dd01c..d637ee7de95 100644 --- a/src/Console/Report/FixReport/JsonReporter.php +++ b/src/Console/Report/FixReport/JsonReporter.php @@ -54,17 +54,11 @@ public function generate(ReportSummary $reportSummary): string $json = [ 'files' => $jFiles, - ]; - - if (null !== $reportSummary->getTime()) { - $json['time'] = [ + 'time' => [ 'total' => round($reportSummary->getTime() / 1000, 3), - ]; - } - - if (null !== $reportSummary->getMemory()) { - $json['memory'] = round($reportSummary->getMemory() / 1024 / 1024, 3); - } + ], + 'memory' => round($reportSummary->getMemory() / 1024 / 1024, 3), + ]; $json = json_encode($json); diff --git a/src/Console/Report/FixReport/JunitReporter.php b/src/Console/Report/FixReport/JunitReporter.php index 759754d49c1..114d3df86ef 100644 --- a/src/Console/Report/FixReport/JunitReporter.php +++ b/src/Console/Report/FixReport/JunitReporter.php @@ -47,13 +47,13 @@ public function generate(ReportSummary $reportSummary): string $testsuite = $testsuites->appendChild($dom->createElement('testsuite')); $testsuite->setAttribute('name', 'PHP CS Fixer'); - if (\count($reportSummary->getChanged())) { + if (\count($reportSummary->getChanged()) > 0) { $this->createFailedTestCases($dom, $testsuite, $reportSummary); } else { $this->createSuccessTestCase($dom, $testsuite); } - if ($reportSummary->getTime()) { + if ($reportSummary->getTime() > 0) { $testsuite->setAttribute( 'time', sprintf( diff --git a/src/Console/Report/ListSetsReport/JsonReporter.php b/src/Console/Report/ListSetsReport/JsonReporter.php index be95b0cf40c..2046939717d 100644 --- a/src/Console/Report/ListSetsReport/JsonReporter.php +++ b/src/Console/Report/ListSetsReport/JsonReporter.php @@ -38,7 +38,7 @@ public function generate(ReportSummary $reportSummary): string { $sets = $reportSummary->getSets(); - usort($sets, function (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b) { + usort($sets, static function (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b): int { return strcmp($a->getName(), $b->getName()); }); diff --git a/src/Console/Report/ListSetsReport/TextReporter.php b/src/Console/Report/ListSetsReport/TextReporter.php index a3d6cd53200..0caddef57f7 100644 --- a/src/Console/Report/ListSetsReport/TextReporter.php +++ b/src/Console/Report/ListSetsReport/TextReporter.php @@ -38,7 +38,7 @@ public function generate(ReportSummary $reportSummary): string { $sets = $reportSummary->getSets(); - usort($sets, function (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b) { + usort($sets, static function (RuleSetDescriptionInterface $a, RuleSetDescriptionInterface $b): int { return strcmp($a->getName(), $b->getName()); }); diff --git a/src/Differ/DiffConsoleFormatter.php b/src/Differ/DiffConsoleFormatter.php index e756dad8c21..887af335903 100644 --- a/src/Differ/DiffConsoleFormatter.php +++ b/src/Differ/DiffConsoleFormatter.php @@ -54,7 +54,7 @@ public function format(string $diff, string $lineTemplate = '%s'): string implode( PHP_EOL, array_map( - static function (string $line) use ($isDecorated, $lineTemplate) { + static function (string $line) use ($isDecorated, $lineTemplate): string { if ($isDecorated) { $count = 0; $line = Preg::replaceCallback( @@ -63,7 +63,7 @@ static function (string $line) use ($isDecorated, $lineTemplate) { '/^(\-.*)/', '/^(@.*)/', ], - static function (array $matches) { + static function (array $matches): string { if ('+' === $matches[0][0]) { $colour = 'green'; } elseif ('-' === $matches[0][0]) { diff --git a/src/Differ/UnifiedDiffer.php b/src/Differ/UnifiedDiffer.php index b2b37c55753..fa2233b3139 100644 --- a/src/Differ/UnifiedDiffer.php +++ b/src/Differ/UnifiedDiffer.php @@ -18,9 +18,6 @@ use PhpCsFixer\Diff\Output\StrictUnifiedDiffOutputBuilder; use PhpCsFixer\Preg; -/** - * @author SpacePossum - */ final class UnifiedDiffer implements DifferInterface { /** diff --git a/src/DocBlock/Annotation.php b/src/DocBlock/Annotation.php index b1f5dce0af6..f06b2e1b65c 100644 --- a/src/DocBlock/Annotation.php +++ b/src/DocBlock/Annotation.php @@ -21,7 +21,7 @@ /** * This represents an entire annotation from a docblock. * - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski * * @final @@ -224,7 +224,7 @@ public function setTypes(array $types): void */ public function getNormalizedTypes(): array { - $normalized = array_map(static function (string $type) { + $normalized = array_map(static function (string $type): string { return strtolower($type); }, $this->getTypes()); diff --git a/src/DocBlock/DocBlock.php b/src/DocBlock/DocBlock.php index 96353e69c53..ccdfe82723e 100644 --- a/src/DocBlock/DocBlock.php +++ b/src/DocBlock/DocBlock.php @@ -23,7 +23,7 @@ * * It internally splits it up into "lines" that we can manipulate. * - * @author Graham Campbell + * @author Graham Campbell * * @final */ @@ -161,7 +161,7 @@ public function makeSingleLine(): void $usefulLines = array_filter( $this->lines, - static function (Line $line) { + static function (Line $line): bool { return $line->containsUsefulContent(); } ); diff --git a/src/DocBlock/Line.php b/src/DocBlock/Line.php index 8b369ffc09e..0cf1ffc586a 100644 --- a/src/DocBlock/Line.php +++ b/src/DocBlock/Line.php @@ -19,7 +19,7 @@ /** * This represents a line of a docblock. * - * @author Graham Campbell + * @author Graham Campbell * * @final */ diff --git a/src/DocBlock/Tag.php b/src/DocBlock/Tag.php index 999ea486ffe..225e3036288 100644 --- a/src/DocBlock/Tag.php +++ b/src/DocBlock/Tag.php @@ -19,7 +19,7 @@ /** * This represents a tag, as defined by the proposed PSR PHPDoc standard. * - * @author Graham Campbell + * @author Graham Campbell * * @final */ diff --git a/src/DocBlock/TagComparator.php b/src/DocBlock/TagComparator.php index e9a3092a9a7..c49761a6181 100644 --- a/src/DocBlock/TagComparator.php +++ b/src/DocBlock/TagComparator.php @@ -18,7 +18,7 @@ * This class is responsible for comparing tags to see if they should be kept * together, or kept apart. * - * @author Graham Campbell + * @author Graham Campbell * * @final */ diff --git a/src/DocBlock/TypeExpression.php b/src/DocBlock/TypeExpression.php index 3fcb471d3fb..9f3ee56a64b 100644 --- a/src/DocBlock/TypeExpression.php +++ b/src/DocBlock/TypeExpression.php @@ -150,13 +150,13 @@ public function getTypes(): array public function getCommonType(): ?string { $aliases = [ - 'true' => 'bool', - 'false' => 'bool', 'boolean' => 'bool', - 'integer' => 'int', + 'callback' => 'callable', 'double' => 'float', + 'false' => 'bool', + 'integer' => 'int', 'real' => 'float', - 'callback' => 'callable', + 'true' => 'bool', ]; $mainType = null; @@ -211,8 +211,8 @@ private function getParentType(string $type1, string $type2): ?string $types = implode('|', $types); $parents = [ - 'array|iterable' => 'iterable', 'array|Traversable' => 'iterable', + 'array|iterable' => 'iterable', 'iterable|Traversable' => 'iterable', 'self|static' => 'self', ]; @@ -223,13 +223,13 @@ private function getParentType(string $type1, string $type2): ?string private function normalize(string $type): string { $aliases = [ - 'true' => 'bool', - 'false' => 'bool', 'boolean' => 'bool', - 'integer' => 'int', + 'callback' => 'callable', 'double' => 'float', + 'false' => 'bool', + 'integer' => 'int', 'real' => 'float', - 'callback' => 'callable', + 'true' => 'bool', ]; if (isset($aliases[$type])) { @@ -237,18 +237,18 @@ private function normalize(string $type): string } if (\in_array($type, [ - 'void', - 'null', + 'array', 'bool', - 'int', + 'callable', 'float', - 'string', - 'array', + 'int', 'iterable', + 'mixed', + 'null', 'object', - 'callable', 'resource', - 'mixed', + 'string', + 'void', ], true)) { return $type; } diff --git a/src/Documentation/DocumentationGenerator.php b/src/Documentation/DocumentationGenerator.php index c56e87365a5..457441a54fa 100644 --- a/src/Documentation/DocumentationGenerator.php +++ b/src/Documentation/DocumentationGenerator.php @@ -77,7 +77,7 @@ public function generateFixersDocumentationIndex(array $fixers): string 'Phpdoc' => 'PHPDoc', ]; - usort($fixers, function (FixerInterface $a, FixerInterface $b) { + usort($fixers, static function (FixerInterface $a, FixerInterface $b): int { return strcmp(\get_class($a), \get_class($b)); }); @@ -131,7 +131,7 @@ public function getFixerDocumentationFilePath(FixerInterface $fixer): string { return $this->getFixersDocumentationDirectoryPath().'/'.Preg::replaceCallback( '/^.*\\\\(.+)\\\\(.+)Fixer$/', - function (array $matches) { + static function (array $matches): string { return Utils::camelCaseToUnderscore($matches[1]).'/'.Utils::camelCaseToUnderscore($matches[2]); }, \get_class($fixer) @@ -224,8 +224,15 @@ public function generateFixerDocumentation(FixerInterface $fixer): string } $allowed = HelpCommand::getDisplayableAllowedValues($option); - $allowedKind = 'Allowed values'; - if (null !== $allowed) { + + if (null === $allowed) { + $allowedKind = 'Allowed types'; + $allowed = array_map(static function ($value): string { + return '``'.$value.'``'; + }, $option->getAllowedTypes()); + } else { + $allowedKind = 'Allowed values'; + foreach ($allowed as &$value) { if ($value instanceof AllowedValueSubset) { $value = 'a subset of ``'.HelpCommand::toString($value->getAllowedValues()).'``'; @@ -233,17 +240,10 @@ public function generateFixerDocumentation(FixerInterface $fixer): string $value = '``'.HelpCommand::toString($value).'``'; } } - } else { - $allowedKind = 'Allowed types'; - $allowed = array_map(function ($value) { - return '``'.$value.'``'; - }, $option->getAllowedTypes()); } - if (null !== $allowed) { - $allowed = implode(', ', $allowed); - $optionInfo .= "\n\n{$allowedKind}: {$allowed}"; - } + $allowed = implode(', ', $allowed); + $optionInfo .= "\n\n{$allowedKind}: {$allowed}"; if ($option->hasDefault()) { $default = HelpCommand::toString($option->getDefault()); diff --git a/src/Error/ErrorsManager.php b/src/Error/ErrorsManager.php index b2b83081a2d..2d70a3e6d63 100644 --- a/src/Error/ErrorsManager.php +++ b/src/Error/ErrorsManager.php @@ -35,7 +35,7 @@ final class ErrorsManager */ public function getInvalidErrors(): array { - return array_filter($this->errors, static function (Error $error) { + return array_filter($this->errors, static function (Error $error): bool { return Error::TYPE_INVALID === $error->getType(); }); } @@ -47,7 +47,7 @@ public function getInvalidErrors(): array */ public function getExceptionErrors(): array { - return array_filter($this->errors, static function (Error $error) { + return array_filter($this->errors, static function (Error $error): bool { return Error::TYPE_EXCEPTION === $error->getType(); }); } @@ -59,7 +59,7 @@ public function getExceptionErrors(): array */ public function getLintErrors(): array { - return array_filter($this->errors, static function (Error $error) { + return array_filter($this->errors, static function (Error $error): bool { return Error::TYPE_LINT === $error->getType(); }); } diff --git a/src/Fixer/Alias/ArrayPushFixer.php b/src/Fixer/Alias/ArrayPushFixer.php index 14becbd76b0..43f4ae4f3a1 100644 --- a/src/Fixer/Alias/ArrayPushFixer.php +++ b/src/Fixer/Alias/ArrayPushFixer.php @@ -23,9 +23,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class ArrayPushFixer extends AbstractFixer { /** diff --git a/src/Fixer/Alias/EregToPregFixer.php b/src/Fixer/Alias/EregToPregFixer.php index 1cfc7e8dde8..80a75db5e7b 100644 --- a/src/Fixer/Alias/EregToPregFixer.php +++ b/src/Fixer/Alias/EregToPregFixer.php @@ -87,9 +87,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void foreach (self::$functions as $map) { // the sequence is the function name, followed by "(" and a quoted string $seq = [[T_STRING, $map[0]], '(', [T_CONSTANT_ENCAPSED_STRING]]; - $currIndex = 0; - while (null !== $currIndex) { + + do { $match = $tokens->findSequence($seq, $currIndex, $end, false); // did we find a match? @@ -112,6 +112,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // ensure the first parameter is just a string (e.g. has nothing appended) $next = $tokens->getNextMeaningfulToken($match[2]); + if (null === $next || !$tokens[$next]->equalsAny([',', ')'])) { continue; } @@ -131,7 +132,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // modify function and argument $tokens[$match[0]] = new Token([T_STRING, $map[1]]); $tokens[$match[2]] = new Token([T_CONSTANT_ENCAPSED_STRING, $quote.$preg.$quote]); - } + } while (null !== $currIndex); } } @@ -171,7 +172,7 @@ private function getBestDelimiter(string $pattern): string } // return the least used delimiter, using the position in the list as a tie breaker - uasort($delimiters, static function (array $a, array $b) { + uasort($delimiters, static function (array $a, array $b): int { if ($a[0] === $b[0]) { return $a[1] <=> $b[1]; } diff --git a/src/Fixer/Alias/MbStrFunctionsFixer.php b/src/Fixer/Alias/MbStrFunctionsFixer.php index b925b9fa62e..730e361ef88 100644 --- a/src/Fixer/Alias/MbStrFunctionsFixer.php +++ b/src/Fixer/Alias/MbStrFunctionsFixer.php @@ -57,7 +57,7 @@ public function __construct() $this->functions = array_filter( self::$functionsMap, - static function (array $mapping) { + static function (array $mapping): bool { return \function_exists($mapping['alternativeName']) && (new \ReflectionFunction($mapping['alternativeName']))->isInternal(); } ); @@ -109,7 +109,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $argumentsAnalyzer = new ArgumentsAnalyzer(); foreach ($this->functions as $functionIdentity => $functionReplacement) { $currIndex = 0; - while (null !== $currIndex) { + do { // try getting function reference and translate boundaries for humans $boundaries = $this->find($functionIdentity, $tokens, $currIndex, $tokens->count() - 1); if (null === $boundaries) { @@ -127,7 +127,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $currIndex = $openParenthesis; $tokens[$functionName] = new Token([T_STRING, $functionReplacement['alternativeName']]); - } + } while (null !== $currIndex); } } } diff --git a/src/Fixer/Alias/NoAliasLanguageConstructCallFixer.php b/src/Fixer/Alias/NoAliasLanguageConstructCallFixer.php index 41eab1c99a4..357fa22830c 100644 --- a/src/Fixer/Alias/NoAliasLanguageConstructCallFixer.php +++ b/src/Fixer/Alias/NoAliasLanguageConstructCallFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NoAliasLanguageConstructCallFixer extends AbstractFixer { /** diff --git a/src/Fixer/Alias/NoMixedEchoPrintFixer.php b/src/Fixer/Alias/NoMixedEchoPrintFixer.php index 0e899a4b910..46782415371 100644 --- a/src/Fixer/Alias/NoMixedEchoPrintFixer.php +++ b/src/Fixer/Alias/NoMixedEchoPrintFixer.php @@ -28,7 +28,6 @@ /** * @author Sullivan Senechal - * @author SpacePossum */ final class NoMixedEchoPrintFixer extends AbstractFixer implements ConfigurableFixerInterface { diff --git a/src/Fixer/Alias/PowToExponentiationFixer.php b/src/Fixer/Alias/PowToExponentiationFixer.php index 8e3836f00c7..f71020e6b15 100644 --- a/src/Fixer/Alias/PowToExponentiationFixer.php +++ b/src/Fixer/Alias/PowToExponentiationFixer.php @@ -23,9 +23,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer { /** diff --git a/src/Fixer/Alias/RandomApiMigrationFixer.php b/src/Fixer/Alias/RandomApiMigrationFixer.php index 7626db97c32..a4772bcae37 100644 --- a/src/Fixer/Alias/RandomApiMigrationFixer.php +++ b/src/Fixer/Alias/RandomApiMigrationFixer.php @@ -103,7 +103,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $currIndex = 0; - while (null !== $currIndex) { + do { // try getting function reference and translate boundaries for humans $boundaries = $this->find($functionIdentity, $tokens, $currIndex, $tokens->count() - 1); @@ -135,7 +135,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $currIndex += 6; } - } + } while (null !== $currIndex); } } @@ -147,7 +147,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn return new FixerConfigurationResolver([ (new FixerOptionBuilder('replacements', 'Mapping between replaced functions with the new ones.')) ->setAllowedTypes(['array']) - ->setAllowedValues([static function (array $value) { + ->setAllowedValues([static function (array $value): bool { foreach ($value as $functionName => $replacement) { if (!\array_key_exists($functionName, self::$argumentCounts)) { throw new InvalidOptionsException(sprintf( diff --git a/src/Fixer/Alias/SetTypeToCastFixer.php b/src/Fixer/Alias/SetTypeToCastFixer.php index ed568384133..5ecc2bd291e 100644 --- a/src/Fixer/Alias/SetTypeToCastFixer.php +++ b/src/Fixer/Alias/SetTypeToCastFixer.php @@ -22,9 +22,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class SetTypeToCastFixer extends AbstractFunctionReferenceFixer { /** diff --git a/src/Fixer/ArrayNotation/ArraySyntaxFixer.php b/src/Fixer/ArrayNotation/ArraySyntaxFixer.php index df278f2eaa6..c3d070de3f3 100644 --- a/src/Fixer/ArrayNotation/ArraySyntaxFixer.php +++ b/src/Fixer/ArrayNotation/ArraySyntaxFixer.php @@ -30,7 +30,6 @@ * @author Gregor Harlan * @author Sebastiaan Stok * @author Dariusz RumiƄski - * @author SpacePossum */ final class ArraySyntaxFixer extends AbstractFixer implements ConfigurableFixerInterface { diff --git a/src/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixer.php b/src/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixer.php index 41a40fb272a..8c568493634 100644 --- a/src/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixer.php +++ b/src/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixer.php @@ -24,7 +24,7 @@ /** * @author Carlos Cirello * @author Dariusz RumiƄski - * @author Graham Campbell + * @author Graham Campbell */ final class NoMultilineWhitespaceAroundDoubleArrowFixer extends AbstractFixer { diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index 2c26e490d2b..69282a513f6 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -313,7 +313,7 @@ private function fixIndents(Tokens $tokens): void $controlTokens = $this->getControlTokens(); $indentTokens = array_filter( array_merge($classyAndFunctionTokens, $controlTokens), - static function (int $item) { + static function (int $item): bool { return T_SWITCH !== $item; } ); diff --git a/src/Fixer/Basic/PsrAutoloadingFixer.php b/src/Fixer/Basic/PsrAutoloadingFixer.php index 4f79089a70b..96a86c92a0a 100644 --- a/src/Fixer/Basic/PsrAutoloadingFixer.php +++ b/src/Fixer/Basic/PsrAutoloadingFixer.php @@ -31,7 +31,7 @@ * @author Jordi Boggiano * @author Dariusz RumiƄski * @author Bram Gotink - * @author Graham Campbell + * @author Graham Campbell * @author Kuba WerƂos */ final class PsrAutoloadingFixer extends AbstractFixer implements ConfigurableFixerInterface @@ -131,7 +131,7 @@ public function supports(\SplFileInfo $file): bool return false; } - // ignore stubs/fixtures, since they are typically containing invalid files for various reasons + // ignore stubs/fixtures, since they typically contain invalid files for various reasons return !Preg::match('{[/\\\\](stub|fixture)s?[/\\\\]}i', $file->getRealPath()); } diff --git a/src/Fixer/Casing/MagicMethodCasingFixer.php b/src/Fixer/Casing/MagicMethodCasingFixer.php index 45979c8a241..c5bf50e6b36 100644 --- a/src/Fixer/Casing/MagicMethodCasingFixer.php +++ b/src/Fixer/Casing/MagicMethodCasingFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class MagicMethodCasingFixer extends AbstractFixer { private static $magicNames = [ diff --git a/src/Fixer/Casing/NativeFunctionCasingFixer.php b/src/Fixer/Casing/NativeFunctionCasingFixer.php index 436baaaf7d7..cf0f68da348 100644 --- a/src/Fixer/Casing/NativeFunctionCasingFixer.php +++ b/src/Fixer/Casing/NativeFunctionCasingFixer.php @@ -22,9 +22,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NativeFunctionCasingFixer extends AbstractFixer { /** diff --git a/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php b/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php index e3810dfff30..37f501c8685 100644 --- a/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php +++ b/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php @@ -25,9 +25,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NativeFunctionTypeDeclarationCasingFixer extends AbstractFixer { /** diff --git a/src/Fixer/CastNotation/LowercaseCastFixer.php b/src/Fixer/CastNotation/LowercaseCastFixer.php index a3f501af891..f0e30ce2d0e 100644 --- a/src/Fixer/CastNotation/LowercaseCastFixer.php +++ b/src/Fixer/CastNotation/LowercaseCastFixer.php @@ -22,9 +22,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class LowercaseCastFixer extends AbstractFixer { /** diff --git a/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php b/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php index 99e51c06f1c..e645149c59d 100644 --- a/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php +++ b/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php @@ -76,9 +76,11 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void foreach ($replacement as $functionIdentity => $newToken) { $currIndex = 0; - while (null !== $currIndex) { + + do { // try getting function reference and translate boundaries for humans $boundaries = $this->find($functionIdentity, $tokens, $currIndex, $tokens->count() - 1); + if (null === $boundaries) { // next function search, as current one not found continue 2; @@ -96,6 +98,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $paramContentEnd = $closeParenthesis; $commaCandidate = $tokens->getPrevMeaningfulToken($paramContentEnd); + if ($tokens[$commaCandidate]->equals(',')) { $tokens->removeTrailingWhitespace($commaCandidate); $tokens->clearAt($commaCandidate); @@ -104,6 +107,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // check if something complex passed as an argument and preserve parenthesises then $countParamTokens = 0; + for ($paramContentIndex = $openParenthesis + 1; $paramContentIndex < $paramContentEnd; ++$paramContentIndex) { //not a space, means some sensible token if (!$tokens[$paramContentIndex]->isGivenKind(T_WHITESPACE)) { @@ -111,14 +115,15 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } } - $preserveParenthesises = $countParamTokens > 1; + $preserveParentheses = $countParamTokens > 1; $afterCloseParenthesisIndex = $tokens->getNextMeaningfulToken($closeParenthesis); $afterCloseParenthesisToken = $tokens[$afterCloseParenthesisIndex]; - $wrapInParenthesises = $afterCloseParenthesisToken->equalsAny(['[', '{']) || $afterCloseParenthesisToken->isGivenKind(T_POW); + $wrapInParentheses = $afterCloseParenthesisToken->equalsAny(['[', '{']) || $afterCloseParenthesisToken->isGivenKind(T_POW); // analyse namespace specification (root one or none) and decide what to do $prevTokenIndex = $tokens->getPrevMeaningfulToken($functionName); + if ($tokens[$prevTokenIndex]->isGivenKind(T_NS_SEPARATOR)) { // get rid of root namespace when it used $tokens->removeTrailingWhitespace($prevTokenIndex); @@ -130,11 +135,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void new Token($newToken), new Token([T_WHITESPACE, ' ']), ]; - if ($wrapInParenthesises) { + + if ($wrapInParentheses) { array_unshift($replacementSequence, new Token('(')); } - if (!$preserveParenthesises) { + if (!$preserveParentheses) { // closing parenthesis removed with leading spaces $tokens->removeLeadingWhitespace($closeParenthesis); $tokens->clearAt($closeParenthesis); @@ -148,7 +154,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $tokens->removeTrailingWhitespace($functionName); } - if ($wrapInParenthesises) { + if ($wrapInParentheses) { $tokens->insertAt($closeParenthesis, new Token(')')); } @@ -156,7 +162,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // nested transformations support $currIndex = $functionName; - } + } while (null !== $currIndex); } } } diff --git a/src/Fixer/CastNotation/NoShortBoolCastFixer.php b/src/Fixer/CastNotation/NoShortBoolCastFixer.php index dbe032add6b..d802d49526d 100644 --- a/src/Fixer/CastNotation/NoShortBoolCastFixer.php +++ b/src/Fixer/CastNotation/NoShortBoolCastFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NoShortBoolCastFixer extends AbstractFixer { /** diff --git a/src/Fixer/CastNotation/NoUnsetCastFixer.php b/src/Fixer/CastNotation/NoUnsetCastFixer.php index 79d6c242a78..c75f8ba429b 100644 --- a/src/Fixer/CastNotation/NoUnsetCastFixer.php +++ b/src/Fixer/CastNotation/NoUnsetCastFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NoUnsetCastFixer extends AbstractFixer { /** diff --git a/src/Fixer/CastNotation/ShortScalarCastFixer.php b/src/Fixer/CastNotation/ShortScalarCastFixer.php index d7758480200..983effde72e 100644 --- a/src/Fixer/CastNotation/ShortScalarCastFixer.php +++ b/src/Fixer/CastNotation/ShortScalarCastFixer.php @@ -22,9 +22,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class ShortScalarCastFixer extends AbstractFixer { /** diff --git a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php index 4bc55c708e3..249b1940806 100644 --- a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php +++ b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php @@ -36,8 +36,6 @@ * Make sure there is one blank line above and below class elements. * * The exception is when an element is the first or last item in a 'classy'. - * - * @author SpacePossum */ final class ClassAttributesSeparationFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { @@ -208,7 +206,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn return new FixerConfigurationResolver([ (new FixerOptionBuilder('elements', 'Dictionary of `const|method|property|trait_import` => `none|one` values.')) ->setAllowedTypes(['array']) - ->setAllowedValues([static function (array $option) { + ->setAllowedValues([static function (array $option): bool { foreach ($option as $type => $spacing) { $supportedTypes = ['const', 'method', 'property', 'trait_import']; @@ -501,19 +499,19 @@ private function getElementsByClass(Tokens $tokens): \Generator private function getFirstTokenIndexOfClassElement(Tokens $tokens, array $class, array $element): int { - static $methodAttr = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; + static $modifierTypes = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; $firstElementAttributeIndex = $element['index']; - while ($firstElementAttributeIndex > $class['open']) { + do { $nonWhiteAbove = $tokens->getPrevMeaningfulToken($firstElementAttributeIndex); - if (null !== $nonWhiteAbove && $tokens[$nonWhiteAbove]->isGivenKind($methodAttr)) { + if (null !== $nonWhiteAbove && $tokens[$nonWhiteAbove]->isGivenKind($modifierTypes)) { $firstElementAttributeIndex = $nonWhiteAbove; } else { break; } - } + } while ($firstElementAttributeIndex > $class['open']); return $firstElementAttributeIndex; } diff --git a/src/Fixer/ClassNotation/ClassDefinitionFixer.php b/src/Fixer/ClassNotation/ClassDefinitionFixer.php index 374697a0bcb..1fb578dd1b2 100644 --- a/src/Fixer/ClassNotation/ClassDefinitionFixer.php +++ b/src/Fixer/ClassNotation/ClassDefinitionFixer.php @@ -29,8 +29,6 @@ /** * Fixer for part of the rules defined in PSR2 ¶4.1 Extends and Implements and PSR12 ¶8. Anonymous Classes. - * - * @author SpacePossum */ final class ClassDefinitionFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { diff --git a/src/Fixer/ClassNotation/FinalInternalClassFixer.php b/src/Fixer/ClassNotation/FinalInternalClassFixer.php index d70ff5dcbb6..0d143f5bafc 100644 --- a/src/Fixer/ClassNotation/FinalInternalClassFixer.php +++ b/src/Fixer/ClassNotation/FinalInternalClassFixer.php @@ -31,7 +31,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum */ final class FinalInternalClassFixer extends AbstractFixer implements ConfigurableFixerInterface { diff --git a/src/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixer.php b/src/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixer.php index b0d96a59ab0..e25dd001281 100644 --- a/src/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixer.php +++ b/src/Fixer/ClassNotation/FinalPublicMethodForAbstractClassFixer.php @@ -122,8 +122,10 @@ private function fixClass(Tokens $tokens, int $classOpenIndex, int $classCloseIn if (!$tokens[$index]->isGivenKind(T_PUBLIC)) { continue; } + $nextIndex = $tokens->getNextMeaningfulToken($index); $nextToken = $tokens[$nextIndex]; + if ($nextToken->isGivenKind(T_STATIC)) { $nextIndex = $tokens->getNextMeaningfulToken($nextIndex); $nextToken = $tokens[$nextIndex]; @@ -133,6 +135,7 @@ private function fixClass(Tokens $tokens, int $classOpenIndex, int $classCloseIn if (!$nextToken->isGivenKind(T_FUNCTION)) { continue; } + $nextIndex = $tokens->getNextMeaningfulToken($nextIndex); $nextToken = $tokens[$nextIndex]; @@ -143,11 +146,13 @@ private function fixClass(Tokens $tokens, int $classOpenIndex, int $classCloseIn $prevIndex = $tokens->getPrevMeaningfulToken($index); $prevToken = $tokens[$prevIndex]; + if ($prevToken->isGivenKind(T_STATIC)) { $index = $prevIndex; $prevIndex = $tokens->getPrevMeaningfulToken($index); $prevToken = $tokens[$prevIndex]; } + // skip abstract or already final methods if ($prevToken->isGivenKind([T_ABSTRACT, T_FINAL])) { $index = $prevIndex; diff --git a/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php b/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php index 423c4095ffe..433bfa07690 100644 --- a/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php +++ b/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php @@ -87,7 +87,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void for ($i = 0; $i < $numClasses; ++$i) { $index = $classes[$i]; - // is it an an anonymous class definition? + // is it an anonymous class definition? if ($tokensAnalyzer->isAnonymousClass($index)) { continue; } @@ -109,6 +109,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // the index points to the { of a block-namespace $nspEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nspIndex); + if ($index < $nspEnd) { // the class is inside a block namespace, skip other classes that might be in it for ($j = $i + 1; $j < $numClasses; ++$j) { @@ -168,6 +169,7 @@ private function fixConstructor(Tokens $tokens, string $className, int $classSta // does the PHP4-constructor only call $this->__construct($args, ...)? [$sequences, $case] = $this->getWrapperMethodSequence($tokens, '__construct', $php4['startIndex'], $php4['bodyIndex']); + foreach ($sequences as $seq) { if (null !== $tokens->findSequence($seq, $php4['bodyIndex'] - 1, $php4['endIndex'], $case)) { // good, delete it! @@ -181,6 +183,7 @@ private function fixConstructor(Tokens $tokens, string $className, int $classSta // does __construct only call the PHP4-constructor (with the same args)? [$sequences, $case] = $this->getWrapperMethodSequence($tokens, $className, $php4['startIndex'], $php4['bodyIndex']); + foreach ($sequences as $seq) { if (null !== $tokens->findSequence($seq, $php5['bodyIndex'] - 1, $php5['endIndex'], $case)) { // that was a weird choice, but we can safely delete it and... @@ -316,6 +319,7 @@ private function getWrapperMethodSequence(Tokens $tokens, string $method, int $s // parse method parameters, if any $index = $startIndex; + while (true) { // find the next variable name $index = $tokens->getNextTokenOfKind($index, [[T_VARIABLE]]); @@ -382,6 +386,7 @@ private function findFunction(Tokens $tokens, string $name, int $startIndex, int $modifiers = []; $prevBlock = $tokens->getPrevMeaningfulToken($function[0]); + while (null !== $prevBlock && $tokens[$prevBlock]->isGivenKind($possibleModifiers)) { $modifiers[$tokens[$prevBlock]->getId()] = $prevBlock; $prevBlock = $tokens->getPrevMeaningfulToken($prevBlock); diff --git a/src/Fixer/ClassNotation/OrderedClassElementsFixer.php b/src/Fixer/ClassNotation/OrderedClassElementsFixer.php index 61084b37362..5ae0cdb7357 100644 --- a/src/Fixer/ClassNotation/OrderedClassElementsFixer.php +++ b/src/Fixer/ClassNotation/OrderedClassElementsFixer.php @@ -471,7 +471,7 @@ private function sortElements(array $elements): array } unset($element); - usort($elements, function (array $a, array $b) { + usort($elements, function (array $a, array $b): int { if ($a['position'] === $b['position']) { return $this->sortGroupElements($a, $b); } diff --git a/src/Fixer/ClassNotation/OrderedInterfacesFixer.php b/src/Fixer/ClassNotation/OrderedInterfacesFixer.php index 63aaa5393ae..702bba0829b 100644 --- a/src/Fixer/ClassNotation/OrderedInterfacesFixer.php +++ b/src/Fixer/ClassNotation/OrderedInterfacesFixer.php @@ -180,7 +180,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $interfaces[$interfaceIndex]['originalIndex'] = $interfaceIndex; } - usort($interfaces, function (array $first, array $second) { + usort($interfaces, function (array $first, array $second): int { $score = self::ORDER_LENGTH === $this->configuration[self::OPTION_ORDER] ? \strlen($first['normalized']) - \strlen($second['normalized']) : strcasecmp($first['normalized'], $second['normalized']); diff --git a/src/Fixer/ClassNotation/OrderedTraitsFixer.php b/src/Fixer/ClassNotation/OrderedTraitsFixer.php index 33653ff5120..9602ec3afe4 100644 --- a/src/Fixer/ClassNotation/OrderedTraitsFixer.php +++ b/src/Fixer/ClassNotation/OrderedTraitsFixer.php @@ -157,9 +157,6 @@ private function sortMultipleTraitsInStatement(Tokens $use): void */ private function sort(Tokens $tokens, array $elements): void { - /** - * @return string - */ $toTraitName = static function (Tokens $use): string { $string = ''; @@ -177,7 +174,7 @@ private function sort(Tokens $tokens, array $elements): void }; $sortedElements = $elements; - uasort($sortedElements, static function (Tokens $useA, Tokens $useB) use ($toTraitName) { + uasort($sortedElements, static function (Tokens $useA, Tokens $useB) use ($toTraitName): int { return strcasecmp($toTraitName($useA), $toTraitName($useB)); }); diff --git a/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php b/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php index 63f2e453724..aaabb095184 100644 --- a/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php +++ b/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php @@ -24,7 +24,6 @@ /** * @author Filippo Tessarotto - * @author SpacePossum */ final class ProtectedToPrivateFixer extends AbstractFixer { @@ -111,7 +110,7 @@ private function fixClass(Tokens $tokens, int $classOpenIndex, int $classCloseIn } /** - * Decide whether or not skip the fix for given class. + * Decide whether to skip the fix for given class. */ private function skipClass(Tokens $tokens, int $classIndex, int $classOpenIndex, int $classCloseIndex): bool { diff --git a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php index 4451a44df3e..60782fec0fa 100644 --- a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php +++ b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php @@ -34,7 +34,6 @@ * Fixer for rules defined in PSR2 ¶4.2. * * @author Javier Spagnoletti - * @author SpacePossum * @author Dariusz RumiƄski */ final class SingleClassElementPerStatementFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface diff --git a/src/Fixer/ClassNotation/SingleTraitInsertPerStatementFixer.php b/src/Fixer/ClassNotation/SingleTraitInsertPerStatementFixer.php index 06b9fe384f2..095cf449bbf 100644 --- a/src/Fixer/ClassNotation/SingleTraitInsertPerStatementFixer.php +++ b/src/Fixer/ClassNotation/SingleTraitInsertPerStatementFixer.php @@ -23,9 +23,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class SingleTraitInsertPerStatementFixer extends AbstractFixer { public function getDefinition(): FixerDefinitionInterface diff --git a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php index 0cf7c880998..8d0ec21b2d1 100644 --- a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php +++ b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php @@ -32,7 +32,6 @@ * Fixer for rules defined in PSR2 ¶4.3, ¶4.5. * * @author Dariusz RumiƄski - * @author SpacePossum */ final class VisibilityRequiredFixer extends AbstractFixer implements ConfigurableFixerInterface { @@ -98,6 +97,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { $tokensAnalyzer = new TokensAnalyzer($tokens); + $propertyTypeDeclarationKinds = [T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; foreach (array_reverse($tokensAnalyzer->getClassyElements(), true) as $index => $element) { @@ -179,8 +179,8 @@ private function isKeywordPlacedProperly(Tokens $tokens, int $keywordIndex, int private function moveTokenAndEnsureSingleSpaceFollows(Tokens $tokens, int $fromIndex, int $toIndex): void { $tokens->insertAt($toIndex, [$tokens[$fromIndex], new Token([T_WHITESPACE, ' '])]); - $tokens->clearAt($fromIndex); + if ($tokens[$fromIndex + 1]->isWhitespace()) { $tokens->clearAt($fromIndex + 1); } diff --git a/src/Fixer/Comment/CommentToPhpdocFixer.php b/src/Fixer/Comment/CommentToPhpdocFixer.php index 0eff6cadeb7..f6cc93542c8 100644 --- a/src/Fixer/Comment/CommentToPhpdocFixer.php +++ b/src/Fixer/Comment/CommentToPhpdocFixer.php @@ -91,7 +91,7 @@ public function configure(array $configuration): void parent::configure($configuration); $this->ignoredTags = array_map( - static function (string $tag) { + static function (string $tag): string { return strtolower($tag); }, $this->configuration['ignored_tags'] @@ -150,7 +150,7 @@ private function isCommentCandidate(Tokens $tokens, array $indices): bool { return array_reduce( $indices, - function (bool $carry, int $index) use ($tokens) { + function (bool $carry, int $index) use ($tokens): bool { if ($carry) { return true; } diff --git a/src/Fixer/Comment/HeaderCommentFixer.php b/src/Fixer/Comment/HeaderCommentFixer.php index cae05c74050..a22e2500568 100644 --- a/src/Fixer/Comment/HeaderCommentFixer.php +++ b/src/Fixer/Comment/HeaderCommentFixer.php @@ -31,7 +31,6 @@ /** * @author Antonio J. GarcĂ­a Lagar - * @author SpacePossum */ final class HeaderCommentFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { @@ -204,7 +203,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn return new FixerConfigurationResolver([ (new FixerOptionBuilder('header', 'Proper header content.')) ->setAllowedTypes(['string']) - ->setNormalizer(static function (Options $options, $value) use ($fixerName) { + ->setNormalizer(static function (Options $options, string $value) use ($fixerName): string { if ('' === trim($value)) { return ''; } diff --git a/src/Fixer/Comment/NoEmptyCommentFixer.php b/src/Fixer/Comment/NoEmptyCommentFixer.php index c2a3c0e0340..396fba4be04 100644 --- a/src/Fixer/Comment/NoEmptyCommentFixer.php +++ b/src/Fixer/Comment/NoEmptyCommentFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Preg; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NoEmptyCommentFixer extends AbstractFixer { private const TYPE_HASH = 1; diff --git a/src/Fixer/ConfigurableFixerInterface.php b/src/Fixer/ConfigurableFixerInterface.php index 8b2211772f0..1cc18ad1ae6 100644 --- a/src/Fixer/ConfigurableFixerInterface.php +++ b/src/Fixer/ConfigurableFixerInterface.php @@ -19,7 +19,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum */ interface ConfigurableFixerInterface extends FixerInterface { diff --git a/src/Fixer/ConstantNotation/NativeConstantInvocationFixer.php b/src/Fixer/ConstantNotation/NativeConstantInvocationFixer.php index 11137b5553f..7793120079f 100644 --- a/src/Fixer/ConstantNotation/NativeConstantInvocationFixer.php +++ b/src/Fixer/ConstantNotation/NativeConstantInvocationFixer.php @@ -161,7 +161,7 @@ public function configure(array $configuration): void $caseInsensitiveConstantsToEscape = array_diff( array_unique($caseInsensitiveConstantsToEscape), - array_map(static function (string $function) { return strtolower($function); }, $uniqueConfiguredExclude) + array_map(static function (string $function): string { return strtolower($function); }, $uniqueConfiguredExclude) ); // Store the cache diff --git a/src/Fixer/ControlStructure/EmptyLoopBodyFixer.php b/src/Fixer/ControlStructure/EmptyLoopBodyFixer.php index 98476e4b6b8..f0898a6fd4a 100644 --- a/src/Fixer/ControlStructure/EmptyLoopBodyFixer.php +++ b/src/Fixer/ControlStructure/EmptyLoopBodyFixer.php @@ -26,9 +26,6 @@ use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\Tokenizer\TokensAnalyzer; -/** - * @author SpacePossum - */ final class EmptyLoopBodyFixer extends AbstractFixer implements ConfigurableFixerInterface { private const STYLE_BRACES = 'braces'; diff --git a/src/Fixer/ControlStructure/NoBreakCommentFixer.php b/src/Fixer/ControlStructure/NoBreakCommentFixer.php index 8a750bfad61..f89c1abbe12 100644 --- a/src/Fixer/ControlStructure/NoBreakCommentFixer.php +++ b/src/Fixer/ControlStructure/NoBreakCommentFixer.php @@ -100,7 +100,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn (new FixerOptionBuilder('comment_text', 'The text to use in the added comment and to detect it.')) ->setAllowedTypes(['string']) ->setAllowedValues([ - static function (string $value) { + static function (string $value): bool { if (Preg::match('/\R/', $value)) { throw new InvalidOptionsException('The comment text must not contain new lines.'); } @@ -108,7 +108,7 @@ static function (string $value) { return true; }, ]) - ->setNormalizer(static function (Options $options, $value) { + ->setNormalizer(static function (Options $options, string $value): string { return rtrim($value); }) ->setDefault('no break') diff --git a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php index c130965c089..34c80d18e04 100644 --- a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php +++ b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php @@ -25,9 +25,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NoUnneededCurlyBracesFixer extends AbstractFixer implements ConfigurableFixerInterface { /** diff --git a/src/Fixer/ControlStructure/NoUselessElseFixer.php b/src/Fixer/ControlStructure/NoUselessElseFixer.php index 1a3dc2d7582..58a9a3cb400 100644 --- a/src/Fixer/ControlStructure/NoUselessElseFixer.php +++ b/src/Fixer/ControlStructure/NoUselessElseFixer.php @@ -20,9 +20,6 @@ use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NoUselessElseFixer extends AbstractNoUselessElseFixer { /** diff --git a/src/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixer.php b/src/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixer.php index 51de357c222..355643dc18f 100644 --- a/src/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixer.php +++ b/src/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixer.php @@ -23,8 +23,6 @@ /** * Fixer for rules defined in PSR2 ¶5.2. - * - * @author SpacePossum */ final class SwitchCaseSemicolonToColonFixer extends AbstractFixer { diff --git a/src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php b/src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php index 58020fc317e..01950325fe2 100644 --- a/src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php +++ b/src/Fixer/ControlStructure/TrailingCommaInMultilineFixer.php @@ -127,6 +127,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn if (\PHP_VERSION_ID < 70300 && \in_array(self::ELEMENTS_ARGUMENTS, $value, true)) { throw new InvalidOptionsForEnvException(sprintf('"%s" option can only be enabled with PHP 7.3+.', self::ELEMENTS_ARGUMENTS)); } + if (\PHP_VERSION_ID < 80000 && \in_array(self::ELEMENTS_PARAMETERS, $value, true)) { throw new InvalidOptionsForEnvException(sprintf('"%s" option can only be enabled with PHP 8.0+.', self::ELEMENTS_PARAMETERS)); } diff --git a/src/Fixer/ControlStructure/YodaStyleFixer.php b/src/Fixer/ControlStructure/YodaStyleFixer.php index 1770af180a9..24049d547ef 100644 --- a/src/Fixer/ControlStructure/YodaStyleFixer.php +++ b/src/Fixer/ControlStructure/YodaStyleFixer.php @@ -30,7 +30,6 @@ /** * @author Bram Gotink * @author Dariusz RumiƄski - * @author SpacePossum */ final class YodaStyleFixer extends AbstractFixer implements ConfigurableFixerInterface { @@ -179,8 +178,10 @@ private function findComparisonEnd(Tokens $tokens, int $index): int { ++$index; $count = \count($tokens); + while ($index < $count) { $token = $tokens[$index]; + if ($token->isGivenKind([T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) { ++$index; @@ -192,6 +193,7 @@ private function findComparisonEnd(Tokens $tokens, int $index): int } $block = Tokens::detectBlockType($token); + if (null === $block) { ++$index; @@ -230,6 +232,7 @@ private function findComparisonStart(Tokens $tokens, int $index): int while (0 <= $index) { $token = $tokens[$index]; + if ($token->isGivenKind([T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) { --$index; @@ -241,6 +244,7 @@ private function findComparisonStart(Tokens $tokens, int $index): int } $block = Tokens::detectBlockType($token); + if (null === $block) { --$index; $nonBlockFound = true; @@ -276,6 +280,7 @@ private function fixTokens(Tokens $tokens): Tokens } $fixableCompareInfo = $this->getCompareFixableInfo($tokens, $i, $yoda); + if (null === $fixableCompareInfo) { continue; } @@ -304,7 +309,7 @@ private function fixTokens(Tokens $tokens): Tokens * If the left-hand side and right-hand side of the given comparison are * swapped, this function runs recursively on the previous left-hand-side. * - * @return int a upper bound for all non-fixed comparisons + * @return int an upper bound for all non-fixed comparisons */ private function fixTokensCompare( Tokens $tokens, @@ -316,6 +321,7 @@ private function fixTokensCompare( ): int { $type = $tokens[$compareOperatorIndex]->getId(); $content = $tokens[$compareOperatorIndex]->getContent(); + if (\array_key_exists($type, $this->candidatesMap)) { $tokens[$compareOperatorIndex] = clone $this->candidatesMap[$type]; } elseif (\array_key_exists($content, $this->candidatesMap)) { @@ -364,7 +370,6 @@ private function getCompareFixableInfo(Tokens $tokens, int $index, bool $yoda): } $strict = $this->configuration['always_move_variable']; - $leftSideIsVariable = $this->isVariable($tokens, $left['start'], $left['end'], $strict); $rightSideIsVariable = $this->isVariable($tokens, $right['start'], $right['end'], $strict); @@ -536,6 +541,7 @@ private function isVariable(Tokens $tokens, int $start, int $end, bool $strict): } $expectString = false; + while ($index <= $end) { $current = $tokens[$index]; if ($current->isComment() || $current->isWhitespace() || $tokens->isEmptyAt($index)) { diff --git a/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php b/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php index e75be43eb45..35e37b0a12e 100644 --- a/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php +++ b/src/Fixer/FunctionNotation/CombineNestedDirnameFixer.php @@ -158,7 +158,7 @@ private function getDirnameInfo(Tokens $tokens, int $index, ?int $firstArgumentE while (!$tokens[$next]->equalsAny([',', ')'])) { $blockType = Tokens::detectBlockType($tokens[$next]); - if ($blockType) { + if (null !== $blockType) { $next = $tokens->findBlockEnd($blockType['type'], $next); } diff --git a/src/Fixer/FunctionNotation/FopenFlagOrderFixer.php b/src/Fixer/FunctionNotation/FopenFlagOrderFixer.php index e873ec5a22b..15b0174fab3 100644 --- a/src/Fixer/FunctionNotation/FopenFlagOrderFixer.php +++ b/src/Fixer/FunctionNotation/FopenFlagOrderFixer.php @@ -22,9 +22,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class FopenFlagOrderFixer extends AbstractFopenFlagFixer { /** @@ -99,7 +96,7 @@ private function sortFlags(array $flags): array { usort( $flags, - static function (string $flag1, string $flag2) { + static function (string $flag1, string $flag2): int { if ($flag1 === $flag2) { return 0; } diff --git a/src/Fixer/FunctionNotation/FopenFlagsFixer.php b/src/Fixer/FunctionNotation/FopenFlagsFixer.php index faf5f51e0cb..5ae2354997c 100644 --- a/src/Fixer/FunctionNotation/FopenFlagsFixer.php +++ b/src/Fixer/FunctionNotation/FopenFlagsFixer.php @@ -25,9 +25,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class FopenFlagsFixer extends AbstractFopenFlagFixer implements ConfigurableFixerInterface { /** diff --git a/src/Fixer/FunctionNotation/LambdaNotUsedImportFixer.php b/src/Fixer/FunctionNotation/LambdaNotUsedImportFixer.php index 926ea5bd880..d0e73f90d4c 100644 --- a/src/Fixer/FunctionNotation/LambdaNotUsedImportFixer.php +++ b/src/Fixer/FunctionNotation/LambdaNotUsedImportFixer.php @@ -24,9 +24,6 @@ use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\Tokenizer\TokensAnalyzer; -/** - * @author SpacePossum - */ final class LambdaNotUsedImportFixer extends AbstractFixer { /** diff --git a/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php b/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php index a38de80970f..e73505aa7c8 100644 --- a/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php +++ b/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php @@ -137,6 +137,7 @@ public function getPriority(): int protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { $expectedTokens = [T_LIST, T_FUNCTION, CT::T_USE_LAMBDA]; + if (\PHP_VERSION_ID >= 70400) { $expectedTokens[] = T_FN; } @@ -149,6 +150,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $meaningfulTokenBeforeParenthesis = $tokens[$tokens->getPrevMeaningfulToken($index)]; + if ( $meaningfulTokenBeforeParenthesis->isKeyword() && !$meaningfulTokenBeforeParenthesis->isGivenKind($expectedTokens) @@ -209,10 +211,9 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn */ private function fixFunction(Tokens $tokens, int $startFunctionIndex): bool { - $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startFunctionIndex); - $isMultiline = false; + $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startFunctionIndex); $firstWhitespaceIndex = $this->findWhitespaceIndexAfterParenthesis($tokens, $startFunctionIndex, $endFunctionIndex); $lastWhitespaceIndex = $this->findWhitespaceIndexAfterParenthesis($tokens, $endFunctionIndex, $startFunctionIndex); @@ -228,6 +229,7 @@ private function fixFunction(Tokens $tokens, int $startFunctionIndex): bool } $newLinesRemoved = $this->ensureSingleLine($tokens, $index); + if (!$newLinesRemoved) { $isMultiline = true; } @@ -294,11 +296,13 @@ private function findWhitespaceIndexAfterParenthesis(Tokens $tokens, int $startP private function ensureSingleLine(Tokens $tokens, int $index): bool { $previousToken = $tokens[$index - 1]; + if ($previousToken->isComment() && 0 !== strpos($previousToken->getContent(), '/*')) { return false; } $content = Preg::replace('/\R\h*/', '', $tokens[$index]->getContent()); + if ('' !== $content) { $tokens[$index] = new Token([T_WHITESPACE, $content]); } else { @@ -317,6 +321,7 @@ private function ensureFunctionFullyMultiline(Tokens $tokens, int $startFunction $searchIndex, [[T_WHITESPACE]] ); + $searchIndex = $prevWhitespaceTokenIndex; } while (null !== $prevWhitespaceTokenIndex && false === strpos($tokens[$prevWhitespaceTokenIndex]->getContent(), "\n") @@ -400,6 +405,7 @@ private function fixNewline(Tokens $tokens, int $index, string $indentation, boo } $nextMeaningfulTokenIndex = $tokens->getNextMeaningfulToken($index); + if ($tokens[$nextMeaningfulTokenIndex]->equals(')')) { return; } diff --git a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php index 7da5ab1c0fa..0ae435d4c97 100644 --- a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php +++ b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php @@ -31,7 +31,6 @@ /** * @author Andreas Möller - * @author SpacePossum */ final class NativeFunctionInvocationFixer extends AbstractFixer implements ConfigurableFixerInterface { @@ -219,7 +218,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn return new FixerConfigurationResolver([ (new FixerOptionBuilder('exclude', 'List of functions to ignore.')) ->setAllowedTypes(['array']) - ->setAllowedValues([static function (array $value) { + ->setAllowedValues([static function (array $value): bool { foreach ($value as $functionName) { if (!\is_string($functionName) || '' === trim($functionName) || trim($functionName) !== $functionName) { throw new InvalidOptionsException(sprintf( @@ -235,7 +234,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->getOption(), (new FixerOptionBuilder('include', 'List of function names or sets to fix. Defined sets are `@internal` (all native functions), `@all` (all global functions) and `@compiler_optimized` (functions that are specially optimized by Zend).')) ->setAllowedTypes(['array']) - ->setAllowedValues([static function (array $value) { + ->setAllowedValues([static function (array $value): bool { foreach ($value as $functionName) { if (!\is_string($functionName) || '' === trim($functionName) || trim($functionName) !== $functionName) { throw new InvalidOptionsException(sprintf( @@ -309,17 +308,18 @@ private function getFunctionFilter(): callable if (\in_array(self::SET_ALL, $this->configuration['include'], true)) { if (\count($exclude) > 0) { - return static function (string $functionName) use ($exclude) { + return static function (string $functionName) use ($exclude): bool { return !isset($exclude[strtolower($functionName)]); }; } - return static function () { + return static function (): bool { return true; }; } $include = []; + if (\in_array(self::SET_INTERNAL, $this->configuration['include'], true)) { $include = $this->getAllInternalFunctionsNormalized(); } elseif (\in_array(self::SET_COMPILER_OPTIMIZED, $this->configuration['include'], true)) { @@ -333,12 +333,12 @@ private function getFunctionFilter(): callable } if (\count($exclude) > 0) { - return static function (string $functionName) use ($include, $exclude) { + return static function (string $functionName) use ($include, $exclude): bool { return isset($include[strtolower($functionName)]) && !isset($exclude[strtolower($functionName)]); }; } - return static function (string $functionName) use ($include) { + return static function (string $functionName) use ($include): bool { return isset($include[strtolower($functionName)]); }; } diff --git a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php index be041cd7e8d..51dd784b41c 100644 --- a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php @@ -134,7 +134,7 @@ private function fixClass(Tokens $tokens, int $index): void continue; } - $typeInfo = $this->resolveAppliableType( + $typeInfo = $this->resolveApplicableType( $propertyIndexes, $this->getAnnotationsFromDocComment('var', $tokens, $docCommentIndex) ); @@ -181,6 +181,7 @@ private function findNextUntypedPropertiesDeclaration(Tokens $tokens, int $index } $properties = []; + while (!$tokens[$index]->equals(';')) { if ($tokens[$index]->isGivenKind(T_VARIABLE)) { $properties[$tokens[$index]->getContent()] = $index; @@ -196,7 +197,7 @@ private function findNextUntypedPropertiesDeclaration(Tokens $tokens, int $index * @param array $propertyIndexes * @param Annotation[] $annotations */ - private function resolveAppliableType(array $propertyIndexes, array $annotations): ?array + private function resolveApplicableType(array $propertyIndexes, array $annotations): ?array { $propertyTypes = []; @@ -231,6 +232,7 @@ private function resolveAppliableType(array $propertyIndexes, array $annotations } $type = array_shift($propertyTypes); + foreach ($propertyTypes as $propertyType) { if ($propertyType !== $type) { return null; diff --git a/src/Fixer/FunctionNotation/StaticLambdaFixer.php b/src/Fixer/FunctionNotation/StaticLambdaFixer.php index c43b09e91e0..1220bb459a9 100644 --- a/src/Fixer/FunctionNotation/StaticLambdaFixer.php +++ b/src/Fixer/FunctionNotation/StaticLambdaFixer.php @@ -23,9 +23,6 @@ use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\Tokenizer\TokensAnalyzer; -/** - * @author SpacePossum - */ final class StaticLambdaFixer extends AbstractFixer { /** diff --git a/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php b/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php index 6681386910e..5448fdf8343 100644 --- a/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php +++ b/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php @@ -188,18 +188,17 @@ private function isMultilined(Tokens $tokens, int $start, int $end): bool private function transform(Tokens $tokens, int $index, ?int $useStart, ?int $useEnd, int $braceOpen, int $return, int $semicolon, int $braceClose): void { $tokensToInsert = [new Token([T_DOUBLE_ARROW, '=>'])]; + if ($tokens->getNextMeaningfulToken($return) === $semicolon) { $tokensToInsert[] = new Token([T_WHITESPACE, ' ']); $tokensToInsert[] = new Token([T_STRING, 'null']); } $tokens->clearRange($semicolon, $braceClose); - $tokens->clearRange($braceOpen + 1, $return); - $tokens->overrideRange($braceOpen, $braceOpen, $tokensToInsert); - if ($useStart) { + if (null !== $useStart) { $tokens->clearRange($useStart, $useEnd); } diff --git a/src/Fixer/Import/GlobalNamespaceImportFixer.php b/src/Fixer/Import/GlobalNamespaceImportFixer.php index 198ecd123ee..269f820d900 100644 --- a/src/Fixer/Import/GlobalNamespaceImportFixer.php +++ b/src/Fixer/Import/GlobalNamespaceImportFixer.php @@ -176,7 +176,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn */ private function importConstants(Tokens $tokens, array $useDeclarations): array { - [$global, $other] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global, $other] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration): bool { return $declaration->isConstant(); }, true); @@ -248,7 +248,7 @@ private function importConstants(Tokens $tokens, array $useDeclarations): array */ private function importFunctions(Tokens $tokens, array $useDeclarations): array { - [$global, $other] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global, $other] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration): bool { return $declaration->isFunction(); }, false); @@ -299,7 +299,7 @@ private function importFunctions(Tokens $tokens, array $useDeclarations): array */ private function importClasses(Tokens $tokens, array $useDeclarations): array { - [$global, $other] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global, $other] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration): bool { return $declaration->isClass(); }, false); @@ -378,7 +378,7 @@ private function importClasses(Tokens $tokens, array $useDeclarations): array $imports = []; foreach ($docBlocks as $index => $docBlock) { - $changed = $this->traverseDocBlockTypes($docBlock, static function (string $type) use ($global, $other, &$imports) { + $changed = $this->traverseDocBlockTypes($docBlock, static function (string $type) use ($global, $other, &$imports): string { if ('\\' !== $type[0]) { return $type; } @@ -490,7 +490,7 @@ private function fullyQualifyConstants(Tokens $tokens, array $useDeclarations): return; } - [$global] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration): bool { return $declaration->isConstant() && !$declaration->isAliased(); }, true); @@ -532,7 +532,7 @@ private function fullyQualifyFunctions(Tokens $tokens, array $useDeclarations): return; } - [$global] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration): bool { return $declaration->isFunction() && !$declaration->isAliased(); }, false); @@ -574,7 +574,7 @@ private function fullyQualifyClasses(Tokens $tokens, array $useDeclarations): vo return; } - [$global] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration) { + [$global] = $this->filterUseDeclarations($useDeclarations, static function (NamespaceUseAnalysis $declaration): bool { return $declaration->isClass() && !$declaration->isAliased(); }, false); @@ -590,7 +590,7 @@ private function fullyQualifyClasses(Tokens $tokens, array $useDeclarations): vo if ($token->isGivenKind(T_DOC_COMMENT)) { $doc = new DocBlock($token->getContent()); - $changed = $this->traverseDocBlockTypes($doc, static function (string $type) use ($global) { + $changed = $this->traverseDocBlockTypes($doc, static function (string $type) use ($global): string { if (!isset($global[strtolower($type)])) { return $type; } diff --git a/src/Fixer/Import/GroupImportFixer.php b/src/Fixer/Import/GroupImportFixer.php index ad18bd055e2..d6e4351d526 100644 --- a/src/Fixer/Import/GroupImportFixer.php +++ b/src/Fixer/Import/GroupImportFixer.php @@ -81,24 +81,24 @@ private function getSameNamespaces(Tokens $tokens): array } $allNamespaceAndType = array_map( - function (NamespaceUseAnalysis $useDeclaration) { + function (NamespaceUseAnalysis $useDeclaration): string { return $this->getNamespaceNameWithSlash($useDeclaration).$useDeclaration->getType(); }, $useDeclarations ); - $sameNamespaces = array_filter(array_count_values($allNamespaceAndType), function (int $count) { + $sameNamespaces = array_filter(array_count_values($allNamespaceAndType), static function (int $count): bool { return $count > 1; }); $sameNamespaces = array_keys($sameNamespaces); - $sameNamespaceAnalysis = array_filter($useDeclarations, function (NamespaceUseAnalysis $useDeclaration) use ($sameNamespaces) { + $sameNamespaceAnalysis = array_filter($useDeclarations, function (NamespaceUseAnalysis $useDeclaration) use ($sameNamespaces): bool { $namespaceNameAndType = $this->getNamespaceNameWithSlash($useDeclaration).$useDeclaration->getType(); return \in_array($namespaceNameAndType, $sameNamespaces, true); }); - usort($sameNamespaceAnalysis, function (NamespaceUseAnalysis $a, NamespaceUseAnalysis $b) { + usort($sameNamespaceAnalysis, function (NamespaceUseAnalysis $a, NamespaceUseAnalysis $b): int { $namespaceA = $this->getNamespaceNameWithSlash($a); $namespaceB = $this->getNamespaceNameWithSlash($b); diff --git a/src/Fixer/Import/OrderedImportsFixer.php b/src/Fixer/Import/OrderedImportsFixer.php index 3cfcc5a9b0c..ca2ba1466f4 100644 --- a/src/Fixer/Import/OrderedImportsFixer.php +++ b/src/Fixer/Import/OrderedImportsFixer.php @@ -33,7 +33,6 @@ /** * @author Sebastiaan Stok * @author Dariusz RumiƄski - * @author SpacePossum * @author Darius Matulionis * @author Adriano Pilger */ @@ -257,7 +256,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->getOption(), (new FixerOptionBuilder('imports_order', 'Defines the order of import types.')) ->setAllowedTypes(['array', 'null']) - ->setAllowedValues([static function (?array $value) use ($supportedSortTypes) { + ->setAllowedValues([static function (?array $value) use ($supportedSortTypes): bool { if (null !== $value) { $missing = array_diff($supportedSortTypes, $value); if (\count($missing)) { diff --git a/src/Fixer/Import/SingleImportPerStatementFixer.php b/src/Fixer/Import/SingleImportPerStatementFixer.php index 36fb2f5f642..48b68733289 100644 --- a/src/Fixer/Import/SingleImportPerStatementFixer.php +++ b/src/Fixer/Import/SingleImportPerStatementFixer.php @@ -29,7 +29,6 @@ * Fixer for rules defined in PSR2 ¶3. * * @author Dariusz RumiƄski - * @author SpacePossum */ final class SingleImportPerStatementFixer extends AbstractFixer implements WhitespacesAwareFixerInterface { diff --git a/src/Fixer/Import/SingleLineAfterImportsFixer.php b/src/Fixer/Import/SingleLineAfterImportsFixer.php index 7ef368ce6ac..773f25bf4c9 100644 --- a/src/Fixer/Import/SingleLineAfterImportsFixer.php +++ b/src/Fixer/Import/SingleLineAfterImportsFixer.php @@ -28,7 +28,7 @@ * Fixer for rules defined in PSR2 ¶3. * * @author Ceeram - * @author Graham Campbell + * @author Graham Campbell */ final class SingleLineAfterImportsFixer extends AbstractFixer implements WhitespacesAwareFixerInterface { diff --git a/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php b/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php index dd7b8244333..5f932e2e988 100644 --- a/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php +++ b/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php @@ -124,13 +124,13 @@ private function storeImports(Tokens $tokens, int $startIndex, int $endIndex): v if ($tokens[$index]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_OPEN)) { $groupEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_GROUP_IMPORT_BRACE, $index); $groupImports = array_map( - static function (string $import) { + static function (string $import): string { return trim($import); }, explode(',', $tokens->generatePartialCode($index + 1, $groupEndIndex - 1)) ); foreach ($groupImports as $groupImport) { - $groupImportParts = array_map(static function (string $import) { + $groupImportParts = array_map(static function (string $import): string { return trim($import); }, explode(' as ', $groupImport)); if (2 === \count($groupImportParts)) { diff --git a/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php b/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php index cf7063e0a2c..cc53bfde3d7 100644 --- a/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php +++ b/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class CombineConsecutiveIssetsFixer extends AbstractFixer { /** @@ -97,7 +94,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // clone what we want to move, do not clone '(' and ')' of the 'isset' statement we're merging $clones = $this->getTokenClones($tokens, \array_slice($nextIssetInfo, 1, -1)); - // clean up no the tokens of the 'isset' statement we're merging + // clean up now the tokens of the 'isset' statement we're merging $this->clearTokens($tokens, array_merge($nextIssetInfo, [$issetIndex, $booleanAndTokenIndex])); // insert the tokens to create the new statement diff --git a/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php b/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php index 007550f575c..6a595b69c8c 100644 --- a/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php +++ b/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class CombineConsecutiveUnsetsFixer extends AbstractFixer { /** @@ -122,7 +119,7 @@ private function clearOffsetTokens(Tokens $tokens, int $offset, array $indices): * * closing brace index * * end semicolon index * - * Or the index to where the method looked for an call. + * Or the index to where the method looked for a call. * * @return int|int[] */ diff --git a/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php b/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php index 2546e7a2628..c1320344963 100644 --- a/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php +++ b/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php @@ -27,7 +27,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum */ final class DeclareEqualNormalizeFixer extends AbstractFixer implements ConfigurableFixerInterface { diff --git a/src/Fixer/LanguageConstruct/DirConstantFixer.php b/src/Fixer/LanguageConstruct/DirConstantFixer.php index 96e02938325..be692bc2663 100644 --- a/src/Fixer/LanguageConstruct/DirConstantFixer.php +++ b/src/Fixer/LanguageConstruct/DirConstantFixer.php @@ -63,7 +63,8 @@ public function getPriority(): int protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { $currIndex = 0; - while (null !== $currIndex) { + + do { $boundaries = $this->find('dirname', $tokens, $currIndex, $tokens->count() - 1); if (null === $boundaries) { return; @@ -78,12 +79,14 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $fileCandidateRightIndex = $tokens->getPrevMeaningfulToken($closeParenthesis); $trailingCommaIndex = null; + if ($tokens[$fileCandidateRightIndex]->equals(',')) { $trailingCommaIndex = $fileCandidateRightIndex; $fileCandidateRightIndex = $tokens->getPrevMeaningfulToken($fileCandidateRightIndex); } $fileCandidateRight = $tokens[$fileCandidateRightIndex]; + if (!$fileCandidateRight->isGivenKind(T_FILE)) { continue; } @@ -98,6 +101,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // get rid of root namespace when it used $namespaceCandidateIndex = $tokens->getPrevMeaningfulToken($functionNameIndex); $namespaceCandidate = $tokens[$namespaceCandidateIndex]; + if ($namespaceCandidate->isGivenKind(T_NS_SEPARATOR)) { $tokens->removeTrailingWhitespace($namespaceCandidateIndex); $tokens->clearAt($namespaceCandidateIndex); @@ -129,6 +133,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // replace constant and remove function name $tokens[$fileCandidateLeftIndex] = new Token([T_DIR, '__DIR__']); $tokens->clearTokenAndMergeSurroundingWhitespace($functionNameIndex); - } + } while (null !== $currIndex); } } diff --git a/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php b/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php index df2d1f7135d..94411090e5b 100644 --- a/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php +++ b/src/Fixer/LanguageConstruct/ErrorSuppressionFixer.php @@ -78,7 +78,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return $tokens->isAnyTokenKindsFound(['@', T_STRING]); + return $tokens->isTokenKindFound(T_STRING); } /** @@ -116,7 +116,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { $functionsAnalyzer = new FunctionsAnalyzer(); - $excludedFunctions = array_map(static function (string $function) { + $excludedFunctions = array_map(static function (string $function): string { return strtolower($function); }, $this->configuration[self::OPTION_NOISE_REMAINING_USAGES_EXCLUDE]); @@ -136,6 +136,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $functionIndex = $index; $startIndex = $index; $prevIndex = $tokens->getPrevMeaningfulToken($index); + if ($tokens[$prevIndex]->isGivenKind(T_NS_SEPARATOR)) { $startIndex = $prevIndex; $prevIndex = $tokens->getPrevMeaningfulToken($startIndex); @@ -174,8 +175,8 @@ private function isDeprecationErrorCall(Tokens $tokens, int $index): bool } $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextTokenOfKind($index, [T_STRING, '('])); - $prevIndex = $tokens->getPrevMeaningfulToken($endBraceIndex); + if ($tokens[$prevIndex]->equals(',')) { $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex); } diff --git a/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php b/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php index ba315bfa0f6..40ce735ef55 100644 --- a/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php +++ b/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php @@ -28,9 +28,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class FunctionToConstantFixer extends AbstractFixer implements ConfigurableFixerInterface { /** diff --git a/src/Fixer/LanguageConstruct/IsNullFixer.php b/src/Fixer/LanguageConstruct/IsNullFixer.php index 747347f6454..405c6c81348 100644 --- a/src/Fixer/LanguageConstruct/IsNullFixer.php +++ b/src/Fixer/LanguageConstruct/IsNullFixer.php @@ -75,9 +75,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { static $sequenceNeeded = [[T_STRING, 'is_null'], '(']; $functionsAnalyzer = new FunctionsAnalyzer(); - $currIndex = 0; - while (null !== $currIndex) { + + do { $matches = $tokens->findSequence($sequenceNeeded, $currIndex, $tokens->count() - 1, false); // stop looping if didn't find any new matches @@ -96,6 +96,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $next = $tokens->getNextMeaningfulToken($currIndex); + if ($tokens[$next]->equals(')')) { continue; } @@ -112,6 +113,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // check if inversion being used, text comparison is due to not existing constant $isInvertedNullCheck = false; + if ($tokens[$prevTokenIndex]->equals('!')) { $isInvertedNullCheck = true; @@ -123,6 +125,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // before getting rind of `()` around a parameter, ensure it's not assignment/ternary invariant $referenceEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $matches[1]); $isContainingDangerousConstructs = false; + for ($paramTokenIndex = $matches[1]; $paramTokenIndex <= $referenceEnd; ++$paramTokenIndex) { if (\in_array($tokens[$paramTokenIndex]->getContent(), ['?', '?:', '=', '??'], true)) { $isContainingDangerousConstructs = true; @@ -139,6 +142,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // possible trailing comma removed $prevIndex = $tokens->getPrevMeaningfulToken($referenceEnd); + if ($tokens[$prevIndex]->equals(',')) { $tokens->clearTokenAndMergeSurroundingWhitespace($prevIndex); } @@ -171,6 +175,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // nested is_null calls support $currIndex = $isNullIndex; - } + } while (null !== $currIndex); } } diff --git a/src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php b/src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php index 272827449ea..af7f65d6048 100644 --- a/src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php +++ b/src/Fixer/LanguageConstruct/NoUnsetOnPropertyFixer.php @@ -83,7 +83,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - $isLastUnset = true; // yes, last - we reverse the array below + $isLastUnset = true; // "last" as we reverse the array below + foreach (array_reverse($unsetsInfo) as $unsetInfo) { $this->updateTokens($tokens, $unsetInfo, $isLastUnset); $isLastUnset = false; @@ -101,8 +102,8 @@ private function getUnsetsInfo(Tokens $tokens, int $index): array $unsetStart = $tokens->getNextTokenOfKind($index, ['(']); $unsetEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $unsetStart); $isFirst = true; - $unsets = []; + foreach ($argumentsAnalyzer->getArguments($tokens, $unsetStart, $unsetEnd) as $startIndex => $endIndex) { $startIndex = $tokens->getNextMeaningfulToken($startIndex - 1); $endIndex = $tokens->getPrevMeaningfulToken($endIndex + 1); @@ -122,11 +123,14 @@ private function isProperty(Tokens $tokens, int $index, int $endIndex): bool { if ($tokens[$index]->isGivenKind(T_VARIABLE)) { $nextIndex = $tokens->getNextMeaningfulToken($index); + if (null === $nextIndex || !$tokens[$nextIndex]->isGivenKind(T_OBJECT_OPERATOR)) { return false; } + $nextIndex = $tokens->getNextMeaningfulToken($nextIndex); $nextNextIndex = $tokens->getNextMeaningfulToken($nextIndex); + if (null !== $nextNextIndex && $nextNextIndex < $endIndex) { return false; } @@ -137,6 +141,7 @@ private function isProperty(Tokens $tokens, int $index, int $endIndex): bool if ($tokens[$index]->isGivenKind([T_NS_SEPARATOR, T_STRING])) { $nextIndex = $tokens->getTokenNotOfKindsSibling($index, 1, [T_DOUBLE_COLON, T_NS_SEPARATOR, T_STRING]); $nextNextIndex = $tokens->getNextMeaningfulToken($nextIndex); + if (null !== $nextNextIndex && $nextNextIndex < $endIndex) { return false; } @@ -166,7 +171,7 @@ private function isAnyUnsetToTransform(array $unsetsInfo): bool */ private function updateTokens(Tokens $tokens, array $unsetInfo, bool $isLastUnset): void { - // if entry is first and to be transform we remove leading "unset(" + // if entry is first and to be transformed we remove leading "unset(" if ($unsetInfo['isFirst'] && $unsetInfo['isToTransform']) { $braceIndex = $tokens->getPrevTokenOfKind($unsetInfo['startIndex'], ['(']); $unsetIndex = $tokens->getPrevTokenOfKind($braceIndex, [[T_UNSET]]); diff --git a/src/Fixer/ListNotation/ListSyntaxFixer.php b/src/Fixer/ListNotation/ListSyntaxFixer.php index e6df93ba488..bdd35d7c606 100644 --- a/src/Fixer/ListNotation/ListSyntaxFixer.php +++ b/src/Fixer/ListNotation/ListSyntaxFixer.php @@ -27,9 +27,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class ListSyntaxFixer extends AbstractFixer implements ConfigurableFixerInterface { /** diff --git a/src/Fixer/NamespaceNotation/NoBlankLinesBeforeNamespaceFixer.php b/src/Fixer/NamespaceNotation/NoBlankLinesBeforeNamespaceFixer.php index 9a88263dad3..96bc14b0851 100644 --- a/src/Fixer/NamespaceNotation/NoBlankLinesBeforeNamespaceFixer.php +++ b/src/Fixer/NamespaceNotation/NoBlankLinesBeforeNamespaceFixer.php @@ -21,7 +21,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class NoBlankLinesBeforeNamespaceFixer extends AbstractLinesBeforeNamespaceFixer { diff --git a/src/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixer.php b/src/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixer.php index f3d46ce66ca..667b1da55f0 100644 --- a/src/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixer.php +++ b/src/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixer.php @@ -21,7 +21,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class SingleBlankLineBeforeNamespaceFixer extends AbstractLinesBeforeNamespaceFixer { diff --git a/src/Fixer/Naming/NoHomoglyphNamesFixer.php b/src/Fixer/Naming/NoHomoglyphNamesFixer.php index 0f16b07903f..40a40aa4f12 100644 --- a/src/Fixer/Naming/NoHomoglyphNamesFixer.php +++ b/src/Fixer/Naming/NoHomoglyphNamesFixer.php @@ -232,9 +232,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - $replaced = Preg::replaceCallback('/[^[:ascii:]]/u', static function (array $matches) { - return self::$replacements[$matches[0]] ?? $matches[0] - ; + $replaced = Preg::replaceCallback('/[^[:ascii:]]/u', static function (array $matches): string { + return self::$replacements[$matches[0]] ?? $matches[0]; }, $token->getContent(), -1, $count); if ($count) { diff --git a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php index 8ea85fc083a..55962f8534e 100644 --- a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php +++ b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php @@ -31,7 +31,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum */ final class BinaryOperatorSpacesFixer extends AbstractFixer implements ConfigurableFixerInterface { @@ -297,7 +296,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void --$index; } - if (\count($this->alignOperatorTokens)) { + if (\count($this->alignOperatorTokens) > 0) { $this->fixAlignment($tokens, $this->alignOperatorTokens); } } @@ -314,7 +313,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->getOption(), (new FixerOptionBuilder('operators', 'Dictionary of `binary operator` => `fix strategy` values that differ from the default strategy.')) ->setAllowedTypes(['array']) - ->setAllowedValues([static function (array $option) { + ->setAllowedValues([static function (array $option): bool { foreach ($option as $operator => $value) { if (!\in_array($operator, self::SUPPORTED_OPERATORS, true)) { throw new InvalidOptionsException( diff --git a/src/Fixer/Operator/ConcatSpaceFixer.php b/src/Fixer/Operator/ConcatSpaceFixer.php index afb2cb979c1..f146b072c9f 100644 --- a/src/Fixer/Operator/ConcatSpaceFixer.php +++ b/src/Fixer/Operator/ConcatSpaceFixer.php @@ -27,7 +27,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum */ final class ConcatSpaceFixer extends AbstractFixer implements ConfigurableFixerInterface { diff --git a/src/Fixer/Operator/NewWithBracesFixer.php b/src/Fixer/Operator/NewWithBracesFixer.php index ebbe728b81d..c361c2c134e 100644 --- a/src/Fixer/Operator/NewWithBracesFixer.php +++ b/src/Fixer/Operator/NewWithBracesFixer.php @@ -121,7 +121,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // entrance into array index syntax - need to look for exit while ($nextToken->equals('[') || $nextToken->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN)) { - $nextIndex = $tokens->findBlockEnd($tokens->detectBlockType($nextToken)['type'], $nextIndex) + 1; + $nextIndex = $tokens->findBlockEnd(Tokens::detectBlockType($nextToken)['type'], $nextIndex) + 1; $nextToken = $tokens[$nextIndex]; } diff --git a/src/Fixer/Operator/OperatorLinebreakFixer.php b/src/Fixer/Operator/OperatorLinebreakFixer.php index 55c6b9ad738..4904b628d50 100644 --- a/src/Fixer/Operator/OperatorLinebreakFixer.php +++ b/src/Fixer/Operator/OperatorLinebreakFixer.php @@ -180,7 +180,7 @@ private function getExcludedIndices(Tokens $tokens): array private function getCasesColonsForSwitch(Tokens $tokens, int $switchIndex): array { return array_map( - static function (CaseAnalysis $caseAnalysis) { + static function (CaseAnalysis $caseAnalysis): int { return $caseAnalysis->getColonIndex(); }, (new SwitchAnalyzer())->getSwitchAnalysis($tokens, $switchIndex)->getCases() @@ -277,11 +277,13 @@ private function fixMoveToTheEnd(Tokens $tokens, array $operatorIndices): void private function getReplacementsAndClear(Tokens $tokens, array $indices, int $direction): array { return array_map( - static function (int $index) use ($tokens, $direction) { + static function (int $index) use ($tokens, $direction): Token { $clone = $tokens[$index]; + if ($tokens[$index + $direction]->isWhitespace()) { $tokens->clearAt($index + $direction); } + $tokens->clearAt($index); return $clone; @@ -312,7 +314,7 @@ private static function getNonBooleanOperators(): array [T_POW_EQUAL], [T_SL], [T_SL_EQUAL], [T_SR], [T_SR_EQUAL], [T_XOR_EQUAL], [T_COALESCE], [T_SPACESHIP], ], - array_map(function ($id) { return [$id]; }, Token::getObjectOperatorKinds()) + array_map(static function ($id): array { return [$id]; }, Token::getObjectOperatorKinds()) ); } } diff --git a/src/Fixer/Operator/TernaryOperatorSpacesFixer.php b/src/Fixer/Operator/TernaryOperatorSpacesFixer.php index fe49cac952e..a03639d05fb 100644 --- a/src/Fixer/Operator/TernaryOperatorSpacesFixer.php +++ b/src/Fixer/Operator/TernaryOperatorSpacesFixer.php @@ -154,7 +154,7 @@ private function belongsToAlternativeSyntax(Tokens $tokens, int $index): bool private function getColonIndicesForSwitch(Tokens $tokens, int $switchIndex): array { return array_map( - static function (CaseAnalysis $caseAnalysis) { + static function (CaseAnalysis $caseAnalysis): int { return $caseAnalysis->getColonIndex(); }, (new SwitchAnalyzer())->getSwitchAnalysis($tokens, $switchIndex)->getCases() diff --git a/src/Fixer/Operator/TernaryToElvisOperatorFixer.php b/src/Fixer/Operator/TernaryToElvisOperatorFixer.php index 44d8527b441..9a643f617ad 100644 --- a/src/Fixer/Operator/TernaryToElvisOperatorFixer.php +++ b/src/Fixer/Operator/TernaryToElvisOperatorFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class TernaryToElvisOperatorFixer extends AbstractFixer { /** diff --git a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php index 9d554be6e85..738c0e6d2ec 100644 --- a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php @@ -27,7 +27,6 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author SpacePossum * @author Dariusz RumiƄski */ final class PhpUnitDedicateAssertFixer extends AbstractPhpUnitFixer implements ConfigurableFixerInterface diff --git a/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php b/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php index 5dbf6f0c52f..0aeffb63eca 100644 --- a/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php @@ -190,7 +190,7 @@ private function updateDocBlock(Tokens $tokens, int $docBlockIndex): void continue; } - $newLineContent = Preg::replaceCallback('/(@depends\s+)(.+)(\b)/', function (array $matches) { + $newLineContent = Preg::replaceCallback('/(@depends\s+)(.+)(\b)/', function (array $matches): string { return sprintf( '%s%s%s', $matches[1], diff --git a/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php b/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php index 3b5b11ae068..2c171a31e76 100644 --- a/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php @@ -149,7 +149,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $importedOriginalClassesMap = []; $currIndex = 0; - while (null !== $currIndex) { + while (true) { $currIndex = $tokens->getNextTokenOfKind($currIndex, [[T_STRING]]); if (null === $currIndex) { @@ -157,6 +157,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $prevIndex = $tokens->getPrevMeaningfulToken($currIndex); + if ($tokens[$prevIndex]->isGivenKind([T_CONST, T_DOUBLE_COLON])) { continue; } diff --git a/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php b/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php index e8d890c4245..c3b708b0bb8 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php @@ -165,9 +165,6 @@ private function applyTestPrefix(Tokens $tokens, int $startIndex, int $endIndex) } } - /** - * @param int$index - */ private function isTestMethod(Tokens $tokens, int $index): bool { // Check if we are dealing with a (non abstract, non lambda) function diff --git a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php index 7eb05e06664..d543a96dc97 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php @@ -360,7 +360,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->getOption(), (new FixerOptionBuilder('methods', 'Dictionary of `method` => `call_type` values that differ from the default strategy.')) ->setAllowedTypes(['array']) - ->setAllowedValues([static function (array $option) use ($thisFixer) { + ->setAllowedValues([static function (array $option) use ($thisFixer): bool { foreach ($option as $method => $value) { if (!isset($thisFixer->staticMethods[$method])) { throw new InvalidOptionsException( diff --git a/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php b/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php index e23fb5e4ce8..01f2d4b6cb4 100644 --- a/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php +++ b/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php @@ -122,10 +122,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $whitespace = ''; $previousIndex = $index - 1; + if ($tokens[$previousIndex]->isWhitespace()) { $whitespace = $tokens[$previousIndex]->getContent(); --$previousIndex; } + if ($tokens[$previousIndex]->isGivenKind(T_OPEN_TAG)) { $whitespace = Preg::replace('/\S/', '', $tokens[$previousIndex]->getContent()).$whitespace; } @@ -147,6 +149,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $line = ltrim($line); + if ($token->isGivenKind(T_COMMENT) && (!isset($line[0]) || '*' !== $line[0])) { continue; } diff --git a/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php b/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php index a72c09c6cd2..de6939c3ad7 100644 --- a/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php +++ b/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php @@ -27,7 +27,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski */ final class GeneralPhpdocAnnotationRemoveFixer extends AbstractFixer implements ConfigurableFixerInterface diff --git a/src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php b/src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php index e7253e4d3fa..a45f36b6a05 100644 --- a/src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php +++ b/src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php @@ -101,7 +101,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->getOption(), (new FixerOptionBuilder('replacements', 'A map of tags to replace.')) ->setAllowedTypes(['array']) - ->setNormalizer(function (Options $options, $value) { + ->setNormalizer(static function (Options $options, $value): array { $normalizedValue = []; foreach ($value as $from => $to) { @@ -199,7 +199,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $tokens[$index] = new Token([T_DOC_COMMENT, Preg::replaceCallback( $regex, - function (array $matches) use ($caseInsensitive, $replacements) { + static function (array $matches) use ($caseInsensitive, $replacements) { if ($caseInsensitive) { $matches[1] = strtolower($matches[1]); } diff --git a/src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.php b/src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.php index 1d700392111..ec3dadda84b 100644 --- a/src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.php +++ b/src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.php @@ -22,7 +22,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class NoBlankLinesAfterPhpdocFixer extends AbstractFixer { diff --git a/src/Fixer/Phpdoc/NoEmptyPhpdocFixer.php b/src/Fixer/Phpdoc/NoEmptyPhpdocFixer.php index 64154cd962e..843bf01daa8 100644 --- a/src/Fixer/Phpdoc/NoEmptyPhpdocFixer.php +++ b/src/Fixer/Phpdoc/NoEmptyPhpdocFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Preg; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NoEmptyPhpdocFixer extends AbstractFixer { /** diff --git a/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php b/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php index fb3fa346f4c..5548e8032e0 100644 --- a/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php +++ b/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php @@ -109,6 +109,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $namespaceUseAnalyzer = new NamespaceUsesAnalyzer(); $shortNames = []; + foreach ($namespaceUseAnalyzer->getDeclarationsFromTokens($tokens) as $namespaceUseAnalysis) { $shortNames[strtolower($namespaceUseAnalysis->getShortName())] = '\\'.strtolower($namespaceUseAnalysis->getFullName()); } @@ -119,7 +120,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $content = $initialContent = $token->getContent(); - $documentedElementIndex = $this->findDocumentedElement($tokens, $index); if (null === $documentedElementIndex) { @@ -176,15 +176,15 @@ private function findDocumentedElement(Tokens $tokens, int $docCommentIndex): ?i do { $index = $tokens->getNextMeaningfulToken($index); - if (null === $index || $tokens[$index]->isGivenKind([T_FUNCTION, T_CLASS, T_INTERFACE])) { + if (null === $index || $tokens[$index]->isGivenKind([T_FUNCTION, T_CLASS, T_INTERFACE, T_TRAIT])) { return $index; } } while ($tokens[$index]->isGivenKind([T_ABSTRACT, T_FINAL, T_STATIC, T_PRIVATE, T_PROTECTED, T_PUBLIC])); - $index = $tokens->getNextMeaningfulToken($docCommentIndex); - $kindsBeforeProperty = [T_STATIC, T_PRIVATE, T_PROTECTED, T_PUBLIC, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, T_STRING, T_NS_SEPARATOR]; + $index = $tokens->getNextMeaningfulToken($docCommentIndex); + if (!$tokens[$index]->isGivenKind($kindsBeforeProperty)) { return null; } @@ -245,11 +245,13 @@ private function fixFunctionDocComment(string $content, Tokens $tokens, int $fun */ private function fixPropertyDocComment(string $content, Tokens $tokens, int $index, array $shortNames): string { + $propertyModifierKinds = [T_STATIC, T_PRIVATE, T_PROTECTED, T_PUBLIC]; + $docBlock = new DocBlock($content); do { $index = $tokens->getNextMeaningfulToken($index); - } while ($tokens[$index]->isGivenKind([T_STATIC, T_PRIVATE, T_PROTECTED, T_PUBLIC])); + } while ($tokens[$index]->isGivenKind($propertyModifierKinds)); $propertyTypeInfo = $this->getPropertyTypeInfo($tokens, $index); @@ -338,15 +340,16 @@ private function getPropertyTypeInfo(Tokens $tokens, int $index): array private function parseTypeHint(Tokens $tokens, int $index): array { $allowsNull = false; + if ($tokens[$index]->isGivenKind(CT::T_NULLABLE_TYPE)) { $allowsNull = true; $index = $tokens->getNextMeaningfulToken($index); } $type = ''; + while ($tokens[$index]->isGivenKind([T_NS_SEPARATOR, T_STATIC, T_STRING, CT::T_ARRAY_TYPEHINT, T_CALLABLE])) { $type .= $tokens[$index]->getContent(); - $index = $tokens->getNextMeaningfulToken($index); } @@ -384,6 +387,7 @@ private function annotationIsSuperfluous(Annotation $annotation, array $info, ar } $actualTypes = null === $info['type'] ? [] : [$info['type']]; + if ($info['allows_null']) { $actualTypes[] = 'null'; } diff --git a/src/Fixer/Phpdoc/PhpdocAlignFixer.php b/src/Fixer/Phpdoc/PhpdocAlignFixer.php index 2ed92d525cf..986706ea292 100644 --- a/src/Fixer/Phpdoc/PhpdocAlignFixer.php +++ b/src/Fixer/Phpdoc/PhpdocAlignFixer.php @@ -34,7 +34,7 @@ * @author Fabien Potencier * @author Jordi Boggiano * @author Sebastiaan Stok - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski */ final class PhpdocAlignFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface diff --git a/src/Fixer/Phpdoc/PhpdocIndentFixer.php b/src/Fixer/Phpdoc/PhpdocIndentFixer.php index 2ccf3f42fd3..c40bc9d3ed1 100644 --- a/src/Fixer/Phpdoc/PhpdocIndentFixer.php +++ b/src/Fixer/Phpdoc/PhpdocIndentFixer.php @@ -25,7 +25,7 @@ /** * @author Ceeram - * @author Graham Campbell + * @author Graham Campbell */ final class PhpdocIndentFixer extends AbstractFixer { diff --git a/src/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixer.php b/src/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixer.php index 2da42290e51..9d7569e9876 100644 --- a/src/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixer.php +++ b/src/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixer.php @@ -26,9 +26,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class PhpdocInlineTagNormalizerFixer extends AbstractFixer implements ConfigurableFixerInterface { /** @@ -89,11 +86,11 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $content = Preg::replaceCallback( sprintf( '#(?:@{+|{+\h*@)\h*(%s)s?([^}]*)(?:}+)#i', - implode('|', array_map(function ($tag) { + implode('|', array_map(static function (string $tag): string { return preg_quote($tag, '/'); }, $this->configuration['tags'])) ), - function (array $matches) { + static function (array $matches): string { $doc = trim($matches[2]); if ('' === $doc) { diff --git a/src/Fixer/Phpdoc/PhpdocLineSpanFixer.php b/src/Fixer/Phpdoc/PhpdocLineSpanFixer.php index 3fbf0ec7405..9be0e621254 100644 --- a/src/Fixer/Phpdoc/PhpdocLineSpanFixer.php +++ b/src/Fixer/Phpdoc/PhpdocLineSpanFixer.php @@ -96,19 +96,16 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { $analyzer = new TokensAnalyzer($tokens); - $elements = $analyzer->getClassyElements(); - - foreach ($elements as $index => $element) { + foreach ($analyzer->getClassyElements() as $index => $element) { if (!$this->hasDocBlock($tokens, $index)) { continue; } - $type = $element['type']; $docIndex = $this->getDocBlockIndex($tokens, $index); $doc = new DocBlock($tokens[$docIndex]->getContent()); - if ('multi' === $this->configuration[$type]) { - $doc->makeMultiLine($originalIndent = WhitespacesAnalyzer::detectIndent($tokens, $docIndex), $this->whitespacesConfig->getLineEnding()); + if ('multi' === $this->configuration[$element['type']]) { + $doc->makeMultiLine(WhitespacesAnalyzer::detectIndent($tokens, $docIndex), $this->whitespacesConfig->getLineEnding()); } else { $doc->makeSingleLine(); } @@ -126,9 +123,7 @@ private function hasDocBlock(Tokens $tokens, int $index): bool private function getDocBlockIndex(Tokens $tokens, int $index): int { - do { - $index = $tokens->getPrevNonWhitespace($index); - } while ($tokens[$index]->isGivenKind([ + $propertyPartKinds = [ T_PUBLIC, T_PROTECTED, T_PRIVATE, @@ -141,7 +136,11 @@ private function getDocBlockIndex(Tokens $tokens, int $index): int T_NS_SEPARATOR, CT::T_ARRAY_TYPEHINT, CT::T_NULLABLE_TYPE, - ])); + ]; + + do { + $index = $tokens->getPrevNonWhitespace($index); + } while ($tokens[$index]->isGivenKind($propertyPartKinds)); return $index; } diff --git a/src/Fixer/Phpdoc/PhpdocNoAccessFixer.php b/src/Fixer/Phpdoc/PhpdocNoAccessFixer.php index 439f0d53d80..a168a9137fe 100644 --- a/src/Fixer/Phpdoc/PhpdocNoAccessFixer.php +++ b/src/Fixer/Phpdoc/PhpdocNoAccessFixer.php @@ -20,7 +20,7 @@ use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; /** - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski */ final class PhpdocNoAccessFixer extends AbstractProxyFixer diff --git a/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php b/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php index 95ade7c5992..b5af8fab66a 100644 --- a/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php +++ b/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php @@ -29,9 +29,8 @@ /** * Case sensitive tag replace fixer (does not process inline tags like {@inheritdoc}). * - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski - * @author SpacePossum */ final class PhpdocNoAliasTagFixer extends AbstractProxyFixer implements ConfigurableFixerInterface { diff --git a/src/Fixer/Phpdoc/PhpdocNoEmptyReturnFixer.php b/src/Fixer/Phpdoc/PhpdocNoEmptyReturnFixer.php index f2cd3f94ee9..bc5ec718c8d 100644 --- a/src/Fixer/Phpdoc/PhpdocNoEmptyReturnFixer.php +++ b/src/Fixer/Phpdoc/PhpdocNoEmptyReturnFixer.php @@ -24,7 +24,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class PhpdocNoEmptyReturnFixer extends AbstractFixer { diff --git a/src/Fixer/Phpdoc/PhpdocNoPackageFixer.php b/src/Fixer/Phpdoc/PhpdocNoPackageFixer.php index 6b009a01c90..d7da1d1aeb8 100644 --- a/src/Fixer/Phpdoc/PhpdocNoPackageFixer.php +++ b/src/Fixer/Phpdoc/PhpdocNoPackageFixer.php @@ -20,7 +20,7 @@ use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; /** - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski */ final class PhpdocNoPackageFixer extends AbstractProxyFixer diff --git a/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php b/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php index 17ac23b62e5..ef99675ffbe 100644 --- a/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php +++ b/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php @@ -25,8 +25,6 @@ /** * Remove inheritdoc tags from classy that does not inherit. - * - * @author SpacePossum */ final class PhpdocNoUselessInheritdocFixer extends AbstractFixer { @@ -126,7 +124,7 @@ private function fixToken(Tokens $tokens, int $tokenIndex): void $count = 0; $content = Preg::replaceCallback( '#(\h*(?:@{*|{*\h*@)\h*inheritdoc\h*)([^}]*)((?:}*)\h*)#i', - static function (array $matches) { + static function (array $matches): string { return ' '.$matches[2]; }, $tokens[$tokenIndex]->getContent(), diff --git a/src/Fixer/Phpdoc/PhpdocOrderByValueFixer.php b/src/Fixer/Phpdoc/PhpdocOrderByValueFixer.php index cae0f4be615..28bee070667 100644 --- a/src/Fixer/Phpdoc/PhpdocOrderByValueFixer.php +++ b/src/Fixer/Phpdoc/PhpdocOrderByValueFixer.php @@ -202,11 +202,11 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ->setAllowedValues([ new AllowedValueSubset($allowedValues), ]) - ->setNormalizer(function (Options $options, $value) { + ->setNormalizer(static function (Options $options, $value): array { $normalized = []; - foreach ($value as $index => $annotation) { - // since we will be using strtolower on the input annotations when building the sorting + foreach ($value as $annotation) { + // since we will be using "strtolower" on the input annotations when building the sorting // map we must match the type in lower case as well $normalized[$annotation] = strtolower($annotation); } diff --git a/src/Fixer/Phpdoc/PhpdocOrderFixer.php b/src/Fixer/Phpdoc/PhpdocOrderFixer.php index 6ae218c5a61..ba12687f496 100644 --- a/src/Fixer/Phpdoc/PhpdocOrderFixer.php +++ b/src/Fixer/Phpdoc/PhpdocOrderFixer.php @@ -23,7 +23,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class PhpdocOrderFixer extends AbstractFixer { diff --git a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php index bdf7a2468a7..a30e42022e0 100644 --- a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php +++ b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php @@ -29,9 +29,6 @@ use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\OptionsResolver\Options; -/** - * @author SpacePossum - */ final class PhpdocReturnSelfReferenceFixer extends AbstractFixer implements ConfigurableFixerInterface { /** @@ -125,6 +122,7 @@ public function getPriority(): int protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { $tokensAnalyzer = new TokensAnalyzer($tokens); + foreach ($tokensAnalyzer->getClassyElements() as $index => $element) { if ('method' === $element['type']) { $this->fixMethod($tokens, $index); @@ -217,9 +215,9 @@ private function fixMethod(Tokens $tokens, int $index): void } $newTypes = []; + foreach ($types as $type) { - $lower = strtolower($type); - $newTypes[] = $this->configuration['replacements'][$lower] ?? $type; + $newTypes[] = $this->configuration['replacements'][strtolower($type)] ?? $type; } if ($types === $newTypes) { diff --git a/src/Fixer/Phpdoc/PhpdocScalarFixer.php b/src/Fixer/Phpdoc/PhpdocScalarFixer.php index 047e7743d45..cbfdfe65771 100644 --- a/src/Fixer/Phpdoc/PhpdocScalarFixer.php +++ b/src/Fixer/Phpdoc/PhpdocScalarFixer.php @@ -25,7 +25,7 @@ use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; /** - * @author Graham Campbell + * @author Graham Campbell */ final class PhpdocScalarFixer extends AbstractPhpdocTypesFixer implements ConfigurableFixerInterface { diff --git a/src/Fixer/Phpdoc/PhpdocSeparationFixer.php b/src/Fixer/Phpdoc/PhpdocSeparationFixer.php index 210c208be70..b8140f62642 100644 --- a/src/Fixer/Phpdoc/PhpdocSeparationFixer.php +++ b/src/Fixer/Phpdoc/PhpdocSeparationFixer.php @@ -25,7 +25,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class PhpdocSeparationFixer extends AbstractFixer { @@ -117,7 +117,7 @@ private function fixDescription(DocBlock $doc): void /** * Make sure the annotations are correctly separated. */ - private function fixAnnotations(DocBlock $doc): string + private function fixAnnotations(DocBlock $doc): void { foreach ($doc->getAnnotations() as $index => $annotation) { $next = $doc->getAnnotation($index + 1); @@ -134,8 +134,6 @@ private function fixAnnotations(DocBlock $doc): string } } } - - return $doc->getContent(); } /** diff --git a/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php b/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php index bc47903d0c3..8ccd3d74eaa 100644 --- a/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php +++ b/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php @@ -24,8 +24,6 @@ /** * Fixer for part of rule defined in PSR5 ¶7.22. - * - * @author SpacePossum */ final class PhpdocSingleLineVarSpacingFixer extends AbstractFixer { diff --git a/src/Fixer/Phpdoc/PhpdocSummaryFixer.php b/src/Fixer/Phpdoc/PhpdocSummaryFixer.php index abb6a7c2684..090ac88f333 100644 --- a/src/Fixer/Phpdoc/PhpdocSummaryFixer.php +++ b/src/Fixer/Phpdoc/PhpdocSummaryFixer.php @@ -25,7 +25,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class PhpdocSummaryFixer extends AbstractFixer implements WhitespacesAwareFixerInterface { diff --git a/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php b/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php index 9cab7e35e5f..735b4e29b01 100644 --- a/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTagTypeFixer.php @@ -28,9 +28,6 @@ use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException; use Symfony\Component\OptionsResolver\Options; -/** - * @author SpacePossum - */ final class PhpdocTagTypeFixer extends AbstractFixer implements ConfigurableFixerInterface { private const TAG_REGEX = '/^(?: @@ -93,7 +90,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $regularExpression = sprintf( '/({?@(?:%s).*?(?:(?=\s\*\/)|(?=\n)}?))/i', implode('|', array_map( - function (string $tag) { + static function (string $tag): string { return preg_quote($tag, '/'); }, array_keys($this->configuration['tags']) @@ -153,7 +150,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn return new FixerConfigurationResolver([ (new FixerOptionBuilder('tags', 'The list of tags to fix')) ->setAllowedTypes(['array']) - ->setAllowedValues([function ($value) { + ->setAllowedValues([static function (array $value): bool { foreach ($value as $type) { if (!\in_array($type, ['annotation', 'inline'], true)) { throw new InvalidOptionsException("Unknown tag type \"{$type}\"."); @@ -185,8 +182,9 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn 'var' => 'annotation', 'version' => 'annotation', ]) - ->setNormalizer(function (Options $options, $value) { + ->setNormalizer(static function (Options $options, $value): array { $normalized = []; + foreach ($value as $tag => $type) { $normalized[strtolower($tag)] = $type; } diff --git a/src/Fixer/Phpdoc/PhpdocToCommentFixer.php b/src/Fixer/Phpdoc/PhpdocToCommentFixer.php index 34da0e85719..b335b4019a8 100644 --- a/src/Fixer/Phpdoc/PhpdocToCommentFixer.php +++ b/src/Fixer/Phpdoc/PhpdocToCommentFixer.php @@ -108,7 +108,7 @@ public function configure(array $configuration = null): void parent::configure($configuration); $this->ignoredTags = array_map( - static function ($tag) { + static function (string $tag): string { return strtolower($tag); }, $this->configuration['ignored_tags'] diff --git a/src/Fixer/Phpdoc/PhpdocTrimFixer.php b/src/Fixer/Phpdoc/PhpdocTrimFixer.php index 52ff0aed0fc..d835fb337ea 100644 --- a/src/Fixer/Phpdoc/PhpdocTrimFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTrimFixer.php @@ -23,7 +23,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class PhpdocTrimFixer extends AbstractFixer { diff --git a/src/Fixer/Phpdoc/PhpdocTypesFixer.php b/src/Fixer/Phpdoc/PhpdocTypesFixer.php index 6a823931a86..7abebd358e0 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesFixer.php @@ -25,7 +25,7 @@ use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; /** - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski */ final class PhpdocTypesFixer extends AbstractPhpdocTypesFixer implements ConfigurableFixerInterface diff --git a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php index 5d5c9ca5c78..8596815da13 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php @@ -175,8 +175,8 @@ private function sortTypes(array $types): array if ('alpha' === $this->configuration['sort_algorithm']) { $types = Utils::stableSort( $types, - static function (string $type) { return $type; }, - static function (string $typeA, string $typeB) { + static function (string $type): string { return $type; }, + static function (string $typeA, string $typeB): int { $regexp = '/^\\??\\\?/'; return strcasecmp( @@ -212,7 +212,7 @@ private function sortJoinedTypes(string $types): string { $types = array_filter( Preg::split('/([^|<{\(]+(?:[<{].*[>}]|\(.+\)(?::.+)?)?)/', $types, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY), - static function (string $value) { + static function (string $value): bool { return '|' !== $value; } ); diff --git a/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php b/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php index 9e4529a1f42..ce533d8aead 100644 --- a/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php +++ b/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php @@ -25,7 +25,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell * @author Dave van der Brugge */ final class PhpdocVarWithoutNameFixer extends AbstractFixer @@ -89,13 +89,15 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - // For people writing static public $foo instead of public static $foo + // For people writing "static public $foo" instead of "public static $foo" if ($tokens[$nextIndex]->isGivenKind(T_STATIC)) { $nextIndex = $tokens->getNextMeaningfulToken($nextIndex); } // We want only doc blocks that are for properties and thus have specified access modifiers next - if (!$tokens[$nextIndex]->isGivenKind([T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR])) { + $propertyModifierKinds = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR]; + + if (!$tokens[$nextIndex]->isGivenKind($propertyModifierKinds)) { continue; } diff --git a/src/Fixer/ReturnNotation/NoUselessReturnFixer.php b/src/Fixer/ReturnNotation/NoUselessReturnFixer.php index e268eb34dcf..7656f950a03 100644 --- a/src/Fixer/ReturnNotation/NoUselessReturnFixer.php +++ b/src/Fixer/ReturnNotation/NoUselessReturnFixer.php @@ -20,9 +20,6 @@ use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class NoUselessReturnFixer extends AbstractFixer { /** diff --git a/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php b/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php index 6cc4bfa9984..8f07b84b700 100644 --- a/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php +++ b/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php @@ -23,9 +23,6 @@ use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\Tokenizer\TokensAnalyzer; -/** - * @author SpacePossum - */ final class ReturnAssignmentFixer extends AbstractFixer { /** @@ -180,7 +177,7 @@ private function fixFunction(Tokens $tokens, int $functionIndex, int $functionOp continue; } - // test if there this is anything in the function body that might + // test if there is anything in the function body that might // change global state or indirect changes (like through references, eval, etc.) if ($tokens[$index]->isGivenKind($riskyKinds)) { diff --git a/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php b/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php index 38c5829cf7f..800c21c13a7 100644 --- a/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php +++ b/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php @@ -22,7 +22,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class SimplifiedNullReturnFixer extends AbstractFixer { diff --git a/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php b/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php index f983a840a4f..79b900434c2 100644 --- a/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php +++ b/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php @@ -28,7 +28,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell * @author Egidijus Girčys */ final class MultilineWhitespaceBeforeSemicolonsFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface diff --git a/src/Fixer/Semicolon/NoEmptyStatementFixer.php b/src/Fixer/Semicolon/NoEmptyStatementFixer.php index 36ba1d3e790..bbd423e148e 100644 --- a/src/Fixer/Semicolon/NoEmptyStatementFixer.php +++ b/src/Fixer/Semicolon/NoEmptyStatementFixer.php @@ -22,7 +22,6 @@ use PhpCsFixer\Tokenizer\TokensAnalyzer; /** - * @author SpacePossum * @author Dariusz RumiƄski */ final class NoEmptyStatementFixer extends AbstractFixer diff --git a/src/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixer.php b/src/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixer.php index 1cc51c05d03..c4030cff0f2 100644 --- a/src/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixer.php +++ b/src/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixer.php @@ -22,7 +22,7 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author Graham Campbell + * @author Graham Campbell */ final class NoSinglelineWhitespaceBeforeSemicolonsFixer extends AbstractFixer { diff --git a/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php b/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php index 484a6c8decc..c9a9131f73a 100644 --- a/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php +++ b/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php @@ -21,9 +21,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class SemicolonAfterInstructionFixer extends AbstractFixer { /** diff --git a/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php b/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php index 53977efe0c7..b2d46ae06cd 100644 --- a/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php +++ b/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php @@ -26,9 +26,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class SpaceAfterSemicolonFixer extends AbstractFixer implements ConfigurableFixerInterface { /** diff --git a/src/Fixer/Strict/DeclareStrictTypesFixer.php b/src/Fixer/Strict/DeclareStrictTypesFixer.php index 12a83d0fe53..077deca99ea 100644 --- a/src/Fixer/Strict/DeclareStrictTypesFixer.php +++ b/src/Fixer/Strict/DeclareStrictTypesFixer.php @@ -24,7 +24,6 @@ /** * @author Jordi Boggiano - * @author SpacePossum */ final class DeclareStrictTypesFixer extends AbstractFixer implements WhitespacesAwareFixerInterface { diff --git a/src/Fixer/Whitespace/ArrayIndentationFixer.php b/src/Fixer/Whitespace/ArrayIndentationFixer.php index 542770fb203..a7504c2a91b 100644 --- a/src/Fixer/Whitespace/ArrayIndentationFixer.php +++ b/src/Fixer/Whitespace/ArrayIndentationFixer.php @@ -197,11 +197,7 @@ private function findExpressionEndIndex(Tokens $tokens, int $index, int $parentS } } - if (null !== $endIndex) { - return $endIndex; - } - - return $tokens->getPrevMeaningfulToken($parentScopeEndIndex); + return $endIndex ?? $tokens->getPrevMeaningfulToken($parentScopeEndIndex); } private function getLineIndentation(Tokens $tokens, int $index): string diff --git a/src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php b/src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php index 1a8364da0f5..c3a560757ad 100644 --- a/src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php +++ b/src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php @@ -31,7 +31,6 @@ /** * @author Dariusz RumiƄski * @author Andreas Möller - * @author SpacePossum */ final class BlankLineBeforeStatementFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { diff --git a/src/Fixer/Whitespace/IndentationTypeFixer.php b/src/Fixer/Whitespace/IndentationTypeFixer.php index a06c2b2534c..fe69de8d8e0 100644 --- a/src/Fixer/Whitespace/IndentationTypeFixer.php +++ b/src/Fixer/Whitespace/IndentationTypeFixer.php @@ -101,7 +101,7 @@ private function fixIndentInComment(Tokens $tokens, int $index): Token $indent = $this->indent; // change indent to expected one - $content = Preg::replaceCallback('/^(?: )+/m', function (array $matches) use ($indent) { + $content = Preg::replaceCallback('/^(?: )+/m', function (array $matches) use ($indent): string { return $this->getExpectedIndent($matches[0], $indent); }, $content); @@ -122,7 +122,7 @@ private function fixIndentToken(Tokens $tokens, int $index): Token $indent = $this->indent; $newContent = Preg::replaceCallback( '/(\R)(\h+)/', // find indent - function (array $matches) use ($indent) { + function (array $matches) use ($indent): string { // normalize mixed indent $content = Preg::replace('/(?:(? - * @author SpacePossum * @author Dariusz RumiƄski */ final class LineEndingFixer extends AbstractFixer implements WhitespacesAwareFixerInterface diff --git a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php index 283b5303359..5aada7e8cc4 100644 --- a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php +++ b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php @@ -33,7 +33,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum */ final class NoExtraBlankLinesFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface { diff --git a/src/FixerFactory.php b/src/FixerFactory.php index ec47fc93585..2ad10fdcd99 100644 --- a/src/FixerFactory.php +++ b/src/FixerFactory.php @@ -156,11 +156,11 @@ public function useRuleSet(RuleSetInterface $ruleSet): self } $fixer = $this->fixersByName[$name]; - $config = $ruleSet->getRuleConfiguration($name); + if (null !== $config) { if ($fixer instanceof ConfigurableFixerInterface) { - if (!\is_array($config) || !\count($config)) { + if (\count($config) < 1) { throw new InvalidFixerConfigurationException($fixer->getName(), 'Configuration must be an array and may not be empty.'); } @@ -223,7 +223,7 @@ private function generateConflictMessage(array $fixerConflicts): string // filter mutual conflicts $report[$fixer] = array_filter( $fixers, - static function (string $candidate) use ($report, $fixer) { + static function (string $candidate) use ($report, $fixer): bool { return !\array_key_exists($candidate, $report) || !\in_array($fixer, $report[$candidate], true); } ); diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index b7c61974d7c..be66ba43529 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -20,7 +20,6 @@ * Set of rules to be used by fixer. * * @author Dariusz RumiƄski - * @author SpacePossum * * @internal */ @@ -95,10 +94,8 @@ public function getRules(): array /** * Resolve input set into group of rules. - * - * @return $this */ - private function resolveSet(array $rules): self + private function resolveSet(array $rules): void { $resolvedRules = []; @@ -120,8 +117,6 @@ private function resolveSet(array $rules): self $resolvedRules = array_filter($resolvedRules); $this->rules = $resolvedRules; - - return $this; } /** diff --git a/src/RuleSet/RuleSetDescriptionInterface.php b/src/RuleSet/RuleSetDescriptionInterface.php index 9fa6e91e8f1..1d4555c8617 100644 --- a/src/RuleSet/RuleSetDescriptionInterface.php +++ b/src/RuleSet/RuleSetDescriptionInterface.php @@ -15,8 +15,6 @@ namespace PhpCsFixer\RuleSet; /** - * @author SpacePossum - * * @internal */ interface RuleSetDescriptionInterface diff --git a/src/RuleSet/RuleSets.php b/src/RuleSet/RuleSets.php index 0d07716fe13..833a386189f 100644 --- a/src/RuleSet/RuleSets.php +++ b/src/RuleSet/RuleSets.php @@ -19,8 +19,6 @@ /** * Set of rule sets to be used by fixer. * - * @author SpacePossum - * * @internal */ final class RuleSets diff --git a/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php b/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php index 51b520ea35e..a2511f56488 100644 --- a/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php +++ b/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php @@ -34,9 +34,9 @@ final class TypeAnalysis implements StartEndTokenAwareAnalysis 'array', 'bool', 'callable', + 'float', 'int', 'iterable', - 'float', 'mixed', 'numeric', 'object', diff --git a/src/Tokenizer/Analyzer/CommentsAnalyzer.php b/src/Tokenizer/Analyzer/CommentsAnalyzer.php index 9ca60e972a5..7e0ab311926 100644 --- a/src/Tokenizer/Analyzer/CommentsAnalyzer.php +++ b/src/Tokenizer/Analyzer/CommentsAnalyzer.php @@ -21,7 +21,6 @@ /** * @author Kuba WerƂos - * @author SpacePossum * * @internal */ diff --git a/src/Tokenizer/Analyzer/FunctionsAnalyzer.php b/src/Tokenizer/Analyzer/FunctionsAnalyzer.php index 601b8ea29e1..080ee79e4f7 100644 --- a/src/Tokenizer/Analyzer/FunctionsAnalyzer.php +++ b/src/Tokenizer/Analyzer/FunctionsAnalyzer.php @@ -135,9 +135,9 @@ public function isGlobalFunctionCall(Tokens $tokens, int $index): bool /** * @return ArgumentAnalysis[] */ - public function getFunctionArguments(Tokens $tokens, int $methodIndex): array + public function getFunctionArguments(Tokens $tokens, int $functionIndex): array { - $argumentsStart = $tokens->getNextTokenOfKind($methodIndex, ['(']); + $argumentsStart = $tokens->getNextTokenOfKind($functionIndex, ['(']); $argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $argumentsStart); $argumentAnalyzer = new ArgumentsAnalyzer(); $arguments = []; diff --git a/src/Tokenizer/Analyzer/NamespaceUsesAnalyzer.php b/src/Tokenizer/Analyzer/NamespaceUsesAnalyzer.php index fde4c34d31a..e31985668fa 100644 --- a/src/Tokenizer/Analyzer/NamespaceUsesAnalyzer.php +++ b/src/Tokenizer/Analyzer/NamespaceUsesAnalyzer.php @@ -62,7 +62,8 @@ private function getDeclarations(Tokens $tokens, array $useIndexes): array foreach ($useIndexes as $index) { $endIndex = $tokens->getNextTokenOfKind($index, [';', [T_CLOSE_TAG]]); $analysis = $this->parseDeclaration($tokens, $index, $endIndex); - if ($analysis) { + + if (null !== $analysis) { $uses[] = $analysis; } } diff --git a/src/Tokenizer/Analyzer/NamespacesAnalyzer.php b/src/Tokenizer/Analyzer/NamespacesAnalyzer.php index c8bd2fe2ed8..e5e3f572ace 100644 --- a/src/Tokenizer/Analyzer/NamespacesAnalyzer.php +++ b/src/Tokenizer/Analyzer/NamespacesAnalyzer.php @@ -74,7 +74,7 @@ public function getDeclarations(Tokens $tokens): array public function getNamespaceAt(Tokens $tokens, int $index): NamespaceAnalysis { if (!$tokens->offsetExists($index)) { - throw new \InvalidArgumentException("Token index {$index} does not exist."); + throw new \InvalidArgumentException(sprintf('Token index %d does not exist.', $index)); } foreach ($this->getDeclarations($tokens) as $namespace) { @@ -83,6 +83,6 @@ public function getNamespaceAt(Tokens $tokens, int $index): NamespaceAnalysis } } - throw new \LogicException("Unable to get the namespace at index {$index}."); + throw new \LogicException(sprintf('Unable to get the namespace at index %d.', $index)); } } diff --git a/src/Tokenizer/Resolver/TypeShortNameResolver.php b/src/Tokenizer/Resolver/TypeShortNameResolver.php index 0e6cc86f14b..d07a0d5503c 100644 --- a/src/Tokenizer/Resolver/TypeShortNameResolver.php +++ b/src/Tokenizer/Resolver/TypeShortNameResolver.php @@ -71,7 +71,7 @@ public function resolve(Tokens $tokens, string $typeName): string */ private function getNamespacesFromTokens(Tokens $tokens): array { - return array_map(static function (NamespaceAnalysis $info) { + return array_map(static function (NamespaceAnalysis $info): string { return $info->getFullName(); }, (new NamespacesAnalyzer())->getDeclarations($tokens)); } diff --git a/src/Tokenizer/Token.php b/src/Tokenizer/Token.php index 12d7af4e49f..5ff6d2ee0ea 100644 --- a/src/Tokenizer/Token.php +++ b/src/Tokenizer/Token.php @@ -202,7 +202,7 @@ public function equalsAny(array $others, bool $caseSensitive = true): bool } /** - * A helper method used to find out whether or not a certain input token has to be case-sensitively matched. + * A helper method used to find out whether a certain input token has to be case-sensitively matched. * * @param array|bool $caseSensitive global case sensitiveness or an array of booleans, whose keys should match * the ones used in $others. If any is missing, the default case-sensitive diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index 37ff4b57424..9b88119488f 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -453,7 +453,7 @@ public function findGivenKind($possibleKind, int $start = 0, ?int $end = null): $elements[$kind] = []; } - $possibleKinds = array_filter($possibleKinds, function ($kind) { + $possibleKinds = array_filter($possibleKinds, function ($kind): bool { return $this->isTokenKindFound($kind); }); @@ -620,7 +620,7 @@ public function getTokenNotOfKindSibling(int $index, int $direction, array $toke return $this->getTokenNotOfKind( $index, $direction, - function (int $a) use ($tokens) { + function (int $a) use ($tokens): bool { return $this[$a]->equalsAny($tokens); } ); @@ -638,7 +638,7 @@ public function getTokenNotOfKindsSibling(int $index, int $direction, array $kin return $this->getTokenNotOfKind( $index, $direction, - function (int $index) use ($kinds) { + function (int $index) use ($kinds): bool { return $this[$index]->isGivenKind($kinds); } ); @@ -705,7 +705,7 @@ public function getPrevMeaningfulToken(int $index): ?int * * @param array $sequence an array of tokens (kinds) (same format used by getNextTokenOfKind) * @param int $start start index, defaulting to the start of the file - * @param int $end end index, defaulting to the end of the file + * @param null|int $end end index, defaulting to the end of the file * @param array|bool $caseSensitive global case sensitiveness or an array of booleans, whose keys should match * the ones used in $others. If any is missing, the default case-sensitive * comparison is used @@ -827,7 +827,7 @@ public function insertAt(int $index, $items): void * like edge case example of 3.7h vs 4s (https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/3996#issuecomment-455617637), * yet at same time changing a logic of fixers in not-always easy way. * - * To be discuss: + * To be discussed: * - should we always aim to use this method? * - should we deprecate `insertAt` method ? * @@ -941,7 +941,7 @@ public function overrideRange(int $indexStart, int $indexEnd, iterable $items): $this[$indexStart + $itemIndex] = $item; } - // If we want to add less tokens than passed range contains then clear + // If we want to add fewer tokens than passed range contains then clear // not needed tokens. if ($itemsCount < $indexToChange) { $this->clearRange($indexStart + $itemsCount, $indexEnd); diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index 7818b366314..8ec5a97e3c0 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -24,7 +24,6 @@ * * @author Dariusz RumiƄski * @author Gregor Harlan - * @author SpacePossum * * @internal */ @@ -733,9 +732,9 @@ private function findClassyElements(int $classIndex, int $index): array if (0 === $bracesLevel && $token->isGivenKind(T_VARIABLE)) { $elements[$index] = [ + 'classIndex' => $classIndex, 'token' => $token, 'type' => 'property', - 'classIndex' => $classIndex, ]; continue; @@ -743,21 +742,21 @@ private function findClassyElements(int $classIndex, int $index): array if ($token->isGivenKind(T_FUNCTION)) { $elements[$index] = [ + 'classIndex' => $classIndex, 'token' => $token, 'type' => 'method', - 'classIndex' => $classIndex, ]; } elseif ($token->isGivenKind(T_CONST)) { $elements[$index] = [ + 'classIndex' => $classIndex, 'token' => $token, 'type' => 'const', - 'classIndex' => $classIndex, ]; } elseif ($token->isGivenKind(CT::T_USE_TRAIT)) { $elements[$index] = [ + 'classIndex' => $classIndex, 'token' => $token, 'type' => 'trait_import', - 'classIndex' => $classIndex, ]; } } diff --git a/src/Tokenizer/Transformer/NameQualifiedTransformer.php b/src/Tokenizer/Transformer/NameQualifiedTransformer.php index fc8e1dc0764..d84037730ec 100644 --- a/src/Tokenizer/Transformer/NameQualifiedTransformer.php +++ b/src/Tokenizer/Transformer/NameQualifiedTransformer.php @@ -21,8 +21,6 @@ /** * Transform NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED and T_NAME_RELATIVE into T_NAMESPACE T_NS_SEPARATOR T_STRING. * - * @author SpacePossum - * * @internal */ final class NameQualifiedTransformer extends AbstractTransformer diff --git a/src/Tokenizer/Transformer/NamedArgumentTransformer.php b/src/Tokenizer/Transformer/NamedArgumentTransformer.php index cddb29cf334..e72993f50ad 100644 --- a/src/Tokenizer/Transformer/NamedArgumentTransformer.php +++ b/src/Tokenizer/Transformer/NamedArgumentTransformer.php @@ -22,8 +22,6 @@ /** * Transform named argument tokens. * - * @author SpacePossum - * * @internal */ final class NamedArgumentTransformer extends AbstractTransformer diff --git a/src/Tokenizer/Transformer/SquareBraceTransformer.php b/src/Tokenizer/Transformer/SquareBraceTransformer.php index 59467a14d65..dfce9310a05 100644 --- a/src/Tokenizer/Transformer/SquareBraceTransformer.php +++ b/src/Tokenizer/Transformer/SquareBraceTransformer.php @@ -27,7 +27,6 @@ * - in `[$a, &$b, [$c]] = array(1, 2, array(3))` into CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN and CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE. * * @author Dariusz RumiƄski - * @author SpacePossum * * @internal */ diff --git a/src/Tokenizer/Transformers.php b/src/Tokenizer/Transformers.php index f7cbc95d11e..ac6334783d2 100644 --- a/src/Tokenizer/Transformers.php +++ b/src/Tokenizer/Transformers.php @@ -40,7 +40,7 @@ private function __construct() { $this->registerBuiltInTransformers(); - usort($this->items, static function (TransformerInterface $a, TransformerInterface $b) { + usort($this->items, static function (TransformerInterface $a, TransformerInterface $b): int { return $b->getPriority() <=> $a->getPriority(); }); } diff --git a/src/Utils.php b/src/Utils.php index d601c6d61b8..805babc3f43 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -19,7 +19,7 @@ /** * @author Dariusz RumiƄski - * @author Graham Campbell + * @author Graham Campbell * @author OdĂ­n del RĂ­o * * @internal @@ -79,7 +79,7 @@ public static function stableSort(array $elements, callable $getComparedValue, c $element = [$element, $index, $getComparedValue($element)]; }); - usort($elements, static function ($a, $b) use ($compareValues) { + usort($elements, static function ($a, $b) use ($compareValues): int { $comparison = $compareValues($a[2], $b[2]); if (0 !== $comparison) { @@ -107,10 +107,10 @@ public static function sortFixers(array $fixers): array // `usort(): Array was modified by the user comparison function` warning for mocked objects. return self::stableSort( $fixers, - static function (FixerInterface $fixer) { + static function (FixerInterface $fixer): int { return $fixer->getPriority(); }, - static function (int $a, int $b) { + static function (int $a, int $b): int { return $b <=> $a; } ); @@ -129,7 +129,7 @@ public static function naturalLanguageJoinWithBackticks(array $names): string throw new \InvalidArgumentException('Array of names cannot be empty.'); } - $names = array_map(static function (string $name) { + $names = array_map(static function (string $name): string { return sprintf('`%s`', $name); }, $names); diff --git a/src/WordMatcher.php b/src/WordMatcher.php index 61cb0a11407..5314b1e1c72 100644 --- a/src/WordMatcher.php +++ b/src/WordMatcher.php @@ -16,7 +16,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal */ diff --git a/tests/AbstractDoctrineAnnotationFixerTestCase.php b/tests/AbstractDoctrineAnnotationFixerTestCase.php index 878a44546c3..197de2ad38a 100644 --- a/tests/AbstractDoctrineAnnotationFixerTestCase.php +++ b/tests/AbstractDoctrineAnnotationFixerTestCase.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -26,7 +27,7 @@ abstract class AbstractDoctrineAnnotationFixerTestCase extends AbstractFixerTest */ public function testConfigureWithInvalidConfiguration(array $configuration): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->fixer->configure($configuration); } diff --git a/tests/AutoReview/CiConfigurationTest.php b/tests/AutoReview/CiConfigurationTest.php index 9cf09f793ec..9132228e7f9 100644 --- a/tests/AutoReview/CiConfigurationTest.php +++ b/tests/AutoReview/CiConfigurationTest.php @@ -137,11 +137,11 @@ private static function assertSupportedPhpVersionsAreCoveredByCiJobs(array $supp private function getAllPhpVersionsUsedByCiForDeployments(): array { - $jobs = array_filter($this->getGitHubJobs(), function (array $job) { + $jobs = array_filter($this->getGitHubJobs(), static function (array $job): bool { return isset($job['execute-deployment']) && 'yes' === $job['execute-deployment']; }); - return array_map(function ($job) { + return array_map(static function ($job): string { return \is_string($job['php-version']) ? $job['php-version'] : sprintf('%.1f', $job['php-version']); }, $jobs); } diff --git a/tests/AutoReview/CommandTest.php b/tests/AutoReview/CommandTest.php index 861482c4b89..5135701de93 100644 --- a/tests/AutoReview/CommandTest.php +++ b/tests/AutoReview/CommandTest.php @@ -34,7 +34,7 @@ final class CommandTest extends TestCase */ public function testCommandHasNameConst(Command $command): void { - static::assertNotNull($command->getDefaultName()); + static::assertNotNull($command::getDefaultName()); } public function provideCommandHasNameConstCases(): array @@ -42,7 +42,7 @@ public function provideCommandHasNameConstCases(): array $application = new Application(); $commands = $application->all(); - $names = array_filter(array_keys($commands), static function (string $name) use ($commands) { + $names = array_filter(array_keys($commands), static function (string $name) use ($commands): bool { return // is not an alias !\in_array($name, $commands[$name]->getAliases(), true) diff --git a/tests/AutoReview/DocumentationTest.php b/tests/AutoReview/DocumentationTest.php index 71244c72fc4..ee4d071554a 100644 --- a/tests/AutoReview/DocumentationTest.php +++ b/tests/AutoReview/DocumentationTest.php @@ -67,7 +67,7 @@ public function testFixerDocumentationFileIsUpToDate(FixerInterface $fixer): voi |$ ) /x', - function (array $matches) use ($actual) { + static function (array $matches) use ($actual): string { $before = preg_quote($matches['before'], '/'); $after = preg_quote($matches['after'], '/'); diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 24e0134f70c..ac03675592b 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -316,7 +316,7 @@ public function provideFixersPrioritySpecialPhpdocCases() $docFixerNames = array_filter( array_keys($fixers), - static function (string $name) { + static function (string $name): bool { return false !== strpos($name, 'phpdoc'); } ); @@ -387,7 +387,7 @@ public function provideFixersPriorityPairsHaveIntegrationTestCases(): array return array_filter( $this->provideFixersPriorityCases(), // ignore speed-up only priorities set up - function (array $case) { + function (array $case): bool { return !\in_array( $this->generateIntegrationTestName($case[0], $case[1]), [ @@ -483,7 +483,7 @@ public function testProvideFixersPriorityCasesAreSorted(): void * @param array $priorityPair1 * @param array $priorityPair2 */ - static function (array $priorityPair1, array $priorityPair2) { + static function (array $priorityPair1, array $priorityPair2): int { $fixer1 = $priorityPair1[0]; $fixer2 = $priorityPair2[0]; diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index 7c640f9ed76..09f25b5c887 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -54,7 +54,7 @@ public function testThatClassesWithoutTestsVarIsProper(): void { $unknownClasses = array_filter( self::$classesWithoutTests, - static function (string $class) { return !class_exists($class) && !trait_exists($class); } + static function (string $class): bool { return !class_exists($class) && !trait_exists($class); } ); static::assertSame([], $unknownClasses); @@ -84,13 +84,13 @@ public function testThatSrcClassesNotAbuseInterfaces(string $className): void $rc = new \ReflectionClass($className); $allowedMethods = array_map( - function (\ReflectionClass $interface) { + function (\ReflectionClass $interface): array { return $this->getPublicMethodNames($interface); }, $rc->getInterfaces() ); - if (\count($allowedMethods)) { + if (\count($allowedMethods) > 0) { $allowedMethods = array_unique(array_merge(...array_values($allowedMethods))); } @@ -120,7 +120,7 @@ function (\ReflectionClass $interface) { sprintf( "Class '%s' should not have public methods that are not part of implemented interfaces.\nViolations:\n%s", $className, - implode("\n", array_map(static function (string $item) { + implode("\n", array_map(static function (string $item): string { return " * {$item}"; }, $extraMethods)) ) @@ -150,11 +150,11 @@ public function testThatSrcClassesNotExposeProperties(string $className): void $allowedProps = $rc->getParentClass()->getProperties(\ReflectionProperty::IS_PROTECTED); } - $allowedProps = array_map(static function (\ReflectionProperty $item) { + $allowedProps = array_map(static function (\ReflectionProperty $item): string { return $item->getName(); }, $allowedProps); - $definedProps = array_map(static function (\ReflectionProperty $item) { + $definedProps = array_map(static function (\ReflectionProperty $item): string { return $item->getName(); }, $definedProps); @@ -177,7 +177,7 @@ public function testThatSrcClassesNotExposeProperties(string $className): void sprintf( "Class '%s' should not have protected properties.\nViolations:\n%s", $className, - implode("\n", array_map(static function (string $item) { + implode("\n", array_map(static function (string $item): string { return " * {$item}"; }, $extraProps)) ) @@ -214,13 +214,13 @@ public function testThatTestClassesAreInternal(string $testClassName): void /** * @dataProvider provideTestClassCases */ - public function testThatPublicMethodsAreCorrectlyNamed(string $testClassName): void + public function testThatTestClassesPublicMethodsAreCorrectlyNamed(string $testClassName): void { $reflectionClass = new \ReflectionClass($testClassName); $publicMethods = array_filter( $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC), - static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass) { + static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bool { return $reflectionMethod->getDeclaringClass()->getName() === $reflectionClass->getName(); } ); @@ -241,7 +241,7 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass) { /** * @dataProvider provideTestClassCases */ - public function testThatDataProvidersAreCorrectlyNamed(string $testClassName): void + public function testThatTestDataProvidersAreCorrectlyNamed(string $testClassName): void { $usedDataProviderMethodNames = $this->getUsedDataProviderMethodNames($testClassName); @@ -263,13 +263,13 @@ public function testThatDataProvidersAreCorrectlyNamed(string $testClassName): v /** * @dataProvider provideTestClassCases */ - public function testThatDataProvidersAreUsed(string $testClassName): void + public function testThatTestDataProvidersAreUsed(string $testClassName): void { $reflectionClass = new \ReflectionClass($testClassName); $definedDataProviders = array_filter( $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC), - static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass) { + static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bool { return $reflectionMethod->getDeclaringClass()->getName() === $reflectionClass->getName() && 'provide' === substr($reflectionMethod->getName(), 0, 7); } @@ -340,13 +340,13 @@ public function testThereIsNoPregFunctionUsedDirectly(string $className): void $tokens = Tokens::fromCode(file_get_contents($rc->getFileName())); $stringTokens = array_filter( $tokens->toArray(), - static function (Token $token) { + static function (Token $token): bool { return $token->isGivenKind(T_STRING); } ); $strings = array_map( - static function (Token $token) { + static function (Token $token): string { return $token->getContent(); }, $stringTokens @@ -372,7 +372,7 @@ public function testExpectedInputOrder(string $testClassName): void $publicMethods = array_filter( $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC), - static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass) { + static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bool { return $reflectionMethod->getDeclaringClass()->getName() === $reflectionClass->getName(); } ); @@ -492,7 +492,7 @@ public function testThereIsNoTriggerErrorUsedDirectly(string $className): void $triggerErrors = array_filter( $tokens->toArray(), - static function (Token $token) { + static function (Token $token): bool { return $token->equals([T_STRING, 'trigger_error'], false); } ); @@ -512,13 +512,13 @@ public function testInheritdocIsNotAbused(string $className): void $rc = new \ReflectionClass($className); $allowedMethods = array_map( - function (\ReflectionClass $interface) { + function (\ReflectionClass $interface): array { return $this->getPublicMethodNames($interface); }, $rc->getInterfaces() ); - if (\count($allowedMethods)) { + if (\count($allowedMethods) > 0) { $allowedMethods = array_merge(...array_values($allowedMethods)); } @@ -533,13 +533,13 @@ function (\ReflectionClass $interface) { $methodsWithInheritdoc = array_filter( $rc->getMethods(), - static function (\ReflectionMethod $rm) { + static function (\ReflectionMethod $rm): bool { return false !== $rm->getDocComment() && stripos($rm->getDocComment(), '@inheritdoc'); } ); $methodsWithInheritdoc = array_map( - static function (\ReflectionMethod $rm) { + static function (\ReflectionMethod $rm): string { return $rm->getName(); }, $methodsWithInheritdoc @@ -552,7 +552,7 @@ static function (\ReflectionMethod $rm) { sprintf( "Class '%s' should not have methods with '@inheritdoc' in PHPDoc that are not inheriting PHPDoc.\nViolations:\n%s", $className, - implode("\n", array_map(static function ($item) { + implode("\n", array_map(static function ($item): string { return " * {$item}"; }, $extraMethods)) ) @@ -562,7 +562,7 @@ static function (\ReflectionMethod $rm) { public function provideSrcClassCases(): array { return array_map( - static function (string $item) { + static function (string $item): array { return [$item]; }, $this->getSrcClasses() @@ -572,10 +572,10 @@ static function (string $item) { public function provideSrcClassesNotAbuseInterfacesCases(): array { return array_map( - static function (string $item) { + static function (string $item): array { return [$item]; }, - array_filter($this->getSrcClasses(), static function (string $className) { + array_filter($this->getSrcClasses(), static function (string $className): bool { $rc = new \ReflectionClass($className); $doc = false !== $rc->getDocComment() @@ -618,10 +618,10 @@ static function (string $item) { public function provideSrcConcreteClassCases(): array { return array_map( - static function (string $item) { return [$item]; }, + static function (string $item): array { return [$item]; }, array_filter( $this->getSrcClasses(), - static function (string $className) { + static function (string $className): bool { $rc = new \ReflectionClass($className); return !$rc->isAbstract() && !$rc->isInterface(); @@ -633,7 +633,7 @@ static function (string $className) { public function provideTestClassCases(): array { return array_map( - static function (string $item) { + static function (string $item): array { return [$item]; }, $this->getTestClasses() @@ -643,12 +643,12 @@ static function (string $item) { public function provideClassesWherePregFunctionsAreForbiddenCases(): array { return array_map( - static function (string $item) { + static function (string $item): array { return [$item]; }, array_filter( $this->getSrcClasses(), - static function (string $className) { + static function (string $className): bool { return Preg::class !== $className; } ) @@ -751,7 +751,7 @@ private function getSrcClasses() ; $classes = array_map( - static function (SplFileInfo $file) { + static function (SplFileInfo $file): string { return sprintf( '%s\\%s%s%s', 'PhpCsFixer', @@ -786,7 +786,7 @@ private function getTestClasses() ; $classes = array_map( - static function (SplFileInfo $file) { + static function (SplFileInfo $file): string { return sprintf( 'PhpCsFixer\\Tests\\%s%s%s', strtr($file->getRelativePath(), \DIRECTORY_SEPARATOR, '\\'), @@ -813,7 +813,7 @@ static function (SplFileInfo $file) { private function getPublicMethodNames(\ReflectionClass $rc): array { return array_map( - static function (\ReflectionMethod $rm) { + static function (\ReflectionMethod $rm): string { return $rm->getName(); }, $rc->getMethods(\ReflectionMethod::IS_PUBLIC) diff --git a/tests/Cache/CacheTest.php b/tests/Cache/CacheTest.php index 0bdbac63037..a7af5e04f79 100644 --- a/tests/Cache/CacheTest.php +++ b/tests/Cache/CacheTest.php @@ -128,7 +128,7 @@ public function provideMissingDataCases(): array 'hashes' => [], ]; - return array_map(static function (string $missingKey) use ($data) { + return array_map(static function (string $missingKey) use ($data): array { unset($data[$missingKey]); return [ @@ -202,6 +202,7 @@ public function testToJsonThrowsExceptionOnInvalid(): void $this->expectException( \UnexpectedValueException::class ); + $this->expectExceptionMessage( 'Can not encode cache signature to JSON, error: "Malformed UTF-8 characters, possibly incorrectly encoded". If you have non-UTF8 chars in your signature, like in license for `header_comment`, consider enabling `ext-mbstring` or install `symfony/polyfill-mbstring`.' ); diff --git a/tests/Cache/FileCacheManagerTest.php b/tests/Cache/FileCacheManagerTest.php index c64b6f0b451..ac35961765e 100644 --- a/tests/Cache/FileCacheManagerTest.php +++ b/tests/Cache/FileCacheManagerTest.php @@ -48,7 +48,7 @@ public function testCreatesCacheIfHandlerReturnedNoCache(): void $handlerProphecy = $this->prophesize(\PhpCsFixer\Cache\FileHandlerInterface::class); $handlerProphecy->read()->shouldBeCalled()->willReturn(null); - $handlerProphecy->write(Argument::that(static function (CacheInterface $cache) use ($signature) { + $handlerProphecy->write(Argument::that(static function (CacheInterface $cache) use ($signature): bool { return $cache->getSignature() === $signature; }))->shouldBeCalled(); $handler = $handlerProphecy->reveal(); @@ -75,7 +75,7 @@ public function testCreatesCacheIfCachedSignatureIsDifferent(): void $handlerProphecy = $this->prophesize(\PhpCsFixer\Cache\FileHandlerInterface::class); $handlerProphecy->read()->shouldBeCalled()->willReturn($cache); - $handlerProphecy->write(Argument::that(static function (CacheInterface $cache) use ($signature) { + $handlerProphecy->write(Argument::that(static function (CacheInterface $cache) use ($signature): bool { return $cache->getSignature() === $signature; }))->shouldBeCalled(); $handler = $handlerProphecy->reveal(); diff --git a/tests/Cache/FileHandlerTest.php b/tests/Cache/FileHandlerTest.php index a4219556ce3..bafd73c4b95 100644 --- a/tests/Cache/FileHandlerTest.php +++ b/tests/Cache/FileHandlerTest.php @@ -19,6 +19,7 @@ use PhpCsFixer\Cache\Signature; use PhpCsFixer\Cache\SignatureInterface; use PhpCsFixer\Tests\TestCase; +use Symfony\Component\Filesystem\Exception\IOException; /** * @author Andreas Möller @@ -100,7 +101,7 @@ public function testWriteThrowsIOExceptionIfFileCanNotBeWritten(): void { $file = __DIR__.'/non-existent-directory/.php-cs-fixer.cache'; - $this->expectException(\Symfony\Component\Filesystem\Exception\IOException::class); + $this->expectException(IOException::class); $this->expectExceptionMessageMatches(sprintf( '#^Directory of cache file "%s" does not exists.#', preg_quote($file, '#') @@ -136,7 +137,7 @@ public function testWriteCacheToDirectory(): void $handler = new FileHandler($dir); - $this->expectException(\Symfony\Component\Filesystem\Exception\IOException::class); + $this->expectException(IOException::class); $this->expectExceptionMessageMatches(sprintf( '#^%s$#', preg_quote('Cannot write cache file "'.realpath($dir).'" as the location exists as directory.', '#') @@ -154,7 +155,7 @@ public function testWriteCacheToNonWriteableFile(): void $handler = new FileHandler($file); - $this->expectException(\Symfony\Component\Filesystem\Exception\IOException::class); + $this->expectException(IOException::class); $this->expectExceptionMessageMatches(sprintf( '#^%s$#', preg_quote('Cannot write to file "'.realpath($file).'" as it is not writable.', '#') diff --git a/tests/ConfigurationException/InvalidForEnvFixerConfigurationExceptionTest.php b/tests/ConfigurationException/InvalidForEnvFixerConfigurationExceptionTest.php index 8bea0ca34e9..e5101860207 100644 --- a/tests/ConfigurationException/InvalidForEnvFixerConfigurationExceptionTest.php +++ b/tests/ConfigurationException/InvalidForEnvFixerConfigurationExceptionTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\ConfigurationException; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\ConfigurationException\InvalidForEnvFixerConfigurationException; use PhpCsFixer\Console\Command\FixCommandExitStatusCalculator; use PhpCsFixer\Tests\TestCase; @@ -37,7 +38,7 @@ public function testDefaults(): void $message ); - static::assertInstanceOf(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class, $exception); + static::assertInstanceOf(InvalidFixerConfigurationException::class, $exception); static::assertSame(sprintf('[%s] %s', $fixerName, $message), $exception->getMessage()); static::assertSame(FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG, $exception->getCode()); static::assertSame($fixerName, $exception->getFixerName()); diff --git a/tests/ConfigurationException/RequiredFixerConfigurationExceptionTest.php b/tests/ConfigurationException/RequiredFixerConfigurationExceptionTest.php index 6d38b367e05..b68bc7575d5 100644 --- a/tests/ConfigurationException/RequiredFixerConfigurationExceptionTest.php +++ b/tests/ConfigurationException/RequiredFixerConfigurationExceptionTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\ConfigurationException; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException; use PhpCsFixer\Console\Command\FixCommandExitStatusCalculator; use PhpCsFixer\Tests\TestCase; @@ -34,7 +35,7 @@ public function testIsInvalidFixerConfigurationException(): void 'I cannot do that, Dave.' ); - static::assertInstanceOf(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class, $exception); + static::assertInstanceOf(InvalidFixerConfigurationException::class, $exception); } public function testDefaults(): void diff --git a/tests/Console/Command/SelfUpdateCommandTest.php b/tests/Console/Command/SelfUpdateCommandTest.php index eee0bfc3736..bd33a40f599 100644 --- a/tests/Console/Command/SelfUpdateCommandTest.php +++ b/tests/Console/Command/SelfUpdateCommandTest.php @@ -116,7 +116,7 @@ public function testExecute( $versionChecker ->compareVersions(Argument::type('string'), Argument::type('string')) - ->will(function (array $arguments) use ($actualVersionCheck) { + ->will(function (array $arguments) use ($actualVersionCheck): int { return $actualVersionCheck->compareVersions($arguments[0], $arguments[1]); }) ; @@ -373,7 +373,7 @@ private function createToolInfo(bool $isInstalledAsPhar = true) $toolInfo->isInstalledAsPhar()->willReturn($isInstalledAsPhar); $toolInfo ->getPharDownloadUri(Argument::type('string')) - ->will(function (array $arguments) use ($root) { + ->will(function (array $arguments) use ($root): string { return "{$root->url()}/{$arguments[0]}.phar"; }) ; diff --git a/tests/Console/ConfigurationResolverTest.php b/tests/Console/ConfigurationResolverTest.php index fb0f6e4936b..7eb666d1f1c 100644 --- a/tests/Console/ConfigurationResolverTest.php +++ b/tests/Console/ConfigurationResolverTest.php @@ -484,7 +484,7 @@ public function testResolveIntersectionOfPaths($expected, ?Finder $configFinder, ], $config); $intersectionItems = array_map( - static function (\SplFileInfo $file) { + static function (\SplFileInfo $file): string { return $file->getRealPath(); }, iterator_to_array($resolver->getFinder(), false) @@ -499,9 +499,9 @@ static function (\SplFileInfo $file) { public function provideResolveIntersectionOfPathsCases(): array { $dir = __DIR__.'/../Fixtures/ConfigurationResolverPathsIntersection'; - $cb = static function (array $items) use ($dir) { + $cb = static function (array $items) use ($dir): array { return array_map( - static function (string $item) use ($dir) { + static function (string $item) use ($dir): string { return realpath($dir.'/'.$item); }, $items diff --git a/tests/Console/Report/FixReport/JsonReporterTest.php b/tests/Console/Report/FixReport/JsonReporterTest.php index f5d379e1a7c..c0f31e97856 100644 --- a/tests/Console/Report/FixReport/JsonReporterTest.php +++ b/tests/Console/Report/FixReport/JsonReporterTest.php @@ -168,7 +168,7 @@ private static function assertJsonSchema(string $json): void implode( "\n", array_map( - static function (array $item) { return sprintf('Property `%s`: %s.', $item['property'], $item['message']); }, + static function (array $item): string { return sprintf('Property `%s`: %s.', $item['property'], $item['message']); }, $validator->getErrors() ) ) diff --git a/tests/Console/Report/ListSetsReport/JsonReporterTest.php b/tests/Console/Report/ListSetsReport/JsonReporterTest.php index 70bc7d6cde9..98ce5245708 100644 --- a/tests/Console/Report/ListSetsReport/JsonReporterTest.php +++ b/tests/Console/Report/ListSetsReport/JsonReporterTest.php @@ -77,7 +77,7 @@ private static function assertJsonSchema(string $json): void implode( "\n", array_map( - static function (array $item) { return sprintf('Property `%s`: %s.', $item['property'], $item['message']); }, + static function (array $item): string { return sprintf('Property `%s`: %s.', $item['property'], $item['message']); }, $validator->getErrors() ) ) diff --git a/tests/DocBlock/AnnotationTest.php b/tests/DocBlock/AnnotationTest.php index 287d622eb43..caf9025c88c 100644 --- a/tests/DocBlock/AnnotationTest.php +++ b/tests/DocBlock/AnnotationTest.php @@ -23,7 +23,7 @@ use PhpCsFixer\Tokenizer\Analyzer\Analysis\NamespaceUseAnalysis; /** - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski * * @internal @@ -236,7 +236,7 @@ public function provideRemoveEdgeCasesCases(): array * * @dataProvider provideTypeParsingCases */ - public function testTypeParsing(string $input, array $expected): void + public function testTypeParsing(array $expected, string $input): void { $tag = new Annotation([new Line($input)]); @@ -247,200 +247,200 @@ public function provideTypeParsingCases(): array { return [ [ - ' * @method int method()', ['int'], + ' * @method int method()', ], [ - " * @return int[]\r", ['int[]'], + " * @return int[]\r", ], [ - " * @return int[]\r\n", ['int[]'], + " * @return int[]\r\n", ], [ - ' * @method Foo[][] method()', ['Foo[][]'], + ' * @method Foo[][] method()', ], [ - ' * @method int[] method()', ['int[]'], + ' * @method int[] method()', ], [ - ' * @method int[]|null method()', ['int[]', 'null'], + ' * @method int[]|null method()', ], [ - ' * @method int[]|null|?int|array method()', ['int[]', 'null', '?int', 'array'], + ' * @method int[]|null|?int|array method()', ], [ - ' * @method null|Foo\Bar|\Baz\Bax|int[] method()', ['null', 'Foo\Bar', '\Baz\Bax', 'int[]'], + ' * @method null|Foo\Bar|\Baz\Bax|int[] method()', ], [ - ' * @method gen method()', ['gen'], + ' * @method gen method()', ], [ - ' * @method int|gen method()', ['int', 'gen'], + ' * @method int|gen method()', ], [ - ' * @method \int|\gen<\int, \bool> method()', ['\int', '\gen<\int, \bool>'], + ' * @method \int|\gen<\int, \bool> method()', ], [ - ' * @method gen method()', ['gen'], + ' * @method gen method()', ], [ - ' * @method gen method()', ['gen'], + ' * @method gen method()', ], [ - ' * @method gen method() <> a', ['gen'], + ' * @method gen method() <> a', ], [ - ' * @method gen> method() foo ', ['gen>'], + ' * @method gen> method() foo ', ], [ - ' * @method gen> method()', ['gen>'], + ' * @method gen> method()', ], [ - ' * @method null|gen>|int|string[] method() foo ', ['null', 'gen>', 'int', 'string[]'], + ' * @method null|gen>|int|string[] method() foo ', ], [ - ' * @method null|gen>|int|array|string[] method() foo ', ['null', 'gen>', 'int', 'array', 'string[]'], + ' * @method null|gen>|int|array|string[] method() foo ', ], [ - '/** @return this */', ['this'], + '/** @return this */', ], [ - '/** @return @this */', ['@this'], + '/** @return @this */', ], [ - '/** @return $SELF|int */', ['$SELF', 'int'], + '/** @return $SELF|int */', ], [ - '/** @var array', ['array'], + '/** @var array', ], [ - " * @return int\n", ['int'], + " * @return int\n", ], [ - " * @return int\r\n", ['int'], + " * @return int\r\n", ], [ - '/** @var Collection, Foo>', ['Collection, Foo>'], + '/** @var Collection, Foo>', ], [ - '/** @var int | string', ['int', 'string'], + '/** @var int | string', ], [ - '/** @var Foo::*', ['Foo::*'], + '/** @var Foo::*', ], [ - '/** @var Foo::A', ['Foo::A'], + '/** @var Foo::A', ], [ - '/** @var Foo::A|Foo::B', ['Foo::A', 'Foo::B'], + '/** @var Foo::A|Foo::B', ], [ - '/** @var Foo::A*', ['Foo::A*'], + '/** @var Foo::A*', ], [ - '/** @var array|null', ['array', 'null'], + '/** @var array|null', ], [ - '/** @var null|true|false|1|1.5|\'a\'|"b"', ['null', 'true', 'false', '1', '1.5', "'a'", '"b"'], + '/** @var null|true|false|1|1.5|\'a\'|"b"', ], [ - '/** @param int | "a" | A, E> $foo */', ['int', '"a"', 'A, E>'], + '/** @param int | "a" | A, E> $foo */', ], [ - '/** @var class-string */', ['class-string'], + '/** @var class-string */', ], [ - '/** @var A&B */', ['A&B'], + '/** @var A&B */', ], [ - '/** @var A & B */', ['A & B'], + '/** @var A & B */', ], [ - '/** @var array{1: bool, 2: bool} */', ['array{1: bool, 2: bool}'], + '/** @var array{1: bool, 2: bool} */', ], [ - '/** @var array{a: int|string, b?: bool} */', ['array{a: int|string, b?: bool}'], + '/** @var array{a: int|string, b?: bool} */', ], [ - '/** @var array{\'a\': "a", "b"?: \'b\'} */', ['array{\'a\': "a", "b"?: \'b\'}'], + '/** @var array{\'a\': "a", "b"?: \'b\'} */', ], [ - '/** @var array { a : int | string , b ? : A } */', ['array { a : int | string , b ? : A }'], + '/** @var array { a : int | string , b ? : A } */', ], [ - '/** @param callable(string) $function', ['callable(string)'], + '/** @param callable(string) $function', ], [ - '/** @param callable(string): bool $function', ['callable(string): bool'], + '/** @param callable(string): bool $function', ], [ - '/** @param callable(array, array): bool $function', ['callable(array, array): bool'], + '/** @param callable(array, array): bool $function', ], [ - '/** @param array $function', ['array'], + '/** @param array $function', ], [ - '/** @param callable(string): callable(int) $function', ['callable(string): callable(int)'], + '/** @param callable(string): callable(int) $function', ], [ - '/** @param callable(string) : callable(int) : bool $function', ['callable(string) : callable(int) : bool'], + '/** @param callable(string) : callable(int) : bool $function', ], [ - '* @param TheCollection|string[]|null $x', ['TheCollection', 'string[]', 'null'], + '* @param TheCollection|string[]|null $x', ], [ - '/** @param Closure(string) $function', ['Closure(string)'], + '/** @param Closure(string) $function', ], [ - '/** @param array < int , callable ( string ) : bool > $function', ['array < int , callable ( string ) : bool >'], + '/** @param array < int , callable ( string ) : bool > $function', ], ]; } diff --git a/tests/DocBlock/DocBlockTest.php b/tests/DocBlock/DocBlockTest.php index a60539b0da1..6f217b9ffda 100644 --- a/tests/DocBlock/DocBlockTest.php +++ b/tests/DocBlock/DocBlockTest.php @@ -18,7 +18,7 @@ use PhpCsFixer\Tests\TestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/DocBlock/LineTest.php b/tests/DocBlock/LineTest.php index 87dba810dda..53c22a3eb60 100644 --- a/tests/DocBlock/LineTest.php +++ b/tests/DocBlock/LineTest.php @@ -19,7 +19,7 @@ use PhpCsFixer\Tests\TestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/DocBlock/TagComparatorTest.php b/tests/DocBlock/TagComparatorTest.php index 2da7cc434e4..54ed60fdda4 100644 --- a/tests/DocBlock/TagComparatorTest.php +++ b/tests/DocBlock/TagComparatorTest.php @@ -20,7 +20,7 @@ use PhpCsFixer\Tests\TestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/DocBlock/TagTest.php b/tests/DocBlock/TagTest.php index 06e115e3ed0..342b03b96fa 100644 --- a/tests/DocBlock/TagTest.php +++ b/tests/DocBlock/TagTest.php @@ -19,7 +19,7 @@ use PhpCsFixer\Tests\TestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Alias/ArrayPushFixerTest.php b/tests/Fixer/Alias/ArrayPushFixerTest.php index 4c307dce5ee..ab9b2f3494b 100644 --- a/tests/Fixer/Alias/ArrayPushFixerTest.php +++ b/tests/Fixer/Alias/ArrayPushFixerTest.php @@ -241,23 +241,43 @@ public function provideFixCases(): \Generator if ($b) {} elseif (foo()) array_push($a, $b); ', ]; + } - if (\PHP_VERSION_ID < 80000) { - yield [ - 'doTest($expected, $input); + } - yield [ - '= 80000) { - yield [ - 'c[2], $b19);', - ]; - } + yield [ + 'doTest($expected, $input); + } + + public function provideFix80Cases(): \Generator + { + yield [ + 'c[2], $b19);', + ]; } } diff --git a/tests/Fixer/Alias/MbStrFunctionsFixerTest.php b/tests/Fixer/Alias/MbStrFunctionsFixerTest.php index 20c1b459243..9a8b5146a67 100644 --- a/tests/Fixer/Alias/MbStrFunctionsFixerTest.php +++ b/tests/Fixer/Alias/MbStrFunctionsFixerTest.php @@ -62,12 +62,7 @@ public function strtolower($a); ], ]; - if (\PHP_VERSION_ID >= 70400) { - $cases[] = [ - 'doTest($expected, $input); + } + + public function provideFixPhp74Cases(): \Generator + { + yield [ + 'expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches($expectedMessage); $this->fixer->configure($wrongConfig); diff --git a/tests/Fixer/Alias/PowToExponentiationFixerTest.php b/tests/Fixer/Alias/PowToExponentiationFixerTest.php index 936a1353de3..db019d759d1 100644 --- a/tests/Fixer/Alias/PowToExponentiationFixerTest.php +++ b/tests/Fixer/Alias/PowToExponentiationFixerTest.php @@ -225,13 +225,23 @@ public function &pow($a, $b); 'doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield [ + 'expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[random_api_migration\] Invalid configuration: Function "is_null" is not handled by the fixer\.$#'); $this->fixer->configure(['replacements' => ['is_null' => 'random_int']]); @@ -36,7 +37,7 @@ public function testConfigureCheckSearchFunction(): void public function testConfigureCheckReplacementType(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[random_api_migration\] Invalid configuration: Replacement for function "rand" must be a string, "NULL" given\.$#'); $this->fixer->configure(['replacements' => ['rand' => null]]); @@ -184,18 +185,17 @@ public function testFix73(string $expected, string $input, array $config = []): $this->doTest($expected, $input); } - public function provideFix73Cases(): array + public function provideFix73Cases(): \Generator { - return [ - [ - ' ['rand' => 'random_int', 'mt_rand' => 'random_int']], - ], - [ - ' ['rand' => 'random_int', 'mt_rand' => 'random_int']], + ]; + + yield [ + 'expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[array_syntax\] Invalid configuration: The option "a" does not exist\. Defined options are: "syntax"\.$#'); $this->fixer->configure(['a' => 1]); diff --git a/tests/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixerTest.php b/tests/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixerTest.php index bb1607f1a9c..4e178f26df1 100644 --- a/tests/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixerTest.php +++ b/tests/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixerTest.php @@ -19,7 +19,7 @@ /** * @author Carlos Cirello * @author Dariusz RumiƄski - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Basic/BracesFixerTest.php b/tests/Fixer/Basic/BracesFixerTest.php index 7be3597eee8..110e7265e68 100644 --- a/tests/Fixer/Basic/BracesFixerTest.php +++ b/tests/Fixer/Basic/BracesFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\Basic; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Fixer\Basic\BracesFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\WhitespacesFixerConfig; @@ -33,7 +34,7 @@ final class BracesFixerTest extends AbstractFixerTestCase public function testInvalidConfigurationClassyConstructs(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[braces\] Invalid configuration: The option "position_after_functions_and_oop_constructs" with value "neither" is invalid\. Accepted values are: "next", "same"\.$#'); $this->fixer->configure(['position_after_functions_and_oop_constructs' => 'neither']); diff --git a/tests/Fixer/Basic/PsrAutoloadingFixerTest.php b/tests/Fixer/Basic/PsrAutoloadingFixerTest.php index 9dc7ebc6be7..ad531cf85a1 100644 --- a/tests/Fixer/Basic/PsrAutoloadingFixerTest.php +++ b/tests/Fixer/Basic/PsrAutoloadingFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * @author Kuba WerƂos * * @internal @@ -389,7 +389,7 @@ public function provideIgnoredCases(): array } } - return array_map(function ($case) { + return array_map(function ($case): array { return [ 'expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[cast_spaces\] Invalid configuration: The option "a" does not exist\. Defined options are: "space"\.$#'); $this->fixer->configure(['a' => 1]); @@ -33,7 +34,7 @@ public function testInvalidConfigMissingKey(): void public function testInvalidConfigValue(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[cast_spaces\] Invalid configuration: The option "space" with value "double" is invalid\. Accepted values are: "none", "single"\.$#'); $this->fixer->configure(['space' => 'double']); diff --git a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php index 4328514cfd3..b929e67c813 100644 --- a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php +++ b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php @@ -170,13 +170,23 @@ public function &doubleval($a); 'doTest($expected, $input); + } - if (\PHP_VERSION_ID < 80000) { - yield [ - ' $config - * * @dataProvider provideClassesWithConfigCases */ public function testFixingClassesWithConfig(string $expected, string $input, array $config): void @@ -87,9 +81,6 @@ public function testFixingClassesWithConfig(string $expected, string $input, arr } /** - * @param string $expected PHP source code - * @param string $input PHP source code - * * @dataProvider provideInterfacesCases */ public function testFixingInterfaces(string $expected, string $input): void @@ -100,9 +91,6 @@ public function testFixingInterfaces(string $expected, string $input): void } /** - * @param string $expected PHP source code - * @param string $input PHP source code - * * @dataProvider provideTraitsCases */ public function testFixingTraits(string $expected, string $input): void @@ -114,7 +102,7 @@ public function testFixingTraits(string $expected, string $input): void public function testInvalidConfigurationKey(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches( '/^\[class_definition\] Invalid configuration: The option "a" does not exist\. Defined options are: "multi_line_extends_each_single_line", "single_item_single_line", "single_line", "space_before_parenthesis"\.$/' ); @@ -125,7 +113,7 @@ public function testInvalidConfigurationKey(): void public function testInvalidConfigurationValueType(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches( '/^\[class_definition\] Invalid configuration: The option "single_line" with value "z" is expected to be of type "bool", but is of type "string"\.$/' ); diff --git a/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php b/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php index a30f575dd22..2964639ed1a 100644 --- a/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php +++ b/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\ClassNotation; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -144,10 +145,6 @@ class A {} } /** - * @param string $expected PHP source code - * @param string $input PHP source code - * @param array $config Fixer configuration - * * @dataProvider provideFixWithConfigCases */ public function testFixWithConfig(string $expected, string $input, array $config): void @@ -297,7 +294,7 @@ public function provideAnonymousClassesCases(): array public function testConfigureSameAnnotationInBothLists(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches( sprintf('#^%s$#', preg_quote('[final_internal_class] Annotation cannot be used in both the include and exclude list, got duplicates: "internal123".', '#')) ); diff --git a/tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php b/tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php index 6e6325333a9..fd5aa56891f 100644 --- a/tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php +++ b/tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\ClassNotation; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; @@ -1300,7 +1301,7 @@ class Foo { public function testWrongConfig(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[ordered_class_elements\] Invalid configuration: The option "order" .*\.$/'); $this->fixer->configure(['order' => ['foo']]); diff --git a/tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php b/tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php index 29a2c231a20..9654867bf24 100644 --- a/tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php +++ b/tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\ClassNotation; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\WhitespacesFixerConfig; @@ -683,7 +684,7 @@ class Foo public function testWrongConfig(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[single_class_element_per_statement\] Invalid configuration: The option "elements" .*\.$/'); $this->fixer->configure(['elements' => ['foo']]); @@ -733,13 +734,11 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases(): array + public function provideMessyWhitespacesCases(): \Generator { - return [ - [ - "expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[visibility_required\] Invalid configuration: The option "elements" .*\.$/'); $this->fixer->configure(['elements' => [null]]); @@ -522,16 +521,13 @@ public function testInvalidConfigurationType(): void public function testInvalidConfigurationValue(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[visibility_required\] Invalid configuration: The option "elements" .*\.$/'); $this->fixer->configure(['elements' => ['_unknown_']]); } /** - * @param string $expected expected PHP source after fixing - * @param string $input PHP source to fix - * * @requires PHP 7.1 * @dataProvider provideFixClassConstCases */ diff --git a/tests/Fixer/Comment/HeaderCommentFixerTest.php b/tests/Fixer/Comment/HeaderCommentFixerTest.php index 93ad9bf8310..69e1c22b306 100644 --- a/tests/Fixer/Comment/HeaderCommentFixerTest.php +++ b/tests/Fixer/Comment/HeaderCommentFixerTest.php @@ -15,6 +15,7 @@ namespace PhpCsFixer\Tests\Fixer\Comment; use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; +use PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException; use PhpCsFixer\Fixer\Comment\HeaderCommentFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\WhitespacesFixerConfig; @@ -571,7 +572,7 @@ public function testDefaultConfiguration(): void */ public function testMisconfiguration(?array $configuration, string $exceptionMessage): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches("#^\\[header_comment\\] {$exceptionMessage}$#"); $this->fixer->configure($configuration); @@ -683,7 +684,7 @@ public function provideDoNotTouchCases(): array public function testWithoutConfiguration(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException::class); + $this->expectException(RequiredFixerConfigurationException::class); $this->doTest('doTest($expected, $input); diff --git a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php index ea315d75d21..b4117c5357d 100644 --- a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php +++ b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php @@ -999,7 +999,7 @@ public function provideTestFixWithDifferentCommentTextCases(): array { $cases = $this->provideFixCases(); - $replaceCommentText = static function (string $php) { + $replaceCommentText = static function (string $php): string { return strtr($php, [ 'No break' => 'Fall-through case!', 'no break' => 'fall-through case!', diff --git a/tests/Fixer/ControlStructure/NoUnneededCurlyBracesFixerTest.php b/tests/Fixer/ControlStructure/NoUnneededCurlyBracesFixerTest.php index 701f2bdc9eb..ebcaf07d844 100644 --- a/tests/Fixer/ControlStructure/NoUnneededCurlyBracesFixerTest.php +++ b/tests/Fixer/ControlStructure/NoUnneededCurlyBracesFixerTest.php @@ -112,15 +112,25 @@ trait E {} ', ], ]; + } - if (\PHP_VERSION_ID < 80000) { - yield 'no fixes, offset access syntax with curly braces' => [ - 'doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield 'no fixes, offset access syntax with curly braces' => [ + 'doTest($expected); + } - if (\PHP_VERSION_ID >= 80000) { - $cases = [ - '$bar = $foo1 ?? throw new \Exception($e);', - '$callable = fn() => throw new Exception();', - '$value = $falsableValue ?: throw new InvalidArgumentException();', - '$value = !empty($array) + public function provideNegativePhp80Cases(): \Generator + { + $cases = [ + '$bar = $foo1 ?? throw new \Exception($e);', + '$callable = fn() => throw new Exception();', + '$value = $falsableValue ?: throw new InvalidArgumentException();', + '$value = !empty($array) ? reset($array) : throw new InvalidArgumentException();', - '$a = $condition && throw new Exception();', - '$a = $condition || throw new Exception();', - '$a = $condition and throw new Exception();', - '$a = $condition or throw new Exception();', - ]; + '$a = $condition && throw new Exception();', + '$a = $condition || throw new Exception();', + '$a = $condition and throw new Exception();', + '$a = $condition or throw new Exception();', + ]; - $template = ' $case) { - yield [sprintf('PHP8 Negative case %d', $index) => sprintf($template, $case)]; - } + foreach ($cases as $index => $case) { + yield [sprintf('PHP8 Negative case %d', $index) => sprintf($template, $case)]; } } @@ -700,9 +710,8 @@ public function testConditionsWithoutBraces(string $expected, ?string $input = n $this->doTest($expected, $input); } - public function provideConditionsWithoutBracesCases(): array + public function provideConditionsWithoutBracesCases(): \Generator { - $cases = []; $statements = [ 'die;', 'throw new Exception($i);', @@ -713,59 +722,11 @@ public function provideConditionsWithoutBracesCases(): array 'foreach($a as $b){throw new Exception($i);}', ]; - if (\PHP_VERSION_ID >= 70000) { - $statements[] = 'throw new class extends Exception{};'; - $statements[] = 'throw new class ($a, 9) extends Exception{ public function z($a, $b){ echo 7;} };'; - } - - if (\PHP_VERSION_ID >= 80000) { - $statements[] = '$b = $a ?? throw new Exception($i);'; - } - - $ifTemplate = 'generateConditionsWithoutBracesCase($statement); } - $cases[] = [ + yield [ 'doTest($expected); + } + + public function provideConditionsWithoutBraces70Cases(): \Generator + { + yield from $this->generateConditionsWithoutBracesCase('throw new class extends Exception{};'); + yield from $this->generateConditionsWithoutBracesCase('throw new class ($a, 9) extends Exception{ public function z($a, $b){ echo 7;} };'); + } + + /** + * @dataProvider provideConditionsWithoutBraces80Cases + * @requires PHP 8.0 + */ + public function testConditionsWithoutBraces80(string $expected): void + { + $this->doTest($expected); + } + + public function provideConditionsWithoutBraces80Cases(): \Generator + { + yield from $this->generateConditionsWithoutBracesCase('$b = $a ?? throw new Exception($i);'); } /** @@ -799,8 +787,8 @@ public function testIsInConditionWithoutBraces(array $indexes, string $input): v $reflection = new \ReflectionObject($this->fixer); $method = $reflection->getMethod('isInConditionWithoutBraces'); $method->setAccessible(true); - $tokens = Tokens::fromCode($input); + foreach ($indexes as $index => $expected) { static::assertSame( $expected, @@ -963,6 +951,50 @@ public function provideIsInConditionWithoutBracesCases(): array ]; } + private function generateConditionsWithoutBracesCase(string $statement): \Generator + { + $ifTemplate = '> */ diff --git a/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php b/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php index 93d2aed1e2f..26c0a604102 100644 --- a/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php +++ b/tests/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixerTest.php @@ -210,23 +210,6 @@ public function provideFixCases(): \Generator ], ]; - if (\PHP_VERSION_ID < 80000) { - yield [ - ' [ 'doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield [ + 'expectException(\PhpCsFixer\ConfigurationException\InvalidForEnvFixerConfigurationException::class); + $this->expectException(InvalidForEnvFixerConfigurationException::class); $this->expectExceptionMessage($exceptionMessega); $this->fixer->configure($configuration); diff --git a/tests/Fixer/ControlStructure/YodaStyleFixerTest.php b/tests/Fixer/ControlStructure/YodaStyleFixerTest.php index bb929f2c713..cab46f16299 100644 --- a/tests/Fixer/ControlStructure/YodaStyleFixerTest.php +++ b/tests/Fixer/ControlStructure/YodaStyleFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\ControlStructure; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -650,11 +651,13 @@ function foo() { } $assignmentOperators = ['=', '**=', '*=', '|=', '+=', '-=', '^=', '<<=', '>>=', '&=', '.=', '/=', '%=']; + if (\PHP_VERSION_ID >= 70400) { $assignmentOperators[] = '??='; } $logicalOperators = ['xor', 'or', 'and', '||', '&&']; + if (\PHP_VERSION_ID >= 70400) { $logicalOperators[] = '??'; } @@ -777,7 +780,7 @@ public function testComplexConfiguration(): void */ public function testInvalidConfig(array $config, string $expectedMessage): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches("#^\\[{$this->fixer->getName()}\\] {$expectedMessage}$#"); $this->fixer->configure($config); @@ -876,24 +879,24 @@ public function testWithConfig(array $config, string $expected): void $this->doTest($expected); } - public function provideFixWithConfigCases(): array + public function provideFixWithConfigCases(): \Generator { - return [ + yield [ [ - [ - 'identical' => false, - ], - ' false, + ], + ' false, - 'identical' => false, - ], - ' false, + 'identical' => false, + ], + 'event == \'created\') { foreach ($revision->getModified() as $col => $data) { $model->$col = $data[\'new\']; @@ -903,7 +906,6 @@ public function provideFixWithConfigCases(): array $model->$col = $data[\'old\']; } }', - ], ]; } @@ -939,21 +941,20 @@ public function testPHP74CasesInverse(string $expected, ?string $input = null, ? $this->doTest($expected, $input); } - public function providePHP74Cases(): array + public function providePHP74Cases(): \Generator { - return [ - [ - ' $c === array(1) ? $b : $d;', - null, - [ - 'less_and_greater' => false, - ], - ], + yield [ + ' $c === array(1) ? $b : $d;', + null, [ - ' false, ], ]; + + yield [ + 'doTest($expected, $input); } - public function provideFixCases(): array + public function provideFixCases(): \Generator { - $cases = $this->createTestCases([ + yield from $this->createTestCases([ [' /** * @Foo @@ -98,7 +98,7 @@ public function provideFixCases(): array */'], ]); - $cases[] = [ + yield [ 'doTest($expected, $input); } - public function provideFixWithColonCases(): array + public function provideFixWithColonCases(): \Generator { - return $this->createTestCases([ + yield from $this->createTestCases([ [' /** * @Foo diff --git a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php index fab4ba1b1c2..ebcfe46668a 100644 --- a/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php +++ b/tests/Fixer/FunctionNotation/FunctionDeclarationFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\FunctionNotation; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; @@ -31,7 +32,7 @@ final class FunctionDeclarationFixerTest extends AbstractFixerTestCase public function testInvalidConfigurationClosureFunctionSpacing(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches( '#^\[function_declaration\] Invalid configuration: The option "closure_function_spacing" with value "neither" is invalid\. Accepted values are: "none", "one"\.$#' ); diff --git a/tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php b/tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php index 9518309d9b4..59092a7d841 100644 --- a/tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php +++ b/tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php @@ -40,16 +40,14 @@ public function testFix(string $expected, ?string $input = null, array $configur $indent = ' '; $lineEnding = "\n"; - if (null !== $expected) { - if (false !== strpos($expected, "\t")) { - $indent = "\t"; - } elseif (preg_match('/\n \S/', $expected)) { - $indent = ' '; - } - - if (false !== strpos($expected, "\r")) { - $lineEnding = "\r\n"; - } + if (false !== strpos($expected, "\t")) { + $indent = "\t"; + } elseif (preg_match('/\n \S/', $expected)) { + $indent = ' '; + } + + if (false !== strpos($expected, "\r")) { + $lineEnding = "\r\n"; } $this->fixer->configure($configuration); diff --git a/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php b/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php index 883d86d1d12..af463f98f67 100644 --- a/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php +++ b/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php @@ -145,18 +145,6 @@ function TisMy ($p1) ], ]; - if (\PHP_VERSION_ID < 80000) { - yield 'test dynamic by array, curly mix' => [ - ' [ - 'getOutput();', 'getOutput ();', @@ -167,4 +155,26 @@ function TisMy ($p1) 'doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield 'test dynamic by array, curly mix' => [ + ' [ + '= 70000) { - yield [ - ' 70300) { - yield 'trailing comma' => [ - 'doTest($expected, $input); + } + + public function provideFix70Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix73Cases(): \Generator + { + yield 'trailing comma' => [ + 'doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield [ + 'fixer->configure($config); } diff --git a/tests/Fixer/FunctionNotation/ReturnTypeDeclarationFixerTest.php b/tests/Fixer/FunctionNotation/ReturnTypeDeclarationFixerTest.php index 3bcd490712c..e625300422d 100644 --- a/tests/Fixer/FunctionNotation/ReturnTypeDeclarationFixerTest.php +++ b/tests/Fixer/FunctionNotation/ReturnTypeDeclarationFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\FunctionNotation; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -27,7 +28,7 @@ final class ReturnTypeDeclarationFixerTest extends AbstractFixerTestCase { public function testInvalidConfiguration(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches( '#^\[return_type_declaration\] Invalid configuration: The option "s" does not exist\. (Known|Defined) options are: "space_before"\.$#' ); diff --git a/tests/Fixer/FunctionNotation/SingleLineThrowFixerTest.php b/tests/Fixer/FunctionNotation/SingleLineThrowFixerTest.php index 82fecfa2b96..4b4a82fe4b4 100644 --- a/tests/Fixer/FunctionNotation/SingleLineThrowFixerTest.php +++ b/tests/Fixer/FunctionNotation/SingleLineThrowFixerTest.php @@ -274,41 +274,55 @@ function ;', ]; } + } - if (\PHP_VERSION_ID >= 80000) { - yield [ - 'getExceptionFactory()?->createAnException("Foo");', - 'doTest($expected, $input); + } + + public static function provideFix80Cases(): \Generator + { + yield [ + 'getExceptionFactory()?->createAnException("Foo");', + 'getExceptionFactory() ?->createAnException( "Foo" );', - ]; + ]; - yield [' $function->one(), 2 => $function->two(), default => throw new \NotOneOrTwo() }; - ']; + ', + ]; - yield [' $function->one(), 2 => throw new Exception("Number 2 is not allowed."), 1 => $function->three(), default => throw new \NotOneOrTwo() }; - ']; + ', + ]; - yield [ - ' "a", 3 => "b" });', - ' "a", - 3 => "b" - });', - ]; - } + yield [ + ' "a", 3 => "b" });', + ' "a", + 3 => "b" + });', + ]; } } diff --git a/tests/Fixer/FunctionNotation/VoidReturnFixerTest.php b/tests/Fixer/FunctionNotation/VoidReturnFixerTest.php index a0e10cb5a42..72afc3aef72 100644 --- a/tests/Fixer/FunctionNotation/VoidReturnFixerTest.php +++ b/tests/Fixer/FunctionNotation/VoidReturnFixerTest.php @@ -252,7 +252,7 @@ public function testMethodWillNotCauseSyntaxError(string $method, int $arguments $static ? ' static' : '', $method, implode(',', array_map( - function ($n) { return sprintf('$x%d', $n); }, + static function (int $n): string { return sprintf('$x%d', $n); }, array_keys(array_fill(0, $arguments, true)) )) )); diff --git a/tests/Fixer/Import/GroupImportFixerTest.php b/tests/Fixer/Import/GroupImportFixerTest.php index 8e116cbd6f0..55c775e9e54 100644 --- a/tests/Fixer/Import/GroupImportFixerTest.php +++ b/tests/Fixer/Import/GroupImportFixerTest.php @@ -339,23 +339,33 @@ public function provideFixCases(): \Generator use function Foo\b; ', ]; + } + + /** + * @dataProvider provideFixPre80Cases + * @requires PHP <8.0 + */ + public function testFixPre80(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } - if (\PHP_VERSION_ID < 80000) { - yield [ - 'expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage('[ordered_imports] Invalid configuration: Unknown sort types "foo", "bar".'); $this->fixer->configure([ @@ -988,7 +989,7 @@ public function testUnknownOrderTypes(): void public function testInvalidOrderTypesSize(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage('[ordered_imports] Invalid configuration: Missing sort type "function".'); $this->fixer->configure([ @@ -999,7 +1000,7 @@ public function testInvalidOrderTypesSize(): void public function testInvalidOrderType(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage('[ordered_imports] Invalid configuration: Missing sort type "class".'); $this->fixer->configure([ @@ -1013,7 +1014,7 @@ public function testInvalidOrderType(): void */ public function testInvalidSortAlgorithm(array $configuration, string $expectedValue): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage(sprintf( '[ordered_imports] Invalid configuration: The option "sort_algorithm" with value %s is invalid. Accepted values are: "alpha", "length", "none".', $expectedValue diff --git a/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php b/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php index 08bb4ef5ead..30ac2660deb 100644 --- a/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php +++ b/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php @@ -130,11 +130,21 @@ public function provideFixCases(): \Generator ', ], ]; + } - if (\PHP_VERSION_ID < 80000) { - yield [ - 'doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield [ + 'expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage(sprintf('[declare_equal_normalize] Invalid configuration: %s', $expectedMessage)); $this->fixer->configure($config); diff --git a/tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php b/tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php index 7ccee41120f..5704c2c8ac3 100644 --- a/tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php +++ b/tests/Fixer/LanguageConstruct/ErrorSuppressionFixerTest.php @@ -41,7 +41,7 @@ public function provideFixCases(): \Generator { yield from [ [ - '', + '', ], [ '', @@ -115,12 +115,22 @@ public function provideFixCases(): \Generator [ErrorSuppressionFixer::OPTION_MUTE_DEPRECATION_ERROR => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES => true, ErrorSuppressionFixer::OPTION_NOISE_REMAINING_USAGES_EXCLUDE => ['trigger_error']], ], ]; + } - if (\PHP_VERSION_ID < 80000) { - yield [ - '', - ]; - } + /** + * @dataProvider provideFixPre80Cases + * @requires PHP <8.0 + */ + public function testFixPre80(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield [ + '', + ]; } /** diff --git a/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php b/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php index bf49eb6a684..991d39c5890 100644 --- a/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php +++ b/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\LanguageConstruct; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -248,7 +249,7 @@ class Foo{ public function Bar(){ echo $reflection = new \ReflectionClass(get_cl */ public function testInvalidConfigurationKeys(array $config): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[function_to_constant\] Invalid configuration: The option "functions" with value array is invalid\.$#'); $this->fixer->configure($config); @@ -265,7 +266,7 @@ public function provideInvalidConfigurationKeysCases(): array public function testInvalidConfigurationValue(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[function_to_constant\] Invalid configuration: The option "0" does not exist\. Defined options are: "functions"\.$#'); $this->fixer->configure(['pi123']); diff --git a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php index d61c903d83b..39de88139d5 100644 --- a/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php +++ b/tests/Fixer/LanguageConstruct/NoUnsetOnPropertyFixerTest.php @@ -122,12 +122,22 @@ public function provideFixCases(): \Generator unset(c($a)->a); ', ]; + } - if (\PHP_VERSION_ID < 80000) { - yield 'It does not break curly access expressions' => [ - 'doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield 'It does not break curly access expressions' => [ + 'fixer->configure(['syntax' => 'long']); - $this->doTest($expected, $input); + $this->doTest($input, $expected); // test reversed } - public function providePhp72Cases(): array + public function providePhp72Cases(): \Generator { - return [ - [ - 'fixer->configure(['syntax' => 'long']); - $this->doTest($expected, $input); + $this->doTest($input, $expected); // test reversed } - public function providePhp73Cases(): array + public function providePhp73Cases(): \Generator { - return [ - [ - ' + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixerTest.php b/tests/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixerTest.php index ded89cb643a..27b9f2a86c8 100644 --- a/tests/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixerTest.php +++ b/tests/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixerTest.php @@ -18,7 +18,7 @@ use PhpCsFixer\WhitespacesFixerConfig; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php index 6370919c325..625b9a6d84b 100644 --- a/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php +++ b/tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\Operator; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; @@ -815,7 +816,7 @@ function b( public function testWrongConfigItem(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches( '/^\[binary_operator_spaces\] Invalid configuration: The option "foo" does not exist\. Defined options are: "default", "operators"\.$/' ); @@ -825,7 +826,7 @@ public function testWrongConfigItem(): void public function testWrongConfigTypeForOperators(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches( '/^\[binary_operator_spaces\] Invalid configuration: The option "operators" with value true is expected to be of type "array", but is of type "(bool|boolean)"\.$/' ); @@ -835,7 +836,7 @@ public function testWrongConfigTypeForOperators(): void public function testWrongConfigTypeForOperatorsKey(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[binary_operator_spaces\] Invalid configuration: Unexpected "operators" key, expected any of ".*", got "integer#123"\.$/'); $this->fixer->configure(['operators' => [123 => 1]]); @@ -843,7 +844,7 @@ public function testWrongConfigTypeForOperatorsKey(): void public function testWrongConfigTypeForOperatorsKeyValue(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[binary_operator_spaces\] Invalid configuration: Unexpected value for operator "\+", expected any of ".*", got "string#abc"\.$/'); $this->fixer->configure(['operators' => ['+' => 'abc']]); diff --git a/tests/Fixer/Operator/ConcatSpaceFixerTest.php b/tests/Fixer/Operator/ConcatSpaceFixerTest.php index 98215d6a7f6..922f299b622 100644 --- a/tests/Fixer/Operator/ConcatSpaceFixerTest.php +++ b/tests/Fixer/Operator/ConcatSpaceFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\Operator; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -28,7 +29,7 @@ final class ConcatSpaceFixerTest extends AbstractFixerTestCase { public function testInvalidConfigMissingKey(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[concat_space\] Invalid configuration: The option "a" does not exist\. Defined options are: "spacing"\.$#'); $this->fixer->configure(['a' => 1]); @@ -36,7 +37,7 @@ public function testInvalidConfigMissingKey(): void public function testInvalidConfigValue(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[concat_space\] Invalid configuration: The option "spacing" with value "tabs" is invalid\. Accepted values are: "one", "none"\.$#'); $this->fixer->configure(['spacing' => 'tabs']); diff --git a/tests/Fixer/Operator/IncrementStyleFixerTest.php b/tests/Fixer/Operator/IncrementStyleFixerTest.php index e271beabf10..06f161615b0 100644 --- a/tests/Fixer/Operator/IncrementStyleFixerTest.php +++ b/tests/Fixer/Operator/IncrementStyleFixerTest.php @@ -48,7 +48,7 @@ public function testFixPostIncrement(string $expected, ?string $input = null): v public function provideFixPostIncrementCases(): array { - return array_map(static function (array $case) { + return array_map(static function (array $case): array { return array_reverse($case); }, $this->provideFixPreIncrementCases()); } diff --git a/tests/Fixer/Operator/NewWithBracesFixerTest.php b/tests/Fixer/Operator/NewWithBracesFixerTest.php index 4e47b1143aa..8c2c93b6a40 100644 --- a/tests/Fixer/Operator/NewWithBracesFixerTest.php +++ b/tests/Fixer/Operator/NewWithBracesFixerTest.php @@ -246,23 +246,6 @@ public function provideFixCases(): \Generator ], ]; - if (\PHP_VERSION_ID < 80000) { - yield [ - '', - '', - ]; - - yield [ - 'doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield [ + '', + '', + ]; + + yield [ + 'bar(); - $bar2 = new $foo[0][1]?->bar(); - ', + $bar1 = new $foo[0]?->bar(); + $bar2 = new $foo[0][1]?->bar(); + ', ]; } } diff --git a/tests/Fixer/Operator/StandardizeIncrementFixerTest.php b/tests/Fixer/Operator/StandardizeIncrementFixerTest.php index 882bc52ea12..ea51cd15b50 100644 --- a/tests/Fixer/Operator/StandardizeIncrementFixerTest.php +++ b/tests/Fixer/Operator/StandardizeIncrementFixerTest.php @@ -554,57 +554,40 @@ public static function bar() { ], ]; - if (\PHP_VERSION_ID < 80000) { - yield [ - '{$bar};', - '{$bar} += 1;', - ]; + yield [ + '{$bar->{$baz}};', - '{$bar->{$baz}} += 1;', - ]; + yield [ + ' 2;', + ]; - yield [ - ' 2;', + ]; - yield from [ - [ - ' 2;', - ], - [ - ' 2;', - ], - [ - '$b::$c;', - '$b::$c += 1;', - ], - [ - '$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h;', - '$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h += 1;', - ], + yield [ + '$b::$c;', + '$b::$c += 1;', + ]; + + yield [ + '$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h;', + '$b::$c->${$d}->${$e}::f(1 + 2 * 3)->$g::$h += 1;', ]; } @@ -625,4 +608,36 @@ public function provideFix74Cases(): array ], ]; } + + /** + * @dataProvider provideFixPre80Cases + * @requires PHP <8.0 + */ + public function testFixPre80(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield [ + '{$bar};', + '{$bar} += 1;', + ]; + + yield [ + '{$bar->{$baz}};', + '{$bar->{$baz}} += 1;', + ]; + + yield [ + '', ]; - if (\PHP_VERSION_ID < 80000) { - yield [ - '{$b} ? $bar{0} : $foo;', - ]; + yield [ + 'doTest($expected, $input); + } - yield [ - '{$b} ? $bar{0} : $foo;', + ]; - yield [ - ' [ - '$a[0] ? : 1;', - '$a[0] ? __FILE__.$a.$b{2}.$c->$a[0] : 1;', - ]; - } + yield [ + ' [ + '$a[0] ? : 1;', + '$a[0] ? __FILE__.$a.$b{2}.$c->$a[0] : 1;', ]; } diff --git a/tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php b/tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php index 6a01bee3261..3904da54121 100644 --- a/tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php +++ b/tests/Fixer/Operator/TernaryToNullCoalescingFixerTest.php @@ -175,24 +175,34 @@ public function provideFixCases(): \Generator ;', ], ]; + } - if (\PHP_VERSION_ID < 80000) { - yield ['doTest($expected, $input); + } - yield [ - 'expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[php_unit_construct\] Invalid configuration: The option "assertions" .*\.$/'); $this->fixer->configure(['assertions' => ['__TEST__']]); diff --git a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php index 065e4d83444..38852df63f8 100644 --- a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\PhpUnit; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; @@ -259,7 +260,7 @@ public function provideNotFixCases(): array public function testInvalidConfig(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[php_unit_dedicate_assert\] Invalid configuration: The option "target" .*\.$/'); $this->fixer->configure(['target' => '_unknown_']); diff --git a/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php index 05c24a4db16..c130ca7b3c5 100644 --- a/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitStrictFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\PhpUnit; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -130,7 +131,7 @@ public function provideTestNoFixWithWrongNumberOfArgumentsCases(): array public function testInvalidConfig(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[php_unit_strict\] Invalid configuration: The option "assertions" .*\.$/'); $this->fixer->configure(['assertions' => ['__TEST__']]); diff --git a/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php index b08f85eca38..a02a27386bd 100644 --- a/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\PhpUnit; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PHPUnit\Framework\TestCase; @@ -48,7 +49,7 @@ public function testFixerContainsAllPhpunitStaticMethodsInItsList(): void public function testWrongConfigTypeForMethodsKey(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/Unexpected "methods" key, expected any of ".*", got "integer#123"\.$/'); $this->fixer->configure(['methods' => [123 => 1]]); @@ -56,7 +57,7 @@ public function testWrongConfigTypeForMethodsKey(): void public function testWrongConfigTypeForMethodsValue(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/Unexpected value for method "assertSame", expected any of ".*", got "integer#123"\.$/'); $this->fixer->configure(['methods' => ['assertSame' => 123]]); diff --git a/tests/Fixer/Phpdoc/AlignMultilineCommentFixerTest.php b/tests/Fixer/Phpdoc/AlignMultilineCommentFixerTest.php index cff6bd58b48..30b6497793a 100644 --- a/tests/Fixer/Phpdoc/AlignMultilineCommentFixerTest.php +++ b/tests/Fixer/Phpdoc/AlignMultilineCommentFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\Phpdoc; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\WhitespacesFixerConfig; @@ -28,7 +29,7 @@ final class AlignMultilineCommentFixerTest extends AbstractFixerTestCase { public function testInvalidConfiguration(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->fixer->configure(['a' => 1]); } diff --git a/tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php b/tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php index 3af6e13cf01..9501b3e6fd6 100644 --- a/tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php +++ b/tests/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php b/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php index 70215abed28..7dfdb9d0bf2 100644 --- a/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php +++ b/tests/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixerTest.php @@ -1234,6 +1234,19 @@ function foo(): bool {} ', ['remove_inheritdoc' => true], ], + 'remove_trait_inheritdoc' => [ + ' true], + ], ]; } diff --git a/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php b/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php index 50dee9bcb6e..11e19edb5d6 100644 --- a/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocLineSpanFixerTest.php @@ -425,8 +425,6 @@ class Bar /** * @requires PHP 7.1 * @dataProvider provideFix71Cases - * - * @param string $input */ public function testFix71(string $expected, string $input = null, array $config = []): void { @@ -472,8 +470,6 @@ class Foo /** * @requires PHP 7.4 * @dataProvider provideFixPhp74Cases - * - * @param string $input */ public function testFixPhp74(string $expected, string $input = null, array $config = []): void { diff --git a/tests/Fixer/Phpdoc/PhpdocNoAccessFixerTest.php b/tests/Fixer/Phpdoc/PhpdocNoAccessFixerTest.php index 3e33db0982c..dd99f81f924 100644 --- a/tests/Fixer/Phpdoc/PhpdocNoAccessFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocNoAccessFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Phpdoc/PhpdocNoAliasTagFixerTest.php b/tests/Fixer/Phpdoc/PhpdocNoAliasTagFixerTest.php index 254e02193f8..3d9fce3dac0 100644 --- a/tests/Fixer/Phpdoc/PhpdocNoAliasTagFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocNoAliasTagFixerTest.php @@ -14,10 +14,11 @@ namespace PhpCsFixer\Tests\Fixer\Phpdoc; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski * @author SpacePossum * @@ -29,7 +30,7 @@ final class PhpdocNoAliasTagFixerTest extends AbstractFixerTestCase { public function testInvalidConfigCase1(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[phpdoc_no_alias_tag\] Invalid configuration: Tag to replace must be a string\.$#'); $this->fixer->configure(['replacements' => [1 => 'abc']]); @@ -37,7 +38,7 @@ public function testInvalidConfigCase1(): void public function testInvalidConfigCase2(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[phpdoc_no_alias_tag\] Invalid configuration: Tag to replace to from "a" must be a string\.$#'); $this->fixer->configure(['replacements' => ['a' => null]]); @@ -45,7 +46,7 @@ public function testInvalidConfigCase2(): void public function testInvalidConfigCase3(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[phpdoc_no_alias_tag\] Invalid configuration: Tag "see" cannot be replaced by invalid tag "link\*\/"\.$#'); $this->fixer->configure(['replacements' => ['see' => 'link*/']]); @@ -53,7 +54,7 @@ public function testInvalidConfigCase3(): void public function testInvalidConfigCase4(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[phpdoc_no_alias_tag\] Invalid configuration: Cannot change tag "link" to tag "see", as the tag "see" is configured to be replaced to "link"\.$#'); $this->fixer->configure(['replacements' => [ @@ -65,7 +66,7 @@ public function testInvalidConfigCase4(): void public function testInvalidConfigCase5(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[phpdoc_no_alias_tag\] Invalid configuration: Cannot change tag "b" to tag "see", as the tag "see" is configured to be replaced to "link"\.$#'); $this->fixer->configure(['replacements' => [ @@ -77,7 +78,7 @@ public function testInvalidConfigCase5(): void public function testInvalidConfigCase6(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('#^\[phpdoc_no_alias_tag\] Invalid configuration: Cannot change tag "see" to tag "link", as the tag "link" is configured to be replaced to "b"\.$#'); $this->fixer->configure(['replacements' => [ diff --git a/tests/Fixer/Phpdoc/PhpdocNoEmptyReturnFixerTest.php b/tests/Fixer/Phpdoc/PhpdocNoEmptyReturnFixerTest.php index 22dcc88476d..a55ce39908d 100644 --- a/tests/Fixer/Phpdoc/PhpdocNoEmptyReturnFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocNoEmptyReturnFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Phpdoc/PhpdocNoPackageFixerTest.php b/tests/Fixer/Phpdoc/PhpdocNoPackageFixerTest.php index 4138969cc01..b3e345d80b1 100644 --- a/tests/Fixer/Phpdoc/PhpdocNoPackageFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocNoPackageFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Phpdoc/PhpdocOrderFixerTest.php b/tests/Fixer/Phpdoc/PhpdocOrderFixerTest.php index be4d2fb78e8..04308c979e7 100644 --- a/tests/Fixer/Phpdoc/PhpdocOrderFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocOrderFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php b/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php index 1b53ae65e91..728b7fa86f7 100644 --- a/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\Phpdoc; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -144,7 +145,7 @@ public function provideGeneratedFixCases(): array */ public function testInvalidConfiguration(array $configuration, string $message): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches(sprintf('/^\[phpdoc_return_self_reference\] %s$/', preg_quote($message, '/'))); $this->fixer->configure($configuration); diff --git a/tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php b/tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php index 5f78dd09ab5..ffe94c1ad19 100644 --- a/tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocScalarFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Phpdoc/PhpdocSeparationFixerTest.php b/tests/Fixer/Phpdoc/PhpdocSeparationFixerTest.php index 34a216aeab8..fcd7589ae46 100644 --- a/tests/Fixer/Phpdoc/PhpdocSeparationFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocSeparationFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * @@ -406,7 +406,7 @@ public function testClassDocBlock(): void * @subpackage Foo\Bar * * @author Dariusz RumiƄski - * @author Graham Campbell + * @author Graham Campbell * @copyright Foo Bar * @license MIT */ @@ -428,7 +428,7 @@ class Bar {} * @subpackage Foo\Bar * @author Dariusz RumiƄski * - * @author Graham Campbell + * @author Graham Campbell * * @copyright Foo Bar * @@ -455,7 +455,7 @@ public function testPoorAlignment(): void * @internal * * @author Dariusz RumiƄski - *@author Graham Campbell + *@author Graham Campbell */ class Bar {} @@ -476,7 +476,7 @@ class Bar {} * @author Dariusz RumiƄski * * - *@author Graham Campbell + *@author Graham Campbell */ class Bar {} diff --git a/tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php b/tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php index 683ab544976..2bf83e61db6 100644 --- a/tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocSummaryFixerTest.php @@ -18,7 +18,7 @@ use PhpCsFixer\WhitespacesFixerConfig; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Phpdoc/PhpdocTrimFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTrimFixerTest.php index 475a2a18ec7..17a40def6a3 100644 --- a/tests/Fixer/Phpdoc/PhpdocTrimFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocTrimFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * @@ -122,7 +122,7 @@ public function testClassDocBlock(): void * @internal * * @author Dariusz RumiƄski - * @author Graham Campbell + * @author Graham Campbell */ class Bar {} @@ -141,7 +141,7 @@ class Bar {} * @internal * * @author Dariusz RumiƄski - * @author Graham Campbell + * @author Graham Campbell * * * diff --git a/tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php index a0de2889591..33d0715c93a 100644 --- a/tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php @@ -14,10 +14,11 @@ namespace PhpCsFixer\Tests\Fixer\Phpdoc; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski * * @internal @@ -256,7 +257,7 @@ public function testWithConfig(): void public function testWrongConfig(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[phpdoc_types\] Invalid configuration: The option "groups" .*\.$/'); $this->fixer->configure(['groups' => ['__TEST__']]); diff --git a/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php b/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php index cde568bde6a..4e9b9b0c187 100644 --- a/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/ReturnNotation/SimplifiedNullReturnFixerTest.php b/tests/Fixer/ReturnNotation/SimplifiedNullReturnFixerTest.php index 8c9b04082bb..c6d1168f6ce 100644 --- a/tests/Fixer/ReturnNotation/SimplifiedNullReturnFixerTest.php +++ b/tests/Fixer/ReturnNotation/SimplifiedNullReturnFixerTest.php @@ -17,7 +17,7 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author Graham Campbell + * @author Graham Campbell * * @internal * diff --git a/tests/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixerTest.php b/tests/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixerTest.php index 63270df74ae..8fc8b879183 100644 --- a/tests/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixerTest.php +++ b/tests/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixerTest.php @@ -20,7 +20,7 @@ /** * @author John Kelly - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski * @author Egidijus Girčys * diff --git a/tests/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixerTest.php b/tests/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixerTest.php index 26cfc24d8c1..31e8ba7fbfb 100644 --- a/tests/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixerTest.php +++ b/tests/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixerTest.php @@ -18,7 +18,7 @@ /** * @author John Kelly - * @author Graham Campbell + * @author Graham Campbell * @author Dariusz RumiƄski * * @internal diff --git a/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php b/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php index 592ef0ca97a..66c7a0086db 100644 --- a/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php +++ b/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php @@ -82,13 +82,23 @@ public function provideFixCases(): \Generator ', ], ]; + } - if (\PHP_VERSION_ID < 80000) { - yield [ - '', - '', - ]; - } + /** + * @dataProvider provideFixPre80Cases + * @requires PHP <8.0 + */ + public function testFixPre80(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFixPre80Cases(): \Generator + { + yield [ + '', + '', + ]; } public function testOpenWithEcho(): void diff --git a/tests/Fixer/Whitespace/IndentationTypeFixerTest.php b/tests/Fixer/Whitespace/IndentationTypeFixerTest.php index b994645cf46..0ff2ffed5aa 100644 --- a/tests/Fixer/Whitespace/IndentationTypeFixerTest.php +++ b/tests/Fixer/Whitespace/IndentationTypeFixerTest.php @@ -311,7 +311,7 @@ public function provideMessyWhitespacesReversedCases() { return array_filter( $this->provideMessyWhitespacesCases(), - static function (string $key) { + static function (string $key): bool { return false === strpos($key, 'mix indentation'); }, ARRAY_FILTER_USE_KEY diff --git a/tests/Fixer/Whitespace/LineEndingFixerTest.php b/tests/Fixer/Whitespace/LineEndingFixerTest.php index 179d15b523b..1af23a49500 100644 --- a/tests/Fixer/Whitespace/LineEndingFixerTest.php +++ b/tests/Fixer/Whitespace/LineEndingFixerTest.php @@ -87,7 +87,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v public function provideMessyWhitespacesCases() { - $cases = array_map(static function (array $case) { + $cases = array_map(static function (array $case): array { return array_reverse($case); }, $this->provideCommonCases()); diff --git a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php index 5856a97aa9f..04c4f299359 100644 --- a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php +++ b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\Whitespace; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; use PhpCsFixer\WhitespacesFixerConfig; @@ -457,7 +458,7 @@ public function provideLineBreakCases(): array public function testWrongConfig(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[no_extra_blank_lines\] Invalid configuration: The option "tokens" .*\.$/'); $this->fixer->configure(['tokens' => ['__TEST__']]); diff --git a/tests/Fixer/Whitespace/NoSpacesAroundOffsetFixerTest.php b/tests/Fixer/Whitespace/NoSpacesAroundOffsetFixerTest.php index 15f6e9b6359..68458634254 100644 --- a/tests/Fixer/Whitespace/NoSpacesAroundOffsetFixerTest.php +++ b/tests/Fixer/Whitespace/NoSpacesAroundOffsetFixerTest.php @@ -14,6 +14,7 @@ namespace PhpCsFixer\Tests\Fixer\Whitespace; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** @@ -358,7 +359,7 @@ public function provideConfigurationCases(): \Generator public function testWrongConfig(): void { - $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessageMatches('/^\[no_spaces_around_offset\] Invalid configuration: The option "positions" .*\.$/'); $this->fixer->configure(['positions' => ['foo']]); diff --git a/tests/Fixer/Whitespace/NoTrailingWhitespaceFixerTest.php b/tests/Fixer/Whitespace/NoTrailingWhitespaceFixerTest.php index f50585ef35f..ac8763ce303 100644 --- a/tests/Fixer/Whitespace/NoTrailingWhitespaceFixerTest.php +++ b/tests/Fixer/Whitespace/NoTrailingWhitespaceFixerTest.php @@ -134,18 +134,28 @@ public function provideFixCases() "= 80000) { - yield [ - 'doTest($expected, $input); + } + + public function provideFix80Cases(): \Generator + { + yield [ + 'expectException(\Symfony\Component\OptionsResolver\Exception\MissingOptionsException::class); + $this->expectException(MissingOptionsException::class); $configuration->resolve([]); } @@ -116,7 +118,7 @@ public function testResolveWithAllowedTypes(): void $configuration->resolve(['foo' => 1]) ); - $this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class); + $this->expectException(InvalidOptionsException::class); $configuration->resolve(['foo' => '1']); } @@ -131,7 +133,7 @@ public function testResolveWithAllowedValues(): void $configuration->resolve(['foo' => true]) ); - $this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class); + $this->expectException(InvalidOptionsException::class); $configuration->resolve(['foo' => 1]); } @@ -146,7 +148,7 @@ public function testResolveWithAllowedValuesSubset(): void $configuration->resolve(['foo' => ['bar']]) ); - $this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class); + $this->expectException(InvalidOptionsException::class); $configuration->resolve(['foo' => ['baz']]); } @@ -156,7 +158,7 @@ public function testResolveWithUndefinedOption(): void new FixerOption('bar', 'Bar.'), ]); - $this->expectException(\Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException::class); + $this->expectException(UndefinedOptionsException::class); $configuration->resolve(['foo' => 'foooo']); } @@ -196,7 +198,7 @@ public function testResolveWithAliasedDuplicateConfig(): void new AliasedFixerOption(new FixerOption('bar', 'Bar.'), 'baz'), ]); - $this->expectException(\Symfony\Component\OptionsResolver\Exception\InvalidOptionsException::class); + $this->expectException(InvalidOptionsException::class); $this->expectExceptionMessage('Aliased option "bar"/"baz" is passed multiple times'); $configuration->resolve([ diff --git a/tests/FixerFactoryTest.php b/tests/FixerFactoryTest.php index 9369b707532..cf69927bb3b 100644 --- a/tests/FixerFactoryTest.php +++ b/tests/FixerFactoryTest.php @@ -14,6 +14,8 @@ namespace PhpCsFixer\Tests; +use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\Fixer\FixerInterface; use PhpCsFixer\FixerFactory; use PhpCsFixer\RuleSet\RuleSet; @@ -297,13 +299,9 @@ public function testConfigureNonConfigurableFixer(): void $fixer = $this->createFixerDouble('non_configurable'); $factory->registerFixer($fixer, false); - $this->expectException( - \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class - ); + $this->expectException(InvalidFixerConfigurationException::class); - $this->expectExceptionMessage( - '[non_configurable] Is not configurable.' - ); + $this->expectExceptionMessage('[non_configurable] Is not configurable.'); $factory->useRuleSet(new RuleSet([ 'non_configurable' => ['bar' => 'baz'], @@ -319,14 +317,12 @@ public function testConfigureFixerWithNonArray($value): void { $factory = new FixerFactory(); - $fixer = $this->prophesize(\PhpCsFixer\Fixer\ConfigurableFixerInterface::class); + $fixer = $this->prophesize(ConfigurableFixerInterface::class); $fixer->getName()->willReturn('foo'); $factory->registerFixer($fixer->reveal(), false); - $this->expectException( - \PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class - ); + $this->expectException(InvalidFixerConfigurationException::class); $this->expectExceptionMessage( '[foo] Rule must be enabled (true), disabled (false) or configured (non-empty, assoc array). Other values are not allowed.' @@ -349,7 +345,7 @@ public function provideConfigureFixerWithNonArrayCases(): array public function testConfigurableFixerIsConfigured(): void { - $fixer = $this->prophesize(\PhpCsFixer\Fixer\ConfigurableFixerInterface::class); + $fixer = $this->prophesize(ConfigurableFixerInterface::class); $fixer->getName()->willReturn('foo'); $fixer->configure(['bar' => 'baz'])->shouldBeCalled(); diff --git a/tests/Linter/AbstractLinterTestCase.php b/tests/Linter/AbstractLinterTestCase.php index ee14567f5d8..2f2fa4efb76 100644 --- a/tests/Linter/AbstractLinterTestCase.php +++ b/tests/Linter/AbstractLinterTestCase.php @@ -15,6 +15,7 @@ namespace PhpCsFixer\Tests\Linter; use PhpCsFixer\Linter\LinterInterface; +use PhpCsFixer\Linter\LintingException; use PhpCsFixer\Tests\TestCase; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -35,7 +36,7 @@ public function testLintingAfterTokenManipulation(): void $tokens = Tokens::fromCode("insertAt(1, new Token([T_NS_SEPARATOR, '\\'])); - $this->expectException(\PhpCsFixer\Linter\LintingException::class); + $this->expectException(LintingException::class); $linter->lintSource($tokens->generateCode())->check(); } @@ -45,7 +46,7 @@ public function testLintingAfterTokenManipulation(): void public function testLintFile(string $file, ?string $errorMessage = null): void { if (null !== $errorMessage) { - $this->expectException(\PhpCsFixer\Linter\LintingException::class); + $this->expectException(LintingException::class); $this->expectExceptionMessage($errorMessage); } else { $this->expectNotToPerformAssertions(); @@ -81,7 +82,7 @@ public function provideLintFileCases(): array public function testLintSource(string $source, ?string $errorMessage = null): void { if (null !== $errorMessage) { - $this->expectException(\PhpCsFixer\Linter\LintingException::class); + $this->expectException(LintingException::class); $this->expectExceptionMessage($errorMessage); } else { $this->expectNotToPerformAssertions(); diff --git a/tests/PregTest.php b/tests/PregTest.php index cdbedc3e329..e78e18fe2db 100644 --- a/tests/PregTest.php +++ b/tests/PregTest.php @@ -67,7 +67,7 @@ public function providePatternValidationCases(): array */ public function testPatternValidation(string $pattern, ?int $expected = null, ?string $expectedException = null, ?string $expectedMessage = null): void { - $setup = function () use ($expectedException, $expectedMessage) { + $setup = function () use ($expectedException, $expectedMessage): bool { $i = 0; if (null !== $expectedException) { @@ -107,7 +107,7 @@ public function testPatternValidation(string $pattern, ?int $expected = null, ?s */ public function testPatternsValidation(string $pattern, ?int $expected = null, ?string $expectedException = null, ?string $expectedMessage = null): void { - $setup = function () use ($expectedException, $expectedMessage) { + $setup = function () use ($expectedException, $expectedMessage): bool { $i = 0; if (null !== $expectedException) { @@ -203,7 +203,7 @@ public function testReplaceCallbackFailing(): void */ public function testReplaceCallback($pattern, $subject): void { - $callback = static function (array $x) { return implode('-', $x); }; + $callback = static function (array $x): string { return implode('-', $x); }; $expectedResult = preg_replace_callback($pattern, $callback, $subject); $actualResult = Preg::replaceCallback($pattern, $callback, $subject); diff --git a/tests/RuleSet/RuleSetTest.php b/tests/RuleSet/RuleSetTest.php index 7a527082342..44d7894d09b 100644 --- a/tests/RuleSet/RuleSetTest.php +++ b/tests/RuleSet/RuleSetTest.php @@ -290,7 +290,7 @@ public function testRiskyRulesInSet(array $set, bool $safe): void public function provideSafeSetCases(): \Generator { foreach (RuleSets::getSetDefinitionNames() as $name) { - yield $name => $sets[$name] = [ + yield $name => [ [$name => true], false === strpos($name, ':risky'), ]; diff --git a/tests/RuleSet/RuleSetsTest.php b/tests/RuleSet/RuleSetsTest.php index 0e276d14ceb..619e462ff93 100644 --- a/tests/RuleSet/RuleSetsTest.php +++ b/tests/RuleSet/RuleSetsTest.php @@ -141,7 +141,7 @@ public function provideSetDefinitionNameCases(): array { $setDefinitionNames = RuleSets::getSetDefinitionNames(); - return array_map(static function (string $setDefinitionName) { + return array_map(static function (string $setDefinitionName): array { return [$setDefinitionName]; }, $setDefinitionNames); } @@ -167,11 +167,11 @@ public function providePHPUnitMigrationSetDefinitionNameCases(): array { $setDefinitionNames = RuleSets::getSetDefinitionNames(); - $setDefinitionPHPUnitMigrationNames = array_filter($setDefinitionNames, static function (string $setDefinitionName) { + $setDefinitionPHPUnitMigrationNames = array_filter($setDefinitionNames, static function (string $setDefinitionName): bool { return 1 === preg_match('/^@PHPUnit\d{2}Migration:risky$/', $setDefinitionName); }); - return array_map(static function (string $setDefinitionName) { + return array_map(static function (string $setDefinitionName): array { return [$setDefinitionName]; }, $setDefinitionPHPUnitMigrationNames); } @@ -196,7 +196,7 @@ private static function assertPHPUnitVersionIsLargestAllowed(string $setName, st $allowedVersionsForRuleset = array_filter( $allowedVersionsForFixer, - static function (string $version) use ($maximumVersionForRuleset) { + static function (string $version) use ($maximumVersionForRuleset): bool { return strcmp($maximumVersionForRuleset, $version) >= 0; } ); diff --git a/tests/Test/AbstractFixerTestCase.php b/tests/Test/AbstractFixerTestCase.php index 86ff90b87a1..f642b11c481 100644 --- a/tests/Test/AbstractFixerTestCase.php +++ b/tests/Test/AbstractFixerTestCase.php @@ -233,7 +233,7 @@ public function testFixerUseInsertSlicesWhenOnlyInsertionsArePerformed(): void $sequences = $this->findAllTokenSequences($tokens, [[T_VARIABLE, '$tokens'], [T_OBJECT_OPERATOR], [T_STRING]]); - $usedMethods = array_unique(array_map(function (array $sequence) { + $usedMethods = array_unique(array_map(static function (array $sequence): string { $last = end($sequence); return $last->getContent(); @@ -246,7 +246,7 @@ public function testFixerUseInsertSlicesWhenOnlyInsertionsArePerformed(): void return; } - $usedMethods = array_filter($usedMethods, function (string $method) { + $usedMethods = array_filter($usedMethods, static function (string $method): bool { return 0 === Preg::match('/^(count|find|generate|get|is|rewind)/', $method); }); @@ -400,7 +400,7 @@ protected function doTest(string $expected, ?string $input = null, ?\SplFileInfo static::assertSame( \count($tokens), - \count(array_unique(array_map(static function (Token $token) { + \count(array_unique(array_map(static function (Token $token): string { return spl_object_hash($token); }, $tokens->toArray()))), 'Token items inside Tokens collection must be unique.' diff --git a/tests/Test/AbstractIntegrationTestCase.php b/tests/Test/AbstractIntegrationTestCase.php index dbe8fa5f00e..3366bbc7c2f 100644 --- a/tests/Test/AbstractIntegrationTestCase.php +++ b/tests/Test/AbstractIntegrationTestCase.php @@ -312,7 +312,7 @@ protected static function assertRevertedOrderFixing(IntegrationCase $case, strin static::assertGreaterThan( 1, \count(array_unique(array_map( - static function (FixerInterface $fixer) { + static function (FixerInterface $fixer): int { return $fixer->getPriority(); }, static::createFixers($case) diff --git a/tests/Test/AbstractTransformerTestCase.php b/tests/Test/AbstractTransformerTestCase.php index 6ff399fec59..adc9b34405e 100644 --- a/tests/Test/AbstractTransformerTestCase.php +++ b/tests/Test/AbstractTransformerTestCase.php @@ -140,7 +140,7 @@ static function ($kindOrPrototype) { sprintf( 'Transformation into "%s" must be allowed in self-documentation of the Transformer, currently allowed custom tokens are: %s', Token::getNameForId($modification), - implode(', ', array_map(function ($ct) { return Token::getNameForId($ct); }, $customTokensOfTransformer)) + implode(', ', array_map(static function ($ct) { return Token::getNameForId($ct); }, $customTokensOfTransformer)) ) ); } else { diff --git a/tests/Tokenizer/Analyzer/Analysis/TypeAnalysisTest.php b/tests/Tokenizer/Analyzer/Analysis/TypeAnalysisTest.php index e361be6ca55..d3ad0d0a215 100644 --- a/tests/Tokenizer/Analyzer/Analysis/TypeAnalysisTest.php +++ b/tests/Tokenizer/Analyzer/Analysis/TypeAnalysisTest.php @@ -71,17 +71,17 @@ public function provideReservedCases(): array ['array', true], ['bool', true], ['callable', true], + ['float', true], ['int', true], ['iterable', true], - ['float', true], ['mixed', true], ['numeric', true], ['object', true], + ['other', false], ['resource', true], ['self', true], ['string', true], ['void', true], - ['other', false], ]; } } diff --git a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php index c2f7b11ce1f..2a2469a9b27 100644 --- a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php @@ -36,7 +36,7 @@ final class FunctionsAnalyzerTest extends TestCase */ public function testIsGlobalFunctionCall(string $code, array $indices): void { - self::assertIsGlobalFunctionCall($code, $indices); + self::assertIsGlobalFunctionCall($indices, $code); } public function provideIsGlobalFunctionCallCases(): \Generator @@ -91,7 +91,7 @@ public function provideIsGlobalFunctionCallCases(): \Generator [], ]; - yield [ + yield 'function with ref. return' => [ ' [ 'getFunctionReturnType($tokens, $methodIndex); + static::assertSame(serialize($expected), serialize($actual)); } @@ -577,8 +575,6 @@ public function provideFunctionsWithArgumentsPhp74Cases(): \Generator } /** - * @param ?TypeAnalysis $expected - * * @dataProvider provideFunctionsWithReturnTypePhp74Cases * @requires PHP 7.4 */ @@ -586,8 +582,8 @@ public function testFunctionReturnTypeInfoPhp74(string $code, int $methodIndex, { $tokens = Tokens::fromCode($code); $analyzer = new FunctionsAnalyzer(); - $actual = $analyzer->getFunctionReturnType($tokens, $methodIndex); + static::assertSame(serialize($expected), serialize($actual)); } @@ -639,11 +635,13 @@ public function methodOne() { sprintf($template, '$this->'), $i, ]; + yield [ 24 === $i, sprintf($template, 'self::'), $i, ]; + yield [ 24 === $i, sprintf($template, 'static::'), @@ -726,12 +724,12 @@ public function provideFunctionsWithArgumentsPhp80Cases(): \Generator /** * @param int[] $expectedIndices */ - private static function assertIsGlobalFunctionCall(string $code, array $expectedIndices): void + private static function assertIsGlobalFunctionCall(array $expectedIndices, string $code): void { $tokens = Tokens::fromCode($code); $analyzer = new FunctionsAnalyzer(); - $actualIndices = []; + foreach ($tokens as $index => $token) { if ($analyzer->isGlobalFunctionCall($tokens, $index)) { $actualIndices[] = $index; diff --git a/tests/Tokenizer/Analyzer/NamespacesAnalyzerTest.php b/tests/Tokenizer/Analyzer/NamespacesAnalyzerTest.php index d26ddaed65d..8f440fe3d81 100644 --- a/tests/Tokenizer/Analyzer/NamespacesAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/NamespacesAnalyzerTest.php @@ -100,57 +100,71 @@ public function testGetNamespaceAt(string $code, int $index, NamespaceAnalysis $ ); } - public function provideGetNamespaceAtCases(): array + public function provideGetNamespaceAtCases(): \Generator { - return [ - [ - 'getContent(); }, $generator->generate($input) @@ -42,12 +43,12 @@ static function (Token $token) { ); } - public function provideGeneratorCases(): array + public function provideGeneratorCases(): \Generator { - return [ - ['test', ['test']], - ['Some\\Namespace', ['Some', '\\', 'Namespace']], - ['Some\\Bigger\\Namespace', ['Some', '\\', 'Bigger', '\\', 'Namespace']], - ]; + yield [['test'], 'test']; + + yield [['Some', '\\', 'Namespace'], 'Some\\Namespace']; + + yield [['Some', '\\', 'Bigger', '\\', 'Namespace'], 'Some\\Bigger\\Namespace']; } } diff --git a/tests/Tokenizer/TokenTest.php b/tests/Tokenizer/TokenTest.php index 32b41896d8d..01f52de8f14 100644 --- a/tests/Tokenizer/TokenTest.php +++ b/tests/Tokenizer/TokenTest.php @@ -273,7 +273,7 @@ public function provideIsWhitespaceCases(): array */ public function testCreatingToken($prototype, ?int $expectedId, ?string $expectedContent, ?bool $expectedIsArray, ?string $expectedExceptionClass = null): void { - if ($expectedExceptionClass) { + if (null !== $expectedExceptionClass) { $this->expectException($expectedExceptionClass); } diff --git a/tests/Tokenizer/TokensAnalyzerTest.php b/tests/Tokenizer/TokensAnalyzerTest.php index 4866ab4affe..9453668859a 100644 --- a/tests/Tokenizer/TokensAnalyzerTest.php +++ b/tests/Tokenizer/TokensAnalyzerTest.php @@ -37,13 +37,13 @@ public function testGetClassyElements(array $expectedElements, string $source): { $tokens = Tokens::fromCode($source); - foreach ($expectedElements as $index => $element) { - $expectedElements[$index] = [ - 'token' => $tokens[$index], - 'type' => $element['type'], - 'classIndex' => $element['classIndex'], - ]; - } + array_walk( + $expectedElements, + static function (array &$element, $index) use ($tokens): void { + $element['token'] = $tokens[$index]; + ksort($element); + } + ); $tokensAnalyzer = new TokensAnalyzer($tokens); @@ -58,28 +58,28 @@ public function provideGetClassyElementsCases(): \Generator yield 'trait import' => [ [ 10 => [ - 'type' => 'trait_import', 'classIndex' => 4, + 'type' => 'trait_import', ], 19 => [ - 'type' => 'trait_import', 'classIndex' => 4, + 'type' => 'trait_import', ], 24 => [ - 'type' => 'const', 'classIndex' => 4, + 'type' => 'const', ], 35 => [ - 'type' => 'method', 'classIndex' => 4, + 'type' => 'method', ], 55 => [ - 'type' => 'trait_import', 'classIndex' => 49, + 'type' => 'trait_import', ], 64 => [ - 'type' => 'method', 'classIndex' => 49, + 'type' => 'method', ], ], ' [ - 'type' => 'property', 'classIndex' => 1, + 'type' => 'property', ], 14 => [ - 'type' => 'property', 'classIndex' => 1, + 'type' => 'property', ], 19 => [ - 'type' => 'property', 'classIndex' => 1, + 'type' => 'property', ], 28 => [ - 'type' => 'property', 'classIndex' => 1, + 'type' => 'property', ], 42 => [ - 'type' => 'const', 'classIndex' => 1, + 'type' => 'const', ], 53 => [ - 'type' => 'method', 'classIndex' => 1, + 'type' => 'method', ], 83 => [ - 'type' => 'method', 'classIndex' => 1, + 'type' => 'method', ], 140 => [ - 'type' => 'method', 'classIndex' => 1, + 'type' => 'method', ], 164 => [ - 'type' => 'const', 'classIndex' => 158, + 'type' => 'const', ], 173 => [ - 'type' => 'trait_import', 'classIndex' => 158, + 'type' => 'trait_import', ], ], <<<'PHP' @@ -215,24 +215,24 @@ class Foo static::assertSame( [ 11 => [ + 'classIndex' => 1, 'token' => $tokens[11], 'type' => 'property', - 'classIndex' => 1, ], 19 => [ + 'classIndex' => 1, 'token' => $tokens[19], 'type' => 'property', - 'classIndex' => 1, ], 26 => [ + 'classIndex' => 1, 'token' => $tokens[26], 'type' => 'property', - 'classIndex' => 1, ], 41 => [ + 'classIndex' => 1, 'token' => $tokens[41], 'type' => 'property', - 'classIndex' => 1, ], ], $elements @@ -269,34 +269,34 @@ function B() {} // do not count this static::assertSame( [ 9 => [ + 'classIndex' => 1, 'token' => $tokens[9], 'type' => 'property', // $A - 'classIndex' => 1, ], 14 => [ + 'classIndex' => 1, 'token' => $tokens[14], 'type' => 'method', // B - 'classIndex' => 1, ], 33 => [ + 'classIndex' => 26, 'token' => $tokens[33], 'type' => 'property', // $level1 - 'classIndex' => 26, ], 38 => [ + 'classIndex' => 26, 'token' => $tokens[38], 'type' => 'method', // XYZ - 'classIndex' => 26, ], 56 => [ + 'classIndex' => 50, 'token' => $tokens[56], 'type' => 'property', // $level2 - 'classIndex' => 50, ], 74 => [ + 'classIndex' => 1, 'token' => $tokens[74], 'type' => 'method', // C - 'classIndex' => 1, ], ], $elements @@ -382,64 +382,64 @@ public function otherFunction1() static::assertSame( [ 9 => [ + 'classIndex' => 1, 'token' => $tokens[9], 'type' => 'method', - 'classIndex' => 1, ], 27 => [ + 'classIndex' => 21, 'token' => $tokens[27], 'type' => 'method', - 'classIndex' => 21, ], 44 => [ + 'classIndex' => 1, 'token' => $tokens[44], 'type' => 'method', - 'classIndex' => 1, ], 64 => [ + 'classIndex' => 56, 'token' => $tokens[64], 'type' => 'method', - 'classIndex' => 56, ], 82 => [ + 'classIndex' => 76, 'token' => $tokens[82], 'type' => 'method', - 'classIndex' => 76, ], 100 => [ + 'classIndex' => 94, 'token' => $tokens[100], 'type' => 'method', - 'classIndex' => 94, ], 118 => [ + 'classIndex' => 112, 'token' => $tokens[118], 'type' => 'method', - 'classIndex' => 112, ], 139 => [ + 'classIndex' => 112, 'token' => $tokens[139], 'type' => 'method', - 'classIndex' => 112, ], 170 => [ + 'classIndex' => 76, 'token' => $tokens[170], 'type' => 'method', - 'classIndex' => 76, ], 188 => [ + 'classIndex' => 182, 'token' => $tokens[188], 'type' => 'method', - 'classIndex' => 182, ], 206 => [ + 'classIndex' => 200, 'token' => $tokens[206], 'type' => 'method', - 'classIndex' => 200, ], 242 => [ + 'classIndex' => 56, 'token' => $tokens[242], 'type' => 'method', - 'classIndex' => 56, ], ], $elements @@ -474,13 +474,13 @@ class Foo $tokens = Tokens::fromCode($source); $tokensAnalyzer = new TokensAnalyzer($tokens); $elements = $tokensAnalyzer->getClassyElements(); - $expected = []; + foreach ([11, 23, 31, 44, 51, 54, 61, 69] as $index) { $expected[$index] = [ + 'classIndex' => 1, 'token' => $tokens[$index], 'type' => 'property', - 'classIndex' => 1, ]; } @@ -490,7 +490,7 @@ class Foo /** * @dataProvider provideIsAnonymousClassCases */ - public function testIsAnonymousClass(string $source, array $expected): void + public function testIsAnonymousClass(array $expected, string $source): void { $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); @@ -502,49 +502,44 @@ public function testIsAnonymousClass(string $source, array $expected): void public function provideIsAnonymousClassCases(): \Generator { yield [ - ' false], + ' true], + ' true], + ' false, 19 => true], + 'a) implements B{}) extends C{};', [7 => true, 11 => true], + 'a) implements B{}) extends C{};', ]; yield [ - ' false], - ]; - - yield [ - ' true], + '= 80000) { yield [ - ' true], + ' true], + ' false], + ' false], + ' true], + ' true], + ' true], ' true], ], [ - ' true], + ' true], ' true], ], [ + [2 => false], ' false], ], ]; } @@ -616,7 +611,7 @@ function foo (): array { * @dataProvider provideIsLambda74Cases * @requires PHP 7.4 */ - public function testIsLambda74(string $source, array $expected): void + public function testIsLambda74(array $expected, string $source): void { $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); @@ -629,12 +624,12 @@ public function provideIsLambda74Cases(): array { return [ [ - ' [];', [5 => true], + ' [];', ], [ - ' [];', [5 => true], + ' [];', ], ]; } @@ -643,7 +638,7 @@ public function provideIsLambda74Cases(): array * @dataProvider provideIsLambda71Cases * @requires PHP 7.1 */ - public function testIsLambda71(string $source, array $expected): void + public function testIsLambda71(array $expected, string $source): void { $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); @@ -656,39 +651,39 @@ public function provideIsLambda71Cases(): array { return [ [ + [6 => true], ' true], ], [ + [2 => false], ' false], ], [ + [6 => true], ' true], ], [ + [6 => true], ' true], ], [ + [2 => false], ' false], ], ]; } @@ -697,7 +692,7 @@ function foo (): ?int { * @dataProvider provideIsLambda80Cases * @requires PHP 8.0 */ - public function testIsLambda80(string $source, array $expected): void + public function testIsLambda80(array $expected, string $source): void { $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); @@ -710,20 +705,21 @@ public function provideIsLambda80Cases(): array { return [ [ + [6 => true], ' true], ], [ + [6 => true], ' true], ], [ + [14 => true], ' true], ], ]; } @@ -754,175 +749,176 @@ public function testIsLambdaInvalid(): void /** * @dataProvider provideIsConstantInvocationCases */ - public function testIsConstantInvocation(string $source, array $expected): void + public function testIsConstantInvocation(array $expected, string $source): void { - $this->doIsConstantInvocationTest($source, $expected); + $this->doIsConstantInvocationTest($expected, $source); } public function provideIsConstantInvocationCases(): array { return [ [ - ' true], + ' true], + ' false, 5 => false, 7 => true], + ' true, 7 => true, 11 => true], + ' true, 7 => true, 11 => true], + ' true], + ' true], + ' true, 5 => true], + ' false, 3 => true, 6 => false, 8 => true], + ' true, 8 => true], + ' true, 7 => false, 9 => false, 11 => true], + ' BAR; }', [3 => false, 11 => true, 16 => true, 20 => true], + ' BAR; }', ], [ - ' true], + ' false], + ' false], + ' false, 7 => false, 9 => false], + ' false, 8 => false], + ' false], + ' false], + ' false], + ' false, 7 => false], + ' false, 7 => false], + ' false, 7 => false, 10 => false, 13 => false], + ' false, 9 => false], + ' false, 9 => false], + ' false, 9 => false, 12 => false, 16 => false, 18 => false, 22 => false], + ' false, 6 => false, 11 => false, 17 => false], + ' false], + ' false, 3 => false], + ' false, 3 => false], + ' false], + ' false], + ' false], + ' true], + ' false, 6 => false], + ' false, 3 => true, 7 => true], + ' false, 7 => false, 10 => false, 13 => false], + ' false, 5 => false, 8 => false, 10 => false, 13 => false, 15 => false], + ' false, 8 => false], + ' false, 5 => false, 8 => false, 11 => false, 15 => false, 18 => false], + ' false, 16 => false, 21 => false], ' false, 16 => false, 21 => false], ], ]; } @@ -939,41 +934,41 @@ abstract public function test(): Foo; * @dataProvider provideIsConstantInvocation71Cases * @requires PHP 7.1 */ - public function testIsConstantInvocation71(string $source, array $expected): void + public function testIsConstantInvocation71(array $expected, string $source): void { - $this->doIsConstantInvocationTest($source, $expected); + $this->doIsConstantInvocationTest($expected, $source); } public function provideIsConstantInvocation71Cases(): array { return [ [ - ' false, 6 => false], + ' false, 9 => false], + ' false, 11 => false, 13 => false], + ' false, 11 => false, 16 => false], + ' false, 11 => false, 17 => false], + ' false, 11 => false, 17 => false], + ' false, 11 => false, 18 => false], + 'doIsConstantInvocationTest($source, $expected); + $this->doIsConstantInvocationTest($expected, $source); } public function provideIsConstantInvocationPhp80Cases(): \Generator { yield [ + [6 => false, 16 => false, 21 => false, 23 => false], ' false, 16 => false, 21 => false, 23 => false], ]; yield [ - ' false, 8 => false, 10 => false], + 'b?->c;', [3 => false, 5 => false], + 'b?->c;', ]; yield [ - ' false], + ' false], + ' false, 13 => false], + ' false, 5 => false, 10 => false], + ' false, 7 => false, 14 => false], + 'b?->c;'); - $tokensAnalyzer = new TokensAnalyzer($tokens); foreach ($tokens as $index => $token) { if (!$token->isGivenKind(T_STRING)) { continue; } + static::assertFalse($tokensAnalyzer->isConstantInvocation($index)); } } @@ -1065,12 +1060,13 @@ public function testIsConstantInvocationForNullSafeObjectOperator(): void /** * @dataProvider provideIsUnarySuccessorOperatorCases */ - public function testIsUnarySuccessorOperator(string $source, array $expected): void + public function testIsUnarySuccessorOperator(array $expected, string $source): void { $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); foreach ($expected as $index => $isUnary) { static::assertSame($isUnary, $tokensAnalyzer->isUnarySuccessorOperator($index)); + if ($isUnary) { static::assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index)); static::assertFalse($tokensAnalyzer->isBinaryOperator($index)); @@ -1082,40 +1078,40 @@ public function provideIsUnarySuccessorOperatorCases(): array { return [ [ - ' true], + ' true], + ' true], + ' true, 4 => false], + ' true], + 'bar++;', [4 => true], + 'bar++;', ], [ - '{"bar"}++;', [6 => true], + '{"bar"}++;', ], 'array access' => [ - ' true], + ' [ - ' true], + ' $isUnary) { static::assertSame($isUnary, $tokensAnalyzer->isUnaryPredecessorOperator($index)); + if ($isUnary) { static::assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index)); static::assertFalse($tokensAnalyzer->isBinaryOperator($index)); @@ -1140,64 +1137,64 @@ public function provideIsUnaryPredecessorOperatorCases(): array { return [ [ - ' true], + ' true], + ' true], + ' false, 5 => true], + ' true, 2 => true], + ' true], + ' true], + ' true], + ' true, 8 => true], + ' true, 11 => true, 17 => true], + ' true], + ' true, 6 => true], + ' true], + ' true], + ' true], + ' $isBinary) { static::assertSame($isBinary, $tokensAnalyzer->isBinaryOperator($index)); + if ($isBinary) { static::assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index)); static::assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index)); @@ -1222,123 +1220,123 @@ public function provideIsBinaryOperatorCases(): \Generator { $cases = [ [ - ' true], + ' true], + '', [3 => true], + '', ], [ - '', [3 => true], + '', ], [ - ' true], + ' true], + ' true], + ' true], + ' true], + ' true], + ' true], + ' true], + ' true], + ' true], + ' true], + ' true], + ' true], + ' true], ' true], ], [ + [3 => true], ' true], ], [ - ' "c", );', [3 => true, 9 => true, 12 => false], + ' "c", );', ], [ - ' true, 5 => false], + ' true, 5 => false, 8 => true, 10 => false], + ' true, 5 => false], + ' false, 4 => true], + ' true], + ' true], + ' true], + ' true], + ' true], + '', '|', '^', '&=', '&&', '||', '.=', '/=', '==', '>=', '===', '!=', '<>', '!==', '<=', 'and', 'or', 'xor', '-=', '%=', '*=', '|=', '+=', '<<', '<<=', '>>', '>>=', '^', ]; + + yield from $cases; + foreach ($operators as $operator) { - $cases[] = [ - ' true], + ' true], + ' $b;', + ]; - yield from [ - [ - ' $b;', - [3 => true], - ], - [ - ' true], - ], + yield [ + [3 => true], + 'isArray($tokenIndex), 'Expected to be an array.'); static::assertSame($isMultiLineArray, $tokensAnalyzer->isArrayMultiLine($tokenIndex), sprintf('Expected %sto be a multiline array', $isMultiLineArray ? '' : 'not ')); } @@ -1453,6 +1452,7 @@ public function testIsArray71(string $source, array $tokenIndexes): void foreach ($tokens as $index => $token) { $expect = \in_array($index, $tokenIndexes, true); + static::assertSame( $expect, $tokensAnalyzer->isArray($index), @@ -1481,12 +1481,13 @@ public function provideIsArray71Cases(): array * @dataProvider provideIsBinaryOperator71Cases * @requires PHP 7.1 */ - public function testIsBinaryOperator71(string $source, array $expected): void + public function testIsBinaryOperator71(array $expected, string $source): void { $tokensAnalyzer = new TokensAnalyzer(Tokens::fromCode($source)); foreach ($expected as $index => $isBinary) { static::assertSame($isBinary, $tokensAnalyzer->isBinaryOperator($index)); + if ($isBinary) { static::assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index)); static::assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index)); @@ -1494,13 +1495,11 @@ public function testIsBinaryOperator71(string $source, array $expected): void } } - public function provideIsBinaryOperator71Cases(): array + public function provideIsBinaryOperator71Cases(): \Generator { - return [ - [ - ' false], - ], + yield [ + [11 => false], + ' $isBinary) { static::assertSame($isBinary, $tokensAnalyzer->isBinaryOperator($index)); + if ($isBinary) { static::assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index)); static::assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index)); @@ -1521,13 +1521,11 @@ public function testIsBinaryOperator74(string $source, array $expected): void } } - public function provideIsBinaryOperator74Cases(): array + public function provideIsBinaryOperator74Cases(): \Generator { - return [ - [ - ' true], - ], + yield [ + [3 => true], + ' $isBinary) { static::assertSame($isBinary, $tokensAnalyzer->isBinaryOperator($index)); + if ($isBinary) { static::assertFalse($tokensAnalyzer->isUnarySuccessorOperator($index)); static::assertFalse($tokensAnalyzer->isUnaryPredecessorOperator($index)); @@ -1551,20 +1550,23 @@ public function testIsBinaryOperator80(string $source, array $expected): void public static function provideIsBinaryOperator80Cases(): iterable { yield [ - ' false], + ' false], + ' false], + ' false], + 'isArray($tokenIndex)); } @@ -1662,6 +1665,7 @@ public function testGetFunctionProperties(string $source, int $index, array $exp $tokens = Tokens::fromCode($source); $tokensAnalyzer = new TokensAnalyzer($tokens); $attributes = $tokensAnalyzer->getMethodAttributes($index); + static::assertSame($expected, $attributes); } @@ -1785,6 +1789,7 @@ public function testIsWhilePartOfDoWhile(): void $tokens = Tokens::fromCode($source); $tokensAnalyzer = new TokensAnalyzer($tokens); + foreach ($tokens as $index => $token) { if (!$token->isGivenKind(T_WHILE)) { continue; @@ -1805,6 +1810,7 @@ public function testGetImportUseIndexes(array $expected, string $input, bool $pe { $tokens = Tokens::fromCode($input); $tokensAnalyzer = new TokensAnalyzer($tokens); + static::assertSame($expected, $tokensAnalyzer->getImportUseIndexes($perNamespace)); } @@ -1895,6 +1901,7 @@ public function testGetImportUseIndexesPHP72(array $expected, string $input, boo { $tokens = Tokens::fromCode($input); $tokensAnalyzer = new TokensAnalyzer($tokens); + static::assertSame($expected, $tokensAnalyzer->getImportUseIndexes($perNamespace)); } @@ -1961,39 +1968,39 @@ public function foo() { static::assertSame([ 13 => [ + 'classIndex' => 1, 'token' => $tokens[13], 'type' => 'method', // setUp - 'classIndex' => 1, ], 46 => [ + 'classIndex' => 1, 'token' => $tokens[46], 'type' => 'method', // testSomethingWithMoney - 'classIndex' => 1, ], 100 => [ + 'classIndex' => 87, 'token' => $tokens[100], // const A 'type' => 'const', - 'classIndex' => 87, ], 115 => [ + 'classIndex' => 65, 'token' => $tokens[115], // const B 'type' => 'const', - 'classIndex' => 65, ], 124 => [ + 'classIndex' => 65, // $a 'token' => $tokens[124], 'type' => 'method', // foo - 'classIndex' => 65, // $a ], 143 => [ + 'classIndex' => 138, 'token' => $tokens[143], // const AA 'type' => 'const', - 'classIndex' => 138, ], 161 => [ + 'classIndex' => 158, 'token' => $tokens[161], // const AB 'type' => 'const', - 'classIndex' => 158, ], ], $elements); } @@ -2053,7 +2060,7 @@ public function provideIsSuperGlobalCases(): array return $cases; } - private function doIsConstantInvocationTest(string $source, array $expected): void + private function doIsConstantInvocationTest(array $expected, string $source): void { $tokens = Tokens::fromCode($source); diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index a8f7905ae33..25ae75b969f 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -866,11 +866,6 @@ public function testClone(): void } /** - * @param string $expected valid PHP code - * @param string $input valid PHP code - * @param int $index token index - * @param string $whiteSpace white space - * * @dataProvider provideEnsureWhitespaceAtIndexCases */ public function testEnsureWhitespaceAtIndex(string $expected, string $input, int $index, int $offset, string $whiteSpace): void diff --git a/tests/Tokenizer/Transformer/ConstructorPromotionTransformerTest.php b/tests/Tokenizer/Transformer/ConstructorPromotionTransformerTest.php index 5001d13e475..15932215916 100644 --- a/tests/Tokenizer/Transformer/ConstructorPromotionTransformerTest.php +++ b/tests/Tokenizer/Transformer/ConstructorPromotionTransformerTest.php @@ -29,7 +29,7 @@ final class ConstructorPromotionTransformerTest extends AbstractTransformerTestC * @dataProvider provideProcessCases * @requires PHP 8.0 */ - public function testProcess(string $source, array $expectedTokens): void + public function testProcess(array $expectedTokens, string $source): void { $this->doTest( $source, @@ -45,6 +45,11 @@ public function testProcess(string $source, array $expectedTokens): void public function provideProcessCases(): \Generator { yield [ + [ + 14 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, + 25 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, + 36 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, + ], ' CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, - 25 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, - 36 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, - ], ]; yield [ - ' CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, 22 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, 28 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, ], + ' - * @author Graham Campbell + * @author Graham Campbell * @author OdĂ­n del RĂ­o * * @internal @@ -46,7 +46,6 @@ protected function tearDown(): void /** * @param string $expected Camel case string - * @param string $input Input string * * @dataProvider provideCamelCaseToUnderscoreCases */ @@ -169,14 +168,14 @@ static function ($element) { return $element; }, [ ['b', 'd', 'e', 'a', 'c'], ['b', 'd', 'e', 'a', 'c'], - static function ($element) { return 'foo'; }, + static function (): string { return 'foo'; }, 'strcmp', ], [ ['b', 'd', 'e', 'a', 'c'], ['b', 'd', 'e', 'a', 'c'], static function ($element) { return $element; }, - static function ($a, $b) { return 0; }, + static function (): int { return 0; }, ], [ ['bar1', 'baz1', 'foo1', 'bar2', 'baz2', 'foo2'], From 81084f1159bc9492fa70ba4e1215a33f5f1fabbc Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Tue, 31 Aug 2021 18:23:44 +0200 Subject: [PATCH 49/80] Extract ControlStructureContinuationPositionFixer from BracesFixer --- ...ontrol_structure_continuation_position.rst | 56 ++++ doc/rules/index.rst | 2 + src/Fixer/Basic/BracesFixer.php | 56 ++-- ...trolStructureContinuationPositionFixer.php | 172 ++++++++++ ...StructureContinuationPositionFixerTest.php | 297 ++++++++++++++++++ 5 files changed, 554 insertions(+), 29 deletions(-) create mode 100644 doc/rules/control_structure/control_structure_continuation_position.rst create mode 100644 src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php create mode 100644 tests/Fixer/ControlStructure/ControlStructureContinuationPositionFixerTest.php diff --git a/doc/rules/control_structure/control_structure_continuation_position.rst b/doc/rules/control_structure/control_structure_continuation_position.rst new file mode 100644 index 00000000000..63b486b9861 --- /dev/null +++ b/doc/rules/control_structure/control_structure_continuation_position.rst @@ -0,0 +1,56 @@ +================================================ +Rule ``control_structure_continuation_position`` +================================================ + +Control structure continuation keyword must be on the configured line. + +Configuration +------------- + +``position`` +~~~~~~~~~~~~ + +the position of the keyword that continues the control structure. + +Allowed values: ``'next_line'``, ``'same_line'`` + +Default value: ``'same_line'`` + +Examples +-------- + +Example #1 +~~~~~~~~~~ + +*Default* configuration. + +.. code-block:: diff + + --- Original + +++ New + 'next_line']``. + +.. code-block:: diff + + --- Original + +++ New + `_ + Control structure continuation keyword must be on the configured line. - `elseif <./control_structure/elseif.rst>`_ The keyword ``elseif`` should be used instead of ``else if`` so that all control keywords look like single words. - `empty_loop_body <./control_structure/empty_loop_body.rst>`_ diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index 2c26e490d2b..85d2185953a 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -16,6 +16,7 @@ use PhpCsFixer\AbstractProxyFixer; use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\Fixer\ControlStructure\ControlStructureContinuationPositionFixer; use PhpCsFixer\Fixer\LanguageConstruct\DeclareParenthesesFixer; use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; @@ -48,6 +49,11 @@ final class BracesFixer extends AbstractProxyFixer implements ConfigurableFixerI */ public const LINE_SAME = 'same'; + /** + * @var null|ControlStructureContinuationPositionFixer + */ + private $controlStructureContinuationPositionFixer; + /** * {@inheritdoc} */ @@ -138,6 +144,17 @@ public function getPriority(): int return 35; } + public function configure(array $configuration = null): void + { + parent::configure($configuration); + + $this->getControlStructureContinuationPositionFixer()->configure([ + 'position' => self::LINE_NEXT === $this->configuration['position_after_control_structures'] + ? ControlStructureContinuationPositionFixer::NEXT_LINE + : ControlStructureContinuationPositionFixer::SAME_LINE, + ]); + } + /** * {@inheritdoc} */ @@ -154,7 +171,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $this->fixCommentBeforeBrace($tokens); $this->fixMissingControlBraces($tokens); $this->fixIndents($tokens); - $this->fixControlContinuationBraces($tokens); $this->fixSpaceAroundToken($tokens); $this->fixDoWhile($tokens); @@ -193,6 +209,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn protected function createProxyFixers(): array { return [ + $this->getControlStructureContinuationPositionFixer(), new DeclareParenthesesFixer(), ]; } @@ -255,34 +272,6 @@ private function fixCommentBeforeBrace(Tokens $tokens): void } } - private function fixControlContinuationBraces(Tokens $tokens): void - { - $controlContinuationTokens = $this->getControlContinuationTokens(); - - for ($index = \count($tokens) - 1; 0 <= $index; --$index) { - $token = $tokens[$index]; - - if (!$token->isGivenKind($controlContinuationTokens)) { - continue; - } - - $prevIndex = $tokens->getPrevNonWhitespace($index); - $prevToken = $tokens[$prevIndex]; - - if (!$prevToken->equals('}')) { - continue; - } - - $tokens->ensureWhitespaceAtIndex( - $index - 1, - 1, - self::LINE_NEXT === $this->configuration['position_after_control_structures'] ? - $this->whitespacesConfig->getLineEnding().WhitespacesAnalyzer::detectIndent($tokens, $index) - : ' ' - ); - } - } - private function fixDoWhile(Tokens $tokens): void { for ($index = \count($tokens) - 1; 0 <= $index; --$index) { @@ -1005,4 +994,13 @@ private function getSiblingContinuousSingleLineComment(Tokens $tokens, int $inde return $siblingIndex; } + + private function getControlStructureContinuationPositionFixer(): ControlStructureContinuationPositionFixer + { + if (null === $this->controlStructureContinuationPositionFixer) { + $this->controlStructureContinuationPositionFixer = new ControlStructureContinuationPositionFixer(); + } + + return $this->controlStructureContinuationPositionFixer; + } } diff --git a/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php b/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php new file mode 100644 index 00000000000..563ba65bd91 --- /dev/null +++ b/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php @@ -0,0 +1,172 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Fixer\ControlStructure; + +use PhpCsFixer\AbstractFixer; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; +use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; +use PhpCsFixer\FixerDefinition\CodeSample; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\Tokens; + +final class ControlStructureContinuationPositionFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface +{ + /** + * @internal + */ + public const NEXT_LINE = 'next_line'; + + /** + * @internal + */ + public const SAME_LINE = 'same_line'; + + private const CONTROL_CONTINUATION_TOKENS = [ + T_CATCH, + T_ELSE, + T_ELSEIF, + T_FINALLY, + T_WHILE, + ]; + + /** + * {@inheritdoc} + */ + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition( + 'Control structure continuation keyword must be on the configured line.', + [ + new CodeSample( + ' self::NEXT_LINE] + ), + ] + ); + } + + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isAnyTokenKindsFound(self::CONTROL_CONTINUATION_TOKENS); + } + + /** + * Must run after ControlStructureBracesFixer. + */ + public function getPriority(): int + { + return parent::getPriority(); + } + + protected function createConfigurationDefinition(): FixerConfigurationResolverInterface + { + return new FixerConfigurationResolver([ + (new FixerOptionBuilder('position', 'the position of the keyword that continues the control structure.')) + ->setAllowedValues([self::NEXT_LINE, self::SAME_LINE]) + ->setDefault(self::SAME_LINE) + ->getOption(), + ]); + } + + protected function applyFix(\SplFileInfo $file, Tokens $tokens): void + { + $this->fixControlContinuationBraces($tokens); + } + + private function fixControlContinuationBraces(Tokens $tokens): void + { + for ($index = \count($tokens) - 1; 0 < $index; --$index) { + $token = $tokens[$index]; + + if (!$token->isGivenKind(self::CONTROL_CONTINUATION_TOKENS)) { + continue; + } + + $prevIndex = $tokens->getPrevNonWhitespace($index); + $prevToken = $tokens[$prevIndex]; + + if (!$prevToken->equals('}')) { + continue; + } + + if ($token->isGivenKind(T_WHILE)) { + $prevIndex = $tokens->getPrevMeaningfulToken( + $tokens->findBlockStart(Tokens::BLOCK_TYPE_CURLY_BRACE, $prevIndex) + ); + + if (!$tokens[$prevIndex]->isGivenKind(T_DO)) { + continue; + } + } + + $tokens->ensureWhitespaceAtIndex( + $index - 1, + 1, + self::NEXT_LINE === $this->configuration['position'] ? + $this->whitespacesConfig->getLineEnding().$this->detectIndent($tokens, $index) + : ' ' + ); + } + } + + private function detectIndent(Tokens $tokens, int $index): string + { + while (true) { + $whitespaceIndex = $tokens->getPrevTokenOfKind($index, [[T_WHITESPACE]]); + + if (null === $whitespaceIndex) { + return ''; + } + + $whitespaceToken = $tokens[$whitespaceIndex]; + + if (false !== strpos($whitespaceToken->getContent(), "\n")) { + break; + } + + $prevToken = $tokens[$whitespaceIndex - 1]; + + if ($prevToken->isGivenKind([T_OPEN_TAG, T_COMMENT]) && "\n" === substr($prevToken->getContent(), -1)) { + break; + } + + $index = $whitespaceIndex; + } + + $explodedContent = explode("\n", $whitespaceToken->getContent()); + + return end($explodedContent); + } +} diff --git a/tests/Fixer/ControlStructure/ControlStructureContinuationPositionFixerTest.php b/tests/Fixer/ControlStructure/ControlStructureContinuationPositionFixerTest.php new file mode 100644 index 00000000000..6152467304d --- /dev/null +++ b/tests/Fixer/ControlStructure/ControlStructureContinuationPositionFixerTest.php @@ -0,0 +1,297 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Fixer\ControlStructure; + +use PhpCsFixer\Preg; +use PhpCsFixer\Tests\Test\AbstractFixerTestCase; +use PhpCsFixer\WhitespacesFixerConfig; + +/** + * @internal + * + * @covers \PhpCsFixer\Fixer\ControlStructure\ControlStructureContinuationPositionFixer + */ +final class ControlStructureContinuationPositionFixerTest extends AbstractFixerTestCase +{ + /** + * @dataProvider provideFixCases + */ + public function testFix(string $expected, ?string $input = null, array $configuration = null): void + { + if (null !== $configuration) { + $this->fixer->configure($configuration); + } + + $this->doTest($expected, $input); + } + + public function provideFixCases(): iterable + { + yield 'else (same line, default)' => [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' 'next_line'], + ]; + + yield 'elseif (next line)' => [ + ' 'next_line'], + ]; + + yield 'else if (next line)' => [ + ' 'next_line'], + ]; + + yield 'do while (next line)' => [ + ' 'next_line'], + ]; + + yield 'try catch finally (next line)' => [ + ' 'next_line'], + ]; + + yield 'else with comment after closing brace' => [ + ' [ + ' [ + ' [ + ' [ + ' [ + 'fixer->configure($configuration); + } + + $this->fixer->setWhitespacesConfig( + new WhitespacesFixerConfig(' ', "\r\n") + ); + + $this->doTest($expected, $input); + } + + public function provideFixWithWindowsLineEndingsCases(): iterable + { + foreach ($this->provideFixCases() as $label => $case) { + yield $label => [ + Preg::replace('/\n/', "\r\n", $case[0]), + isset($case[1]) ? Preg::replace('/\n/', "\r\n", $case[1]) : null, + $case[2] ?? null, + ]; + } + } +} From 2b027e77d8addad59c44a133511fde636f0fdf54 Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Mon, 30 Aug 2021 23:10:45 +0200 Subject: [PATCH 50/80] DX: ProjectCodeTest - fix detection by testExpectedInputOrder --- tests/AutoReview/ProjectCodeTest.php | 2 +- ...eclarationForDefaultNullValueFixerTest.php | 148 ++++++++++-------- .../ListNotation/ListSyntaxFixerTest.php | 37 +++-- tests/Test/TestCaseUtils.php | 35 +++++ 4 files changed, 142 insertions(+), 80 deletions(-) create mode 100644 tests/Test/TestCaseUtils.php diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index 09f25b5c887..93cb6e229ed 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -406,7 +406,7 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bo } } - $expected = array_filter($expected); + $expected = array_filter($expected, function ($item) { return false !== $item; }); if (\count($expected) < 2) { $this->addToAssertionCount(1); // not enough parameters to test, all good! diff --git a/tests/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixerTest.php b/tests/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixerTest.php index d61b3fee060..f6b6db24a1d 100644 --- a/tests/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixerTest.php +++ b/tests/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixerTest.php @@ -15,6 +15,7 @@ namespace PhpCsFixer\Tests\Fixer\FunctionNotation; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; +use PhpCsFixer\Tests\Test\TestCaseUtils; /** * @author HypeMC @@ -96,10 +97,10 @@ public function provideDoNotFixCases(): \Generator * @dataProvider provideFixCases * @dataProvider provideNonInverseOnlyFixCases */ - public function testFix(string $input, string $expected): void + public function testFix(string $expected, string $input): void { if (\PHP_VERSION_ID < 70100) { - $this->doTest($input); + $this->doTest($expected); } else { $this->doTest($expected, $input); } @@ -108,7 +109,7 @@ public function testFix(string $input, string $expected): void /** * @requires PHP 7.1 * - * @dataProvider provideFixCases + * @dataProvider provideInvertedFixCases * @dataProvider provideInverseOnlyFixCases */ public function testFixInverse(string $expected, string $input): void @@ -121,200 +122,205 @@ public function testFixInverse(string $expected, string $input): void public function provideFixCases(): \Generator { yield [ - 'provideFixCases()); + } + public function provideNonInverseOnlyFixCases(): \Generator { yield [ - 'doTest($expected, $input); } /** - * @dataProvider provideFixPhp74Cases + * @dataProvider provideInvertedFixPhp74Cases * @requires PHP 7.4 */ public function testFixInversePhp74(string $expected, string $input): void @@ -359,55 +365,60 @@ public function testFixInversePhp74(string $expected, string $input): void public function provideFixPhp74Cases(): \Generator { yield [ - ' null;', ' null;', + ' null;', ]; yield [ - ' null;', ' null;', + ' null;', ]; yield [ - ' null;', ' null;', + ' null;', ]; yield [ - ' null;', ' null;', + ' null;', ]; yield [ - ' null;', ' null;', + ' null;', ]; yield [ - ' null;', ' null;', + ' null;', ]; } + public function provideInvertedFixPhp74Cases() + { + return TestCaseUtils::swapExpectedInputTestCases($this->provideFixPhp74Cases()); + } + /** * @dataProvider provideFix80Cases * @requires PHP 8.0 */ - public function testFix80(string $input, ?string $expected = null): void + public function testFix80(string $expected, ?string $input = null): void { - if (null === $expected) { - $this->doTest($input); + if (null === $input) { + $this->doTest($expected); } else { $this->doTest($expected, $input); } } /** - * @dataProvider provideFix80Cases + * @dataProvider provideInvertedFix80Cases * @requires PHP 8.0 */ public function testFixInverse80(string $expected, ?string $input = null): void @@ -420,8 +431,8 @@ public function testFixInverse80(string $expected, ?string $input = null): void public function provideFix80Cases(): \Generator { yield 'trailing comma' => [ - ' [ @@ -430,7 +441,7 @@ public function __construct( public ?string $paramA = null, protected ?string $paramB = null, private ?string $paramC = null, - string $paramD = null, + ?string $paramD = null, $a = [] ) {} }', @@ -439,7 +450,7 @@ public function __construct( public ?string $paramA = null, protected ?string $paramB = null, private ?string $paramC = null, - ?string $paramD = null, + string $paramD = null, $a = [] ) {} }', @@ -454,21 +465,26 @@ public function bbb(int | null $bar = null, $baz = 1) {} ]; yield 'attribute' => [ - ' [ - 'provideFix80Cases()); + } } diff --git a/tests/Fixer/ListNotation/ListSyntaxFixerTest.php b/tests/Fixer/ListNotation/ListSyntaxFixerTest.php index 264bb2ed425..115c697fcde 100644 --- a/tests/Fixer/ListNotation/ListSyntaxFixerTest.php +++ b/tests/Fixer/ListNotation/ListSyntaxFixerTest.php @@ -15,6 +15,7 @@ namespace PhpCsFixer\Tests\Fixer\ListNotation; use PhpCsFixer\Tests\Test\AbstractFixerTestCase; +use PhpCsFixer\Tests\Test\TestCaseUtils; /** * @requires PHP 7.1 @@ -37,7 +38,7 @@ public function testFixWithDefaultConfiguration(): void } /** - * @dataProvider provideToLongCases + * @dataProvider provideFixToLongSyntaxCases */ public function testFixToLongSyntax(string $expected, ?string $input = null): void { @@ -46,7 +47,7 @@ public function testFixToLongSyntax(string $expected, ?string $input = null): vo } /** - * @dataProvider provideToShortCases + * @dataProvider provideFixToShortSyntaxCases */ public function testFixToShortSyntax(string $expected, ?string $input = null): void { @@ -54,10 +55,10 @@ public function testFixToShortSyntax(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideToLongCases(): array + public function provideFixToLongSyntaxCases(): array { // reverse testing - $shortCases = $this->provideToShortCases(); + $shortCases = $this->provideFixToShortSyntaxCases(); $cases = []; foreach ($shortCases as $label => $shortCase) { $cases[$label] = [$shortCase[1], $shortCase[0]]; @@ -100,7 +101,7 @@ public function updateAttributeKey($key, $value) return $cases; } - public function provideToShortCases(): array + public function provideFixToShortSyntaxCases(): array { return [ [ @@ -176,7 +177,7 @@ public function provideToShortCases(): array /** * @requires PHP 7.2 - * @dataProvider providePhp72Cases + * @dataProvider provideFixToShortSyntaxPhp72Cases */ public function testFixToShortSyntaxPhp72(string $expected, string $input): void { @@ -186,15 +187,15 @@ public function testFixToShortSyntaxPhp72(string $expected, string $input): void /** * @requires PHP 7.2 - * @dataProvider providePhp72Cases + * @dataProvider provideFixToLongSyntaxPhp72Cases */ public function testFixToLongSyntaxPhp72(string $expected, string $input): void { $this->fixer->configure(['syntax' => 'long']); - $this->doTest($input, $expected); // test reversed + $this->doTest($expected, $input); } - public function providePhp72Cases(): \Generator + public function provideFixToShortSyntaxPhp72Cases(): \Generator { yield [ 'provideFixToShortSyntaxPhp72Cases()); + } + /** * @requires PHP 7.3 - * @dataProvider providePhp73Cases + * @dataProvider provideFixToShortSyntaxPhp73Cases */ public function testFixToShortSyntaxPhp73(string $expected, string $input): void { @@ -214,15 +220,15 @@ public function testFixToShortSyntaxPhp73(string $expected, string $input): void /** * @requires PHP 7.3 - * @dataProvider providePhp73Cases + * @dataProvider provideFixToLongSyntaxPhp73Cases */ public function testFixToLongSyntaxPhp73(string $expected, string $input): void { $this->fixer->configure(['syntax' => 'long']); - $this->doTest($input, $expected); // test reversed + $this->doTest($expected, $input); } - public function providePhp73Cases(): \Generator + public function provideFixToShortSyntaxPhp73Cases(): \Generator { yield [ 'provideFixToShortSyntaxPhp73Cases()); + } } diff --git a/tests/Test/TestCaseUtils.php b/tests/Test/TestCaseUtils.php new file mode 100644 index 00000000000..ad6390d9eb3 --- /dev/null +++ b/tests/Test/TestCaseUtils.php @@ -0,0 +1,35 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Test; + +/** + * @internal + */ +final class TestCaseUtils +{ + public static function swapExpectedInputTestCases(iterable $cases): iterable + { + foreach ($cases as $case) { + if (1 === \count($case)) { + yield $case; + + continue; + } + + [$case[0], $case[1]] = [$case[1], $case[0]]; + yield $case; + } + } +} From f73470dd6f9aec6c838d547ce6d776bcb4696e9d Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Sat, 4 Sep 2021 23:37:50 +0800 Subject: [PATCH 51/80] Re-add omitted `only_if_meta` option --- doc/rules/class_notation/class_attributes_separation.rst | 3 ++- src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/rules/class_notation/class_attributes_separation.rst b/doc/rules/class_notation/class_attributes_separation.rst index 9b2156ef7ac..b6643c63a4f 100644 --- a/doc/rules/class_notation/class_attributes_separation.rst +++ b/doc/rules/class_notation/class_attributes_separation.rst @@ -11,7 +11,8 @@ Configuration ``elements`` ~~~~~~~~~~~~ -Dictionary of ``const|method|property|trait_import`` => ``none|one`` values. +Dictionary of ``const|method|property|trait_import`` => +``none|one|only_if_meta`` values. Allowed types: ``array`` diff --git a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php index 249b1940806..f61a8df4a39 100644 --- a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php +++ b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php @@ -204,7 +204,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void protected function createConfigurationDefinition(): FixerConfigurationResolverInterface { return new FixerConfigurationResolver([ - (new FixerOptionBuilder('elements', 'Dictionary of `const|method|property|trait_import` => `none|one` values.')) + (new FixerOptionBuilder('elements', 'Dictionary of `const|method|property|trait_import` => `none|one|only_if_meta` values.')) ->setAllowedTypes(['array']) ->setAllowedValues([static function (array $option): bool { foreach ($option as $type => $spacing) { From a89ac4e0fa3216e7ce1e27f2ef7b24020a2353f4 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 4 Sep 2021 12:51:27 +0100 Subject: [PATCH 52/80] Removed PHP 5 exception catch --- src/Runner/Runner.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Runner/Runner.php b/src/Runner/Runner.php index b96dc91b578..971a8a9fd50 100644 --- a/src/Runner/Runner.php +++ b/src/Runner/Runner.php @@ -193,10 +193,6 @@ private function fixFile(\SplFileInfo $file, LintingResultInterface $lintingResu $appliedFixers[] = $fixer->getName(); } } - } catch (\Exception $e) { - $this->processException($name, $e); - - return null; } catch (\ParseError $e) { $this->dispatchEvent( FixerFileProcessedEvent::NAME, From 4f3c0fb52aa279f8be19580f8ed8d4d0f056102a Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Sun, 5 Sep 2021 12:04:36 +0200 Subject: [PATCH 53/80] bump version --- src/Console/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Console/Application.php b/src/Console/Application.php index 541bf68b24c..e0d06302664 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -39,7 +39,7 @@ */ final class Application extends BaseApplication { - public const VERSION = '3.1.1-DEV'; + public const VERSION = '3.2.0-DEV'; public const VERSION_CODENAME = 'River'; /** From fa0d3bc45dd60f996a82e8de153ed1c006ceb638 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sat, 4 Sep 2021 18:07:04 +0000 Subject: [PATCH 54/80] Fixed `class_attributes_separation` processing class with multiple trait imports --- .../ClassAttributesSeparationFixer.php | 2 +- .../ClassAttributesSeparationFixerTest.php | 29 ++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php index 249b1940806..6e3fbcbfa0a 100644 --- a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php +++ b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php @@ -533,7 +533,7 @@ private function getLastTokenIndexOfClassElement(Tokens $tokens, array $class, a do { $elementEndIndex = $tokens->getNextMeaningfulToken($elementEndIndex); - } while ($tokens[$elementEndIndex]->isGivenKind([T_STRING, T_NS_SEPARATOR])); + } while ($tokens[$elementEndIndex]->isGivenKind([T_STRING, T_NS_SEPARATOR]) || $tokens[$elementEndIndex]->equals(',')); if (!$tokens[$elementEndIndex]->equals(';')) { $elementEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tokens->getNextTokenOfKind($element['index'], ['{'])); diff --git a/tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php b/tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php index cf37c576521..aee81b3d6a1 100644 --- a/tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php +++ b/tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php @@ -1161,7 +1161,7 @@ public function provideMessyWhitespacesCases(): array /** * @dataProvider provideConfigCases */ - public function testWithConfig(string $expected, string $input, array $config): void + public function testWithConfig(string $expected, ?string $input, array $config): void { $this->fixer->configure($config); $this->doTest($expected, $input); @@ -1281,6 +1281,33 @@ class Sample }', ['elements' => ['const' => 'none']], ], + 'multiple trait import 5954' => [ + ' ['method' => 'one']], + ], + 'multiple trait import with method 5954' => [ + ' ['method' => 'one']], + ], 'trait group import 5843' => [ ' Date: Sun, 5 Sep 2021 13:48:27 +0200 Subject: [PATCH 55/80] Keep PHPStan cache between Docker runs --- dev-tools/.gitignore | 1 + phpstan.neon | 1 + 2 files changed, 2 insertions(+) diff --git a/dev-tools/.gitignore b/dev-tools/.gitignore index 46fd5bdc227..dce02ead080 100644 --- a/dev-tools/.gitignore +++ b/dev-tools/.gitignore @@ -1,3 +1,4 @@ /composer.lock /bin/ +/phpstan/cache/ /vendor/ diff --git a/phpstan.neon b/phpstan.neon index ffd5911c81c..b5838764885 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -15,3 +15,4 @@ parameters: - '/^Unsafe call to private method [a-zA-Z\\]+::[a-zA-Z]+\(\) through static::\.$/' - '/^\$this\(PhpCsFixer\\Tokenizer\\Tokens\) does not accept PhpCsFixer\\Tokenizer\\Token\|null\.$/' tipsOfTheDay: false + tmpDir: dev-tools/phpstan/cache From 695c8129ffd0dddff33dc4d00016b8ab7d6a3792 Mon Sep 17 00:00:00 2001 From: "John Paul E. Balandan, CPA" Date: Wed, 1 Sep 2021 13:05:38 +0800 Subject: [PATCH 56/80] NoAlternativeSyntaxFixer - Add option to not fix non-monolithic PHP code --- .../no_alternative_syntax.rst | 48 ++-- src/Console/WarningsDetector.php | 2 +- .../NoAlternativeSyntaxFixer.php | 30 ++- .../NoAlternativeSyntaxFixerTest.php | 217 +++++++++++------- 4 files changed, 178 insertions(+), 119 deletions(-) diff --git a/doc/rules/control_structure/no_alternative_syntax.rst b/doc/rules/control_structure/no_alternative_syntax.rst index f91a6981fae..32a6f36f262 100644 --- a/doc/rules/control_structure/no_alternative_syntax.rst +++ b/doc/rules/control_structure/no_alternative_syntax.rst @@ -4,12 +4,26 @@ Rule ``no_alternative_syntax`` Replace control structure alternative syntax to use braces. +Configuration +------------- + +``fix_non_monolithic_code`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Whether to also fix code with inline HTML. + +Allowed types: ``bool`` + +Default value: ``true`` + Examples -------- Example #1 ~~~~~~~~~~ +*Default* configuration. + .. code-block:: diff --- Original @@ -21,35 +35,17 @@ Example #1 Example #2 ~~~~~~~~~~ -.. code-block:: diff - - --- Original - +++ New - true]``. .. code-block:: diff --- Original +++ New - + + + Lorem ipsum. + - + + Rule sets --------- @@ -57,7 +53,7 @@ Rule sets The rule is part of the following rule sets: @PhpCsFixer - Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``no_alternative_syntax`` rule. + Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``no_alternative_syntax`` rule with the default config. @Symfony - Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``no_alternative_syntax`` rule. + Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``no_alternative_syntax`` rule with the default config. diff --git a/src/Console/WarningsDetector.php b/src/Console/WarningsDetector.php index 9d168ba250b..cc8165a8119 100644 --- a/src/Console/WarningsDetector.php +++ b/src/Console/WarningsDetector.php @@ -41,7 +41,7 @@ public function __construct(ToolInfoInterface $toolInfo) public function detectOldMajor(): void { - // @TODO 3.99 to be activated with new MAJOR release + // @TODO 3.99 to be activated with new MAJOR release 4.0 // $currentMajorVersion = \intval(explode('.', Application::VERSION)[0], 10); // $nextMajorVersion = $currentMajorVersion + 1; // $this->warnings[] = "You are running PHP CS Fixer v{$currentMajorVersion}, which is not maintained anymore. Please update to v{$nextMajorVersion}."; diff --git a/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php b/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php index 0c0c28ad347..38bf6c111e7 100644 --- a/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php +++ b/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php @@ -15,6 +15,10 @@ namespace PhpCsFixer\Fixer\ControlStructure; use PhpCsFixer\AbstractFixer; +use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; +use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; +use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; @@ -24,7 +28,7 @@ /** * @author Eddilbert Macharia */ -final class NoAlternativeSyntaxFixer extends AbstractFixer +final class NoAlternativeSyntaxFixer extends AbstractFixer implements ConfigurableFixerInterface { /** * {@inheritdoc} @@ -38,13 +42,8 @@ public function getDefinition(): FixerDefinitionInterface "\nLorem ipsum.\n\n", + ['fix_non_monolithic_code' => true] ), ] ); @@ -55,7 +54,7 @@ public function getDefinition(): FixerDefinitionInterface */ public function isCandidate(Tokens $tokens): bool { - return $tokens->hasAlternativeSyntax(); + return $tokens->hasAlternativeSyntax() && ($this->configuration['fix_non_monolithic_code'] || $tokens->isMonolithicPhp()); } /** @@ -68,6 +67,19 @@ public function getPriority(): int return 42; } + /** + * {@inheritDoc} + */ + protected function createConfigurationDefinition(): FixerConfigurationResolverInterface + { + return new FixerConfigurationResolver([ + (new FixerOptionBuilder('fix_non_monolithic_code', 'Whether to also fix code with inline HTML.')) + ->setAllowedTypes(['bool']) + ->setDefault(true) // @TODO change to "false" on next major 4.0 + ->getOption(), + ]); + } + /** * {@inheritdoc} */ diff --git a/tests/Fixer/ControlStructure/NoAlternativeSyntaxFixerTest.php b/tests/Fixer/ControlStructure/NoAlternativeSyntaxFixerTest.php index edec3c44c5a..18c0db40722 100644 --- a/tests/Fixer/ControlStructure/NoAlternativeSyntaxFixerTest.php +++ b/tests/Fixer/ControlStructure/NoAlternativeSyntaxFixerTest.php @@ -28,99 +28,150 @@ final class NoAlternativeSyntaxFixerTest extends AbstractFixerTestCase /** * @dataProvider provideFixCases */ - public function testFix(string $expected, ?string $input = null): void + public function testFix(string $expected, ?string $input = null, ?array $configuration = null): void { + if (null !== $configuration) { + $this->fixer->configure($configuration); + } + $this->doTest($expected, $input); } - public function provideFixCases(): array + public function provideFixCases(): \Generator { - return [ - [ - '', - '', - ], - [ - '', + '', + ]; + + yield [ + '

This is visible.

', + '

This is visible.

', + ]; + + yield [ + '

This is visible.

', + null, + ['fix_non_monolithic_code' => false], + ]; + + yield [ + 'Text display.', + 'Text display.', + ['fix_non_monolithic_code' => true], + ]; + + yield [ + 'Text display.', + null, + ['fix_non_monolithic_code' => false], + ]; + + yield [ + '', + '', + ['fix_non_monolithic_code' => true], + ]; + + yield [ + '', + null, + ['fix_non_monolithic_code' => false], ]; } } From d33c35614bbf6c4deb584c6c7b49024be4f04810 Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Sun, 5 Sep 2021 14:43:36 +0200 Subject: [PATCH 57/80] Fix STDIN test when path is one level deep --- tests/Smoke/StdinTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Smoke/StdinTest.php b/tests/Smoke/StdinTest.php index 9ac0e51dafb..01b5362f568 100644 --- a/tests/Smoke/StdinTest.php +++ b/tests/Smoke/StdinTest.php @@ -15,6 +15,7 @@ namespace PhpCsFixer\Tests\Smoke; use Keradus\CliExecutor\CommandExecutor; +use PhpCsFixer\Preg; /** * @author Dariusz RumiƄski @@ -45,6 +46,7 @@ public function testFixingStdin(): void '', $fileResult->getError() ); + static::assertSame($expectedError, $stdinResult->getError()); $fileResult = $this->unifyFooter($fileResult->getOutput()); @@ -55,7 +57,11 @@ public function testFixingStdin(): void $fileResult = str_replace("\n+++ ".$path."\n", "\n+++ php://stdin\n", $fileResult); $path = str_replace('/', \DIRECTORY_SEPARATOR, basename(realpath($cwd)).'/'.$inputFile); - $fileResult = str_replace($path, 'php://stdin', $fileResult); + $fileResult = Preg::replace( + '#/?'.preg_quote($path, '#').'#', + 'php://stdin', + $fileResult + ); static::assertSame( $fileResult, From 9d584d9909e5a4f3d0931c98ebcadab9c3b4d7dd Mon Sep 17 00:00:00 2001 From: Julien Falque Date: Sun, 5 Sep 2021 16:31:31 +0200 Subject: [PATCH 58/80] Remove duplicated method --- ...trolStructureContinuationPositionFixer.php | 32 ++----------------- 1 file changed, 2 insertions(+), 30 deletions(-) diff --git a/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php b/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php index 563ba65bd91..dd3088b0c01 100644 --- a/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php +++ b/src/Fixer/ControlStructure/ControlStructureContinuationPositionFixer.php @@ -23,6 +23,7 @@ use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\Analyzer\WhitespacesAnalyzer; use PhpCsFixer\Tokenizer\Tokens; final class ControlStructureContinuationPositionFixer extends AbstractFixer implements ConfigurableFixerInterface, WhitespacesAwareFixerInterface @@ -135,38 +136,9 @@ private function fixControlContinuationBraces(Tokens $tokens): void $index - 1, 1, self::NEXT_LINE === $this->configuration['position'] ? - $this->whitespacesConfig->getLineEnding().$this->detectIndent($tokens, $index) + $this->whitespacesConfig->getLineEnding().WhitespacesAnalyzer::detectIndent($tokens, $index) : ' ' ); } } - - private function detectIndent(Tokens $tokens, int $index): string - { - while (true) { - $whitespaceIndex = $tokens->getPrevTokenOfKind($index, [[T_WHITESPACE]]); - - if (null === $whitespaceIndex) { - return ''; - } - - $whitespaceToken = $tokens[$whitespaceIndex]; - - if (false !== strpos($whitespaceToken->getContent(), "\n")) { - break; - } - - $prevToken = $tokens[$whitespaceIndex - 1]; - - if ($prevToken->isGivenKind([T_OPEN_TAG, T_COMMENT]) && "\n" === substr($prevToken->getContent(), -1)) { - break; - } - - $index = $whitespaceIndex; - } - - $explodedContent = explode("\n", $whitespaceToken->getContent()); - - return end($explodedContent); - } } From 955178fbc25359a31bed54393aee6c59213a5d2e Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Sun, 5 Sep 2021 15:29:34 +0200 Subject: [PATCH 59/80] EmptyLoopConditionFixer - add space when fixing, add rule to SymfonySet --- doc/ruleSets/Symfony.rst | 1 + .../control_structure/empty_loop_condition.rst | 15 +++++++++++++-- .../ClassAttributesSeparationFixer.php | 4 ++-- .../ControlStructure/EmptyLoopConditionFixer.php | 2 +- .../SwitchContinueToBreakFixer.php | 4 ++-- .../Phpdoc/PhpdocReturnSelfReferenceFixer.php | 4 ++-- .../ReturnNotation/ReturnAssignmentFixer.php | 4 ++-- src/RuleSet/Sets/SymfonySet.php | 1 + .../EmptyLoopConditionFixerTest.php | 14 +++++++------- ...empty_loop_condition,no_extra_blank_lines.test | 2 +- ...pty_loop_condition,no_trailing_whitespace.test | 2 +- 11 files changed, 33 insertions(+), 20 deletions(-) diff --git a/doc/ruleSets/Symfony.rst b/doc/ruleSets/Symfony.rst index 4be545f8dd1..73ddf3ca5de 100644 --- a/doc/ruleSets/Symfony.rst +++ b/doc/ruleSets/Symfony.rst @@ -30,6 +30,7 @@ Rules - `empty_loop_body <./../rules/control_structure/empty_loop_body.rst>`_ config: ``['style' => 'braces']`` +- `empty_loop_condition <./../rules/control_structure/empty_loop_condition.rst>`_ - `fully_qualified_strict_types <./../rules/import/fully_qualified_strict_types.rst>`_ - `function_typehint_space <./../rules/function_notation/function_typehint_space.rst>`_ - `general_phpdoc_tag_rename <./../rules/phpdoc/general_phpdoc_tag_rename.rst>`_ diff --git a/doc/rules/control_structure/empty_loop_condition.rst b/doc/rules/control_structure/empty_loop_condition.rst index 024bfc80d51..86bd5bf9d9b 100644 --- a/doc/rules/control_structure/empty_loop_condition.rst +++ b/doc/rules/control_structure/empty_loop_condition.rst @@ -30,12 +30,12 @@ Example #1 +++ New 'for']``. +for(;;) { foo(); } + +Rule sets +--------- + +The rule is part of the following rule sets: + +@PhpCsFixer + Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``empty_loop_condition`` rule with the default config. + +@Symfony + Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``empty_loop_condition`` rule with the default config. diff --git a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php index ff389d21df9..7e50ba1e10a 100644 --- a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php +++ b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php @@ -553,7 +553,7 @@ private function getLastTokenIndexOfClassElement(Tokens $tokens, array $class, a } if ($singleLineElement) { - do { + while (true) { $nextToken = $tokens[$elementEndIndex + 1]; if (($nextToken->isComment() || $nextToken->isWhitespace()) && false === strpos($nextToken->getContent(), "\n")) { @@ -561,7 +561,7 @@ private function getLastTokenIndexOfClassElement(Tokens $tokens, array $class, a } else { break; } - } while (true); + } if ($tokens[$elementEndIndex]->isWhitespace()) { $elementEndIndex = $tokens->getPrevNonWhitespace($elementEndIndex); diff --git a/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php b/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php index 8d7a9f2a167..71ca6ce286a 100644 --- a/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php +++ b/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php @@ -75,7 +75,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { if (self::STYLE_WHILE === $this->configuration['style']) { $candidateLoopKinds = [T_FOR, T_WHILE]; - $replacement = [new Token([T_WHILE, 'while']), new Token('('), new Token([T_STRING, 'true']), new Token(')')]; + $replacement = [new Token([T_WHILE, 'while']), new Token([T_WHITESPACE, ' ']), new Token('('), new Token([T_STRING, 'true']), new Token(')')]; $fixLoop = static function (int $index, int $openIndex, int $endIndex) use ($tokens, $replacement): void { if (self::isForLoopWithEmptyCondition($tokens, $index, $openIndex, $endIndex)) { diff --git a/src/Fixer/ControlStructure/SwitchContinueToBreakFixer.php b/src/Fixer/ControlStructure/SwitchContinueToBreakFixer.php index b8db6a50c1a..c929c983052 100644 --- a/src/Fixer/ControlStructure/SwitchContinueToBreakFixer.php +++ b/src/Fixer/ControlStructure/SwitchContinueToBreakFixer.php @@ -152,7 +152,7 @@ private function fixInLoop(Tokens $tokens, int $openIndex, int $depth): int { $openCount = 1; - do { + while (true) { ++$openIndex; $token = $tokens[$openIndex]; @@ -173,7 +173,7 @@ private function fixInLoop(Tokens $tokens, int $openIndex, int $depth): int } $openIndex = $this->doFix($tokens, $openIndex, $depth, false); - } while (true); + } return $openIndex; } diff --git a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php index a30e42022e0..2d959099195 100644 --- a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php +++ b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php @@ -185,14 +185,14 @@ private function fixMethod(Tokens $tokens, int $index): void static $methodModifiers = [T_STATIC, T_FINAL, T_ABSTRACT, T_PRIVATE, T_PROTECTED, T_PUBLIC]; // find PHPDoc of method (if any) - do { + while (true) { $tokenIndex = $tokens->getPrevMeaningfulToken($index); if (!$tokens[$tokenIndex]->isGivenKind($methodModifiers)) { break; } $index = $tokenIndex; - } while (true); + } $docIndex = $tokens->getPrevNonWhitespace($index); if (!$tokens[$docIndex]->isGivenKind(T_DOC_COMMENT)) { diff --git a/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php b/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php index 8f07b84b700..143d6007f1c 100644 --- a/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php +++ b/src/Fixer/ReturnNotation/ReturnAssignmentFixer.php @@ -228,7 +228,7 @@ private function fixFunction(Tokens $tokens, int $functionIndex, int $functionOp } // Note: here we are @ "; return $a;" (or "; return $a ? >") - do { + while (true) { $prevMeaningFul = $tokens->getPrevMeaningfulToken($assignVarEndIndex); if (!$tokens[$prevMeaningFul]->equals(')')) { @@ -236,7 +236,7 @@ private function fixFunction(Tokens $tokens, int $functionIndex, int $functionOp } $assignVarEndIndex = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $prevMeaningFul); - } while (true); + } $assignVarOperatorIndex = $tokens->getPrevTokenOfKind( $assignVarEndIndex, diff --git a/src/RuleSet/Sets/SymfonySet.php b/src/RuleSet/Sets/SymfonySet.php index 608cc6e9e26..635f64d0125 100644 --- a/src/RuleSet/Sets/SymfonySet.php +++ b/src/RuleSet/Sets/SymfonySet.php @@ -50,6 +50,7 @@ public function getRules(): array 'concat_space' => true, 'echo_tag_syntax' => true, 'empty_loop_body' => ['style' => 'braces'], + 'empty_loop_condition' => true, 'fully_qualified_strict_types' => true, 'function_typehint_space' => true, 'general_phpdoc_tag_rename' => [ diff --git a/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php b/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php index 890b8e228fd..e1e6877bc39 100644 --- a/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php +++ b/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php @@ -41,7 +41,7 @@ public function provideFixCases(): \Generator { yield 'from `for` to `while`' => [ ' [ - ' [ - ' [ - ' [ - ' [ - ' Date: Sun, 5 Sep 2021 21:53:08 +0200 Subject: [PATCH 60/80] DX: extract config for special CI jobs --- .github/workflows/ci.yml | 8 +++--- .php-cs-fixer.php-highest.php | 26 +++++++++++++++++++ ...0types.php => .php-cs-fixer.php-lowest.php | 6 +++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 .php-cs-fixer.php-highest.php rename .php-cs-fixer.php70types.php => .php-cs-fixer.php-lowest.php (70%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 88e7955db15..2a1338ae581 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -111,7 +111,7 @@ jobs: - name: Execute migration rules if: matrix.execute-migration-rules == 'yes' - run: php php-cs-fixer fix --rules @PHP80Migration,@PHP80Migration:risky -q + run: php php-cs-fixer fix --config .php-cs-fixer.php-highest.php -q - name: Disable time limit for tests when collecting coverage if: matrix.calculate-code-coverage == 'yes' @@ -129,9 +129,9 @@ jobs: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: php vendor/bin/php-coveralls --verbose - - name: Run PHP CS Fixer for PHP 7.0 types - if: matrix.php-version == '7.1' # we run on lowest supported version, we running it on higher would falsy expect more changes, eg `mixed` type on PHP 8 - run: php php-cs-fixer fix --diff --dry-run -v --config .php-cs-fixer.php70types.php + - name: Run PHP CS Fixer for PHP 7.1 types + if: matrix.php-version == '7.1' # we run on lowest supported version, running it on higher would falsy expect more changes, eg `mixed` type on PHP 8 + run: php php-cs-fixer fix --diff --dry-run -v --config .php-cs-fixer.php-lowest.php - name: Run PHP CS Fixer env: diff --git a/.php-cs-fixer.php-highest.php b/.php-cs-fixer.php-highest.php new file mode 100644 index 00000000000..0f01a1872c0 --- /dev/null +++ b/.php-cs-fixer.php-highest.php @@ -0,0 +1,26 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +if (PHP_VERSION_ID <= 80001 || PHP_VERSION_ID >= 80100) { + fwrite(STDERR, "PHP CS Fixer's config for PHP-HIGHEST can be executed only on highest supported PHP version - 8.0.*.\n"); + fwrite(STDERR, "Running it on lower PHP version would prevent calling migration rules.\n"); + exit(1); +} + +$config = require '.php-cs-fixer.dist.php'; + +$config->setRules([ + '@PHP80Migration' => true, + '@PHP80Migration:risky' => true, +]); + +return $config; diff --git a/.php-cs-fixer.php70types.php b/.php-cs-fixer.php-lowest.php similarity index 70% rename from .php-cs-fixer.php70types.php rename to .php-cs-fixer.php-lowest.php index f8e0a0115f6..3d914f59083 100644 --- a/.php-cs-fixer.php70types.php +++ b/.php-cs-fixer.php-lowest.php @@ -10,6 +10,12 @@ * with this source code in the file LICENSE. */ +if (PHP_VERSION_ID <= 70103 || PHP_VERSION_ID >= 70200) { + fwrite(STDERR, "PHP CS Fixer's config for PHP-LOWEST can be executed only on lowest supported PHP version - 7.1.*.\n"); + fwrite(STDERR, "Running it on higher PHP version would falsy expect more changes, eg `mixed` type on PHP 8.\n"); + exit(1); +} + $config = require '.php-cs-fixer.dist.php'; $config->getFinder()->notPath([ From 2ca22a27c4ffb8cc46f20e7110b1dfcbb0c8c47c Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 30 May 2021 13:48:29 +0200 Subject: [PATCH 61/80] Add ModernizeStrposFixer --- doc/ruleSets/PHP80MigrationRisky.rst | 1 + doc/rules/alias/modernize_strpos.rst | 61 +++++++ doc/rules/index.rst | 2 + src/Fixer/Alias/ModernizeStrposFixer.php | 153 ++++++++++++++++++ src/RuleSet/Sets/PHP80MigrationRiskySet.php | 1 + .../Fixer/Alias/ModernizeStrposFixerTest.php | 55 +++++++ 6 files changed, 273 insertions(+) create mode 100644 doc/rules/alias/modernize_strpos.rst create mode 100644 src/Fixer/Alias/ModernizeStrposFixer.php create mode 100644 tests/Fixer/Alias/ModernizeStrposFixerTest.php diff --git a/doc/ruleSets/PHP80MigrationRisky.rst b/doc/ruleSets/PHP80MigrationRisky.rst index 6942647a890..d5b9f874b87 100644 --- a/doc/ruleSets/PHP80MigrationRisky.rst +++ b/doc/ruleSets/PHP80MigrationRisky.rst @@ -8,6 +8,7 @@ Rules ----- - `@PHP74Migration:risky <./PHP74MigrationRisky.rst>`_ +- `modernize_strpos <./../rules/alias/modernize_strpos.rst>`_ - `no_alias_functions <./../rules/alias/no_alias_functions.rst>`_ config: ``['sets' => ['@all']]`` diff --git a/doc/rules/alias/modernize_strpos.rst b/doc/rules/alias/modernize_strpos.rst new file mode 100644 index 00000000000..82886195faa --- /dev/null +++ b/doc/rules/alias/modernize_strpos.rst @@ -0,0 +1,61 @@ +========================= +Rule ``modernize_strpos`` +========================= + +Replace ``strpos()`` expressions with ``str_starts_with()`` or +``str_contains()`` if possible. + +.. warning:: Using this rule is risky. + + Risky if the ``strpos`` function is overridden. + +Examples +-------- + +Example #1 +~~~~~~~~~~ + +.. code-block:: diff + + --- Original + +++ New + -`_ rule set will enable the ``modernize_strpos`` rule. diff --git a/doc/rules/index.rst b/doc/rules/index.rst index 737ad1edb0b..7367f3dba1f 100644 --- a/doc/rules/index.rst +++ b/doc/rules/index.rst @@ -13,6 +13,8 @@ Alias Replace deprecated ``ereg`` regular expression functions with ``preg``. - `mb_str_functions <./alias/mb_str_functions.rst>`_ *(risky)* Replace non multibyte-safe functions with corresponding mb function. +- `modernize_strpos <./alias/modernize_strpos.rst>`_ *(risky)* + Replace ``strpos()`` expressions with ``str_starts_with()`` or ``str_contains()`` if possible. - `no_alias_functions <./alias/no_alias_functions.rst>`_ *(risky)* Master functions shall be used instead of aliases. - `no_alias_language_construct_call <./alias/no_alias_language_construct_call.rst>`_ diff --git a/src/Fixer/Alias/ModernizeStrposFixer.php b/src/Fixer/Alias/ModernizeStrposFixer.php new file mode 100644 index 00000000000..23333db7f52 --- /dev/null +++ b/src/Fixer/Alias/ModernizeStrposFixer.php @@ -0,0 +1,153 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Fixer\Alias; + +use PhpCsFixer\AbstractFixer; +use PhpCsFixer\FixerDefinition\CodeSample; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\Token; +use PhpCsFixer\Tokenizer\Tokens; + +/** + * @author Alexander M. Turek + */ +final class ModernizeStrposFixer extends AbstractFixer +{ + private const REPLACEMENTS = [ + [ + 'operator' => [T_IS_IDENTICAL, '==='], + 'operand' => [T_LNUMBER, '0'], + 'replacement' => [T_STRING, 'str_starts_with'], + 'negate' => false, + ], + [ + 'operator' => [T_IS_NOT_IDENTICAL, '!=='], + 'operand' => [T_LNUMBER, '0'], + 'replacement' => [T_STRING, 'str_starts_with'], + 'negate' => true, + ], + [ + 'operator' => [T_IS_NOT_IDENTICAL, '!=='], + 'operand' => [T_STRING, 'false'], + 'replacement' => [T_STRING, 'str_contains'], + 'negate' => false, + ], + [ + 'operator' => [T_IS_IDENTICAL, '==='], + 'operand' => [T_STRING, 'false'], + 'replacement' => [T_STRING, 'str_contains'], + 'negate' => true, + ], + ]; + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition( + 'Replace `strpos()` expressions with `str_starts_with()` or `str_contains()` if possible.', + [ + new CodeSample("isTokenKindFound(T_STRING); + } + + public function isRisky(): bool + { + return true; + } + + protected function applyFix(\SplFileInfo $file, Tokens $tokens): void + { + $seq = [[T_STRING, 'strpos'], '(']; + + $currIndex = 0; + while (null !== $currIndex) { + $match = $tokens->findSequence($seq, $currIndex, null, false); + if (null === $match) { + break; + } + + [$functionPos, $argumentsStart] = array_keys($match); + $currIndex = $argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $argumentsStart); + + $operatorPos = $tokens->getNextMeaningfulToken($argumentsEnd); + $operandPos = $tokens->getNextMeaningfulToken($operatorPos); + + foreach (self::REPLACEMENTS as [ + 'operator' => $operator, + 'operand' => $operand, + 'replacement' => $replacement, + 'negate' => $negate, + ]) { + if (!$tokens[$operatorPos]->equals($operator) || !$tokens[$operandPos]->equals($operand)) { + continue; + } + + for ($i = $argumentsEnd + 1; $i <= $operandPos; ++$i) { + $tokens[$i] = new Token(''); + } + $tokens[$functionPos] = new Token($replacement); + + if ($negate) { + for ($i = $argumentsEnd; $i >= $functionPos; --$i) { + $token = $tokens[$i]; + \assert(null !== $token); + $tokens[$i + 1] = $token; + } + $tokens[$functionPos] = new Token('!'); + } + + continue 2; + } + + $operatorPos = $tokens->getPrevMeaningfulToken($functionPos); + $operandPos = $tokens->getPrevMeaningfulToken($operatorPos); + + foreach (self::REPLACEMENTS as [ + 'operator' => $operator, + 'operand' => $operand, + 'replacement' => $replacement, + 'negate' => $negate, + ]) { + if (!$tokens[$operatorPos]->equals($operator) || !$tokens[$operandPos]->equals($operand)) { + continue; + } + + for ($i = $functionPos - 1; $i >= $operandPos; --$i) { + $tokens[$i] = new Token(''); + } + $tokens[$functionPos] = new Token($replacement); + + if ($negate) { + $tokens[$functionPos - 1] = new Token('!'); + } + + continue 2; + } + } + + $tokens->clearEmptyTokens(); + } +} diff --git a/src/RuleSet/Sets/PHP80MigrationRiskySet.php b/src/RuleSet/Sets/PHP80MigrationRiskySet.php index ab244cd1047..23970d6ffbf 100644 --- a/src/RuleSet/Sets/PHP80MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHP80MigrationRiskySet.php @@ -25,6 +25,7 @@ public function getRules(): array { return [ '@PHP74Migration:risky' => true, + 'modernize_strpos' => true, 'no_alias_functions' => [ 'sets' => [ '@all', diff --git a/tests/Fixer/Alias/ModernizeStrposFixerTest.php b/tests/Fixer/Alias/ModernizeStrposFixerTest.php new file mode 100644 index 00000000000..aecae38602f --- /dev/null +++ b/tests/Fixer/Alias/ModernizeStrposFixerTest.php @@ -0,0 +1,55 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Fixer\Alias; + +use PhpCsFixer\Tests\Test\AbstractFixerTestCase; + +/** + * @author Alexander M. Turek + * + * @internal + * + * @covers \PhpCsFixer\Fixer\Alias\ModernizeStrposFixer + */ +final class ModernizeStrposFixerTest extends AbstractFixerTestCase +{ + /** + * @dataProvider provideFixCases + */ + public function testFix(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFixCases(): array + { + return [ + [' 0) {}'], + + [' Date: Tue, 31 Aug 2021 16:06:43 +0200 Subject: [PATCH 62/80] ModernizeStrposFixer - tweaks --- doc/rules/alias/modernize_strpos.rst | 48 ++--- doc/rules/index.rst | 2 +- src/Fixer/Alias/ModernizeStrposFixer.php | 200 ++++++++++++------ .../SingleSpaceAfterConstructFixer.php | 1 + .../Operator/BinaryOperatorSpacesFixer.php | 2 +- .../Operator/NotOperatorWithSpaceFixer.php | 2 +- .../NotOperatorWithSuccessorSpaceFixer.php | 2 +- .../Whitespace/NoExtraBlankLinesFixer.php | 2 +- .../NoSpacesInsideParenthesisFixer.php | 2 +- .../Whitespace/NoTrailingWhitespaceFixer.php | 2 +- tests/AutoReview/FixerFactoryTest.php | 7 + .../Fixer/Alias/ModernizeStrposFixerTest.php | 148 +++++++++++-- ...dernize_strpos,binary_operator_spaces.test | 11 + ...modernize_strpos,no_extra_blank_lines.test | 16 ++ ...e_strpos,no_spaces_inside_parenthesis.test | 11 + ...dernize_strpos,no_trailing_whitespace.test | 13 ++ ...ernize_strpos,not_operator_with_space.test | 11 + ...pos,not_operator_with_successor_space.test | 11 + ...e_strpos,single_space_after_construct.test | 17 ++ 19 files changed, 382 insertions(+), 126 deletions(-) create mode 100644 tests/Fixtures/Integration/priority/modernize_strpos,binary_operator_spaces.test create mode 100644 tests/Fixtures/Integration/priority/modernize_strpos,no_extra_blank_lines.test create mode 100644 tests/Fixtures/Integration/priority/modernize_strpos,no_spaces_inside_parenthesis.test create mode 100644 tests/Fixtures/Integration/priority/modernize_strpos,no_trailing_whitespace.test create mode 100644 tests/Fixtures/Integration/priority/modernize_strpos,not_operator_with_space.test create mode 100644 tests/Fixtures/Integration/priority/modernize_strpos,not_operator_with_successor_space.test create mode 100644 tests/Fixtures/Integration/priority/modernize_strpos,single_space_after_construct.test diff --git a/doc/rules/alias/modernize_strpos.rst b/doc/rules/alias/modernize_strpos.rst index 82886195faa..51f270a3d7f 100644 --- a/doc/rules/alias/modernize_strpos.rst +++ b/doc/rules/alias/modernize_strpos.rst @@ -2,12 +2,13 @@ Rule ``modernize_strpos`` ========================= -Replace ``strpos()`` expressions with ``str_starts_with()`` or -``str_contains()`` if possible. +Replace ``strpos()`` calls with ``str_starts_with()`` or ``str_contains()`` if +possible. .. warning:: Using this rule is risky. - Risky if the ``strpos`` function is overridden. + Risky if ``strpos``, ``str_starts_with`` or ``str_contains`` functions are + overridden. Examples -------- @@ -19,38 +20,15 @@ Example #1 --- Original +++ New - -`_ *(risky)* Replace non multibyte-safe functions with corresponding mb function. - `modernize_strpos <./alias/modernize_strpos.rst>`_ *(risky)* - Replace ``strpos()`` expressions with ``str_starts_with()`` or ``str_contains()`` if possible. + Replace ``strpos()`` calls with ``str_starts_with()`` or ``str_contains()`` if possible. - `no_alias_functions <./alias/no_alias_functions.rst>`_ *(risky)* Master functions shall be used instead of aliases. - `no_alias_language_construct_call <./alias/no_alias_language_construct_call.rst>`_ diff --git a/src/Fixer/Alias/ModernizeStrposFixer.php b/src/Fixer/Alias/ModernizeStrposFixer.php index 23333db7f52..aee4ea76747 100644 --- a/src/Fixer/Alias/ModernizeStrposFixer.php +++ b/src/Fixer/Alias/ModernizeStrposFixer.php @@ -18,6 +18,8 @@ use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\Analyzer\ArgumentsAnalyzer; +use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -56,21 +58,35 @@ final class ModernizeStrposFixer extends AbstractFixer public function getDefinition(): FixerDefinitionInterface { return new FixerDefinition( - 'Replace `strpos()` expressions with `str_starts_with()` or `str_contains()` if possible.', + 'Replace `strpos()` calls with `str_starts_with()` or `str_contains()` if possible.', [ - new CodeSample("isTokenKindFound(T_STRING); + return $tokens->isTokenKindFound(T_STRING) && $tokens->isAnyTokenKindsFound([T_IS_IDENTICAL, T_IS_NOT_IDENTICAL]); } public function isRisky(): bool @@ -80,74 +96,122 @@ public function isRisky(): bool protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { - $seq = [[T_STRING, 'strpos'], '(']; + $functionsAnalyzer = new FunctionsAnalyzer(); + $argumentsAnalyzer = new ArgumentsAnalyzer(); + + for ($index = \count($tokens) - 1; $index > 0; --$index) { + // find candidate function call + if (!$tokens[$index]->equals([T_STRING, 'strpos'], false) || !$functionsAnalyzer->isGlobalFunctionCall($tokens, $index)) { + continue; + } - $currIndex = 0; - while (null !== $currIndex) { - $match = $tokens->findSequence($seq, $currIndex, null, false); - if (null === $match) { - break; + // assert called with 2 arguments + $openIndex = $tokens->getNextMeaningfulToken($index); + $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex); + $arguments = $argumentsAnalyzer->getArguments($tokens, $openIndex, $closeIndex); + + if (2 !== \count($arguments)) { + continue; } - [$functionPos, $argumentsStart] = array_keys($match); - $currIndex = $argumentsEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $argumentsStart); - - $operatorPos = $tokens->getNextMeaningfulToken($argumentsEnd); - $operandPos = $tokens->getNextMeaningfulToken($operatorPos); - - foreach (self::REPLACEMENTS as [ - 'operator' => $operator, - 'operand' => $operand, - 'replacement' => $replacement, - 'negate' => $negate, - ]) { - if (!$tokens[$operatorPos]->equals($operator) || !$tokens[$operandPos]->equals($operand)) { - continue; - } - - for ($i = $argumentsEnd + 1; $i <= $operandPos; ++$i) { - $tokens[$i] = new Token(''); - } - $tokens[$functionPos] = new Token($replacement); - - if ($negate) { - for ($i = $argumentsEnd; $i >= $functionPos; --$i) { - $token = $tokens[$i]; - \assert(null !== $token); - $tokens[$i + 1] = $token; - } - $tokens[$functionPos] = new Token('!'); - } - - continue 2; + // check if part condition and fix if needed + $compareTokens = $this->getCompareTokens($tokens, $index, -1); // look behind + + if (null === $compareTokens) { + $compareTokens = $this->getCompareTokens($tokens, $closeIndex, 1); // look ahead } - $operatorPos = $tokens->getPrevMeaningfulToken($functionPos); - $operandPos = $tokens->getPrevMeaningfulToken($operatorPos); - - foreach (self::REPLACEMENTS as [ - 'operator' => $operator, - 'operand' => $operand, - 'replacement' => $replacement, - 'negate' => $negate, - ]) { - if (!$tokens[$operatorPos]->equals($operator) || !$tokens[$operandPos]->equals($operand)) { - continue; - } - - for ($i = $functionPos - 1; $i >= $operandPos; --$i) { - $tokens[$i] = new Token(''); - } - $tokens[$functionPos] = new Token($replacement); - - if ($negate) { - $tokens[$functionPos - 1] = new Token('!'); - } - - continue 2; + if (null !== $compareTokens) { + $this->fixCall($tokens, $index, $compareTokens); } } + } + + private function fixCall(Tokens $tokens, int $functionIndex, array $operatorIndexes): void + { + foreach (self::REPLACEMENTS as $replacement) { + if (!$tokens[$operatorIndexes['operator_index']]->equals($replacement['operator'])) { + continue; + } + + if (!$tokens[$operatorIndexes['operand_index']]->equals($replacement['operand'], false)) { + continue; + } + + $tokens->clearTokenAndMergeSurroundingWhitespace($operatorIndexes['operator_index']); + $tokens->clearTokenAndMergeSurroundingWhitespace($operatorIndexes['operand_index']); + $tokens->clearTokenAndMergeSurroundingWhitespace($functionIndex); + + if ($replacement['negate']) { + $tokens->insertAt($functionIndex, new Token('!')); + ++$functionIndex; + } + + $tokens->insertAt($functionIndex, new Token($replacement['replacement'])); + + break; + } + } + + private function getCompareTokens(Tokens $tokens, int $offsetIndex, int $direction): ?array + { + $operatorIndex = $tokens->getMeaningfulTokenSibling($offsetIndex, $direction); + + if (null === $operatorIndex) { + return null; + } - $tokens->clearEmptyTokens(); + $operandIndex = $tokens->getMeaningfulTokenSibling($operatorIndex, $direction); + + if (null === $operandIndex) { + return null; + } + + $operand = $tokens[$operandIndex]; + + if (!$operand->equals([T_LNUMBER, '0']) && !$operand->equals([T_STRING, 'false'], false)) { + return null; + } + + if (!$tokens[$operatorIndex]->isGivenKind([T_IS_IDENTICAL, T_IS_NOT_IDENTICAL])) { + return null; + } + + $precedenceTokenIndex = $tokens->getMeaningfulTokenSibling($operandIndex, $direction); + + if (null !== $precedenceTokenIndex && $this->isOfHigherPrecedence($tokens[$precedenceTokenIndex])) { + return null; + } + + return ['operator_index' => $operatorIndex, 'operand_index' => $operandIndex]; + } + + private function isOfHigherPrecedence(Token $token): bool + { + static $operatorsPerId = [ + T_DEC => true, // -- + T_INC => true, // ++ + T_INSTANCEOF => true, // instanceof + T_IS_GREATER_OR_EQUAL => true, // >= + T_IS_SMALLER_OR_EQUAL => true, // <= + T_POW => true, // ** + T_SL => true, // << + T_SR => true, // >> + ]; + + static $operatorsPerContent = [ + '!', + '%', + '*', + '+', + '-', + '.', + '/', + '<', + '>', + '~', + ]; + + return isset($operatorsPerId[$token->getId()]) || $token->equalsAny($operatorsPerContent); } } diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index c71f9374c56..74647457063 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -176,6 +176,7 @@ public function getDefinition(): FixerDefinitionInterface * {@inheritdoc} * * Must run before BracesFixer, FunctionDeclarationFixer. + * Must run after ModernizeStrposFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php index 55962f8534e..2a8f49ec9b9 100644 --- a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php +++ b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php @@ -253,7 +253,7 @@ public function getDefinition(): FixerDefinitionInterface /** * {@inheritdoc} * - * Must run after ArrayIndentationFixer, ArraySyntaxFixer, ListSyntaxFixer, NoMultilineWhitespaceAroundDoubleArrowFixer, NoUnsetCastFixer, PowToExponentiationFixer, StandardizeNotEqualsFixer, StrictComparisonFixer. + * Must run after ArrayIndentationFixer, ArraySyntaxFixer, ListSyntaxFixer, ModernizeStrposFixer, NoMultilineWhitespaceAroundDoubleArrowFixer, NoUnsetCastFixer, PowToExponentiationFixer, StandardizeNotEqualsFixer, StrictComparisonFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Operator/NotOperatorWithSpaceFixer.php b/src/Fixer/Operator/NotOperatorWithSpaceFixer.php index 84313560468..83c5cf55099 100644 --- a/src/Fixer/Operator/NotOperatorWithSpaceFixer.php +++ b/src/Fixer/Operator/NotOperatorWithSpaceFixer.php @@ -47,7 +47,7 @@ public function getDefinition(): FixerDefinitionInterface /** * {@inheritdoc} * - * Must run after UnaryOperatorSpacesFixer. + * Must run after ModernizeStrposFixer, UnaryOperatorSpacesFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Operator/NotOperatorWithSuccessorSpaceFixer.php b/src/Fixer/Operator/NotOperatorWithSuccessorSpaceFixer.php index ca10dc4eaf0..acdf0b3dcc8 100644 --- a/src/Fixer/Operator/NotOperatorWithSuccessorSpaceFixer.php +++ b/src/Fixer/Operator/NotOperatorWithSuccessorSpaceFixer.php @@ -47,7 +47,7 @@ public function getDefinition(): FixerDefinitionInterface /** * {@inheritdoc} * - * Must run after UnaryOperatorSpacesFixer. + * Must run after ModernizeStrposFixer, UnaryOperatorSpacesFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php index 9382c58b29a..403ddcdaa86 100644 --- a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php +++ b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php @@ -271,7 +271,7 @@ class Bar * {@inheritdoc} * * Must run before BlankLineBeforeStatementFixer. - * Must run after ClassAttributesSeparationFixer, CombineConsecutiveUnsetsFixer, EmptyLoopBodyFixer, EmptyLoopConditionFixer, FunctionToConstantFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoEmptyStatementFixer, NoUnusedImportsFixer, NoUselessElseFixer, NoUselessReturnFixer, NoUselessSprintfFixer. + * Must run after ClassAttributesSeparationFixer, CombineConsecutiveUnsetsFixer, EmptyLoopBodyFixer, EmptyLoopConditionFixer, FunctionToConstantFixer, ModernizeStrposFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoEmptyStatementFixer, NoUnusedImportsFixer, NoUselessElseFixer, NoUselessReturnFixer, NoUselessSprintfFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php b/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php index 3511d3aad1a..0ce81c19f1d 100644 --- a/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php +++ b/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php @@ -51,7 +51,7 @@ function foo( \$bar, \$baz ) * {@inheritdoc} * * Must run before FunctionToConstantFixer. - * Must run after CombineConsecutiveIssetsFixer, CombineNestedDirnameFixer, LambdaNotUsedImportFixer, NoUselessSprintfFixer, PowToExponentiationFixer. + * Must run after CombineConsecutiveIssetsFixer, CombineNestedDirnameFixer, LambdaNotUsedImportFixer, ModernizeStrposFixer, NoUselessSprintfFixer, PowToExponentiationFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php b/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php index e9ac58eee84..05a4f429690 100644 --- a/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php +++ b/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php @@ -46,7 +46,7 @@ public function getDefinition(): FixerDefinitionInterface /** * {@inheritdoc} * - * Must run after CombineConsecutiveIssetsFixer, CombineConsecutiveUnsetsFixer, EmptyLoopBodyFixer, EmptyLoopConditionFixer, FunctionToConstantFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoEmptyStatementFixer, NoUnneededControlParenthesesFixer, NoUselessElseFixer, TernaryToElvisOperatorFixer. + * Must run after CombineConsecutiveIssetsFixer, CombineConsecutiveUnsetsFixer, EmptyLoopBodyFixer, EmptyLoopConditionFixer, FunctionToConstantFixer, ModernizeStrposFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoEmptyStatementFixer, NoUnneededControlParenthesesFixer, NoUselessElseFixer, TernaryToElvisOperatorFixer. */ public function getPriority(): int { diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index aa6406f4462..17437b7409f 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -135,6 +135,13 @@ public function provideFixersPriorityCases() [$fixers['method_argument_space'], $fixers['array_indentation']], [$fixers['method_chaining_indentation'], $fixers['array_indentation']], [$fixers['method_chaining_indentation'], $fixers['method_argument_space']], + [$fixers['modernize_strpos'], $fixers['binary_operator_spaces']], + [$fixers['modernize_strpos'], $fixers['no_extra_blank_lines']], + [$fixers['modernize_strpos'], $fixers['no_spaces_inside_parenthesis']], + [$fixers['modernize_strpos'], $fixers['no_trailing_whitespace']], + [$fixers['modernize_strpos'], $fixers['not_operator_with_space']], + [$fixers['modernize_strpos'], $fixers['not_operator_with_successor_space']], + [$fixers['modernize_strpos'], $fixers['single_space_after_construct']], [$fixers['multiline_whitespace_before_semicolons'], $fixers['space_after_semicolon']], [$fixers['native_constant_invocation'], $fixers['global_namespace_import']], [$fixers['native_function_invocation'], $fixers['global_namespace_import']], diff --git a/tests/Fixer/Alias/ModernizeStrposFixerTest.php b/tests/Fixer/Alias/ModernizeStrposFixerTest.php index aecae38602f..9372dcf25f2 100644 --- a/tests/Fixer/Alias/ModernizeStrposFixerTest.php +++ b/tests/Fixer/Alias/ModernizeStrposFixerTest.php @@ -33,23 +33,139 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases(): array + public function provideFixCases(): \Generator { - return [ - [' 0) {}'], - - [' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + '', + '', + ]; + + yield [ + ' [ + ' [ + ' [ + '', + ]; + + yield 'none zero int' => [ + ' [ + ' 0) {}', + ]; + + yield 'lesser condition' => [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' [ + ' $b;', ]; } } diff --git a/tests/Fixtures/Integration/priority/modernize_strpos,binary_operator_spaces.test b/tests/Fixtures/Integration/priority/modernize_strpos,binary_operator_spaces.test new file mode 100644 index 00000000000..bc1a4731fc1 --- /dev/null +++ b/tests/Fixtures/Integration/priority/modernize_strpos,binary_operator_spaces.test @@ -0,0 +1,11 @@ +--TEST-- +Integration of fixers: modernize_strpos,binary_operator_spaces. +--RULESET-- +{"modernize_strpos": true, "binary_operator_spaces": true} +--EXPECT-- + Date: Sun, 5 Sep 2021 22:35:19 +0200 Subject: [PATCH 63/80] DX: make CI migration rules step ready for new 8.0 rules --- .github/workflows/ci.yml | 2 +- .php-cs-fixer.php-highest.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a1338ae581..fd2ada5205a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -109,7 +109,7 @@ jobs: composer update --optimize-autoloader --no-interaction --no-progress ${{ matrix.composer-flags }} composer info -D - - name: Execute migration rules + - name: Execute migration rules # we want to execute migration rules BEFORE we gonna run tests and self-fixing, so we know that our codebase is future-ready if: matrix.execute-migration-rules == 'yes' run: php php-cs-fixer fix --config .php-cs-fixer.php-highest.php -q diff --git a/.php-cs-fixer.php-highest.php b/.php-cs-fixer.php-highest.php index 0f01a1872c0..b3971965f39 100644 --- a/.php-cs-fixer.php-highest.php +++ b/.php-cs-fixer.php-highest.php @@ -18,9 +18,10 @@ $config = require '.php-cs-fixer.dist.php'; -$config->setRules([ +$config->setRules(array_merge($config->getRules(), [ '@PHP80Migration' => true, '@PHP80Migration:risky' => true, -]); + 'heredoc_indentation' => false, +])); return $config; From 07769f0e4b8483e5c4fc09771030675deadb558d Mon Sep 17 00:00:00 2001 From: Dariusz Ruminski Date: Mon, 6 Sep 2021 00:22:15 +0200 Subject: [PATCH 64/80] CI: don't try to execute jobs with Symfony:^3 --- .github/workflows/ci.yml | 7 +------ composer.json | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2a1338ae581..7873b3a838d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,16 +17,11 @@ jobs: - operating-system: 'ubuntu-20.04' php-version: '7.2' - job-description: 'with Sf ^3' - execute-flex-with-symfony-version: '^3' # Explicit check for Sf 3.x compatibility - - - operating-system: 'ubuntu-20.04' - php-version: '7.3' job-description: 'with Sf ^4' execute-flex-with-symfony-version: '^4' # Explicit check for Sf 4.x compatibility - operating-system: 'ubuntu-20.04' - php-version: '7.4' + php-version: '7.3' job-description: 'with Sf ^5' execute-flex-with-symfony-version: '^5' # Explicit check for Sf 5.x compatibility diff --git a/composer.json b/composer.json index c665a720217..980184e423b 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "require-dev": { "justinrainbow/json-schema": "^5.2", - "keradus/cli-executor": "^1.4", + "keradus/cli-executor": "^1.5", "mikey179/vfsstream": "^1.6.8", "php-coveralls/php-coveralls": "^2.4.3", "php-cs-fixer/accessible-object": "^1.1", From b6fa37f82eaa6cac1d55422a863b51189706b7bd Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Wed, 1 Sep 2021 08:50:44 +0200 Subject: [PATCH 65/80] PHP8.1 - type "never" support --- src/DocBlock/TypeExpression.php | 1 + ...tiveFunctionTypeDeclarationCasingFixer.php | 5 ++++ .../PhpdocToPropertyTypeFixer.php | 2 +- .../Analyzer/Analysis/TypeAnalysis.php | 1 + src/Tokenizer/Analyzer/ClassyAnalyzer.php | 2 +- tests/DocBlock/TypeExpressionTest.php | 1 + ...FunctionTypeDeclarationCasingFixerTest.php | 17 +++++++++++++ .../PhpdocToPropertyTypeFixerTest.php | 3 +++ tests/Fixtures/Integration/misc/PHP8_1.test | 25 +++++++++++++++++++ .../Analyzer/Analysis/TypeAnalysisTest.php | 1 + .../Tokenizer/Analyzer/ClassyAnalyzerTest.php | 19 ++++++++++++++ 11 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 tests/Fixtures/Integration/misc/PHP8_1.test diff --git a/src/DocBlock/TypeExpression.php b/src/DocBlock/TypeExpression.php index 9f3ee56a64b..48eb477c11f 100644 --- a/src/DocBlock/TypeExpression.php +++ b/src/DocBlock/TypeExpression.php @@ -244,6 +244,7 @@ private function normalize(string $type): string 'int', 'iterable', 'mixed', + 'never', 'null', 'object', 'resource', diff --git a/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php b/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php index 37f501c8685..3d2bddecd80 100644 --- a/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php +++ b/src/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixer.php @@ -42,6 +42,7 @@ final class NativeFunctionTypeDeclarationCasingFixer extends AbstractFixer * object PHP 7.2 * static PHP 8.0 (return type only) * mixed PHP 8.0 + * never PHP 8.1 * * @var array */ @@ -89,6 +90,10 @@ public function __construct() $this->hints = array_merge($this->hints, ['mixed' => true]); } + if (\PHP_VERSION_ID >= 80100) { + $this->hints = array_merge($this->hints, ['never' => true]); + } + $this->functionsAnalyzer = new FunctionsAnalyzer(); } diff --git a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php index 51dd784b41c..bc20074570f 100644 --- a/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToPropertyTypeFixer.php @@ -145,7 +145,7 @@ private function fixClass(Tokens $tokens, int $index): void [$propertyType, $isNullable] = $typeInfo; - if (\in_array($propertyType, ['void', 'callable'], true)) { + if (\in_array($propertyType, ['callable', 'never', 'void'], true)) { continue; } diff --git a/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php b/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php index a2511f56488..896b2fbecc0 100644 --- a/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php +++ b/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php @@ -38,6 +38,7 @@ final class TypeAnalysis implements StartEndTokenAwareAnalysis 'int', 'iterable', 'mixed', + 'never', 'numeric', 'object', 'resource', diff --git a/src/Tokenizer/Analyzer/ClassyAnalyzer.php b/src/Tokenizer/Analyzer/ClassyAnalyzer.php index c45cece76a8..1edb2c70a4a 100644 --- a/src/Tokenizer/Analyzer/ClassyAnalyzer.php +++ b/src/Tokenizer/Analyzer/ClassyAnalyzer.php @@ -30,7 +30,7 @@ public function isClassyInvocation(Tokens $tokens, int $index): bool throw new \LogicException(sprintf('No T_STRING at given index %d, got "%s".', $index, $tokens[$index]->getName())); } - if (\in_array(strtolower($token->getContent()), ['bool', 'float', 'int', 'iterable', 'object', 'parent', 'self', 'string', 'void', 'null', 'false'], true)) { + if (\in_array(strtolower($token->getContent()), ['bool', 'float', 'int', 'iterable', 'object', 'parent', 'self', 'string', 'void', 'null', 'false', 'never'], true)) { return false; } diff --git a/tests/DocBlock/TypeExpressionTest.php b/tests/DocBlock/TypeExpressionTest.php index 67030e4e501..f947c128f6f 100644 --- a/tests/DocBlock/TypeExpressionTest.php +++ b/tests/DocBlock/TypeExpressionTest.php @@ -144,6 +144,7 @@ public function provideCommonTypeCases(): \Generator yield ['int|null', 'int']; yield ['null|int', 'int']; yield ['void', 'void']; + yield ['never', 'never']; yield ['array|Traversable', 'iterable', null, [$useTraversable]]; yield ['array|Traversable', 'iterable', $globalNamespace, [$useTraversable]]; yield ['array|Traversable', 'iterable', $appNamespace, [$useTraversable]]; diff --git a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php index 1239d47366e..c72fd2234d9 100644 --- a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php +++ b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php @@ -204,4 +204,21 @@ public function provideFix80Cases(): \Generator 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + ' [ ' [ + ' [ ' $expected + * + * @dataProvider provideIsClassyInvocation81Cases + * @requires PHP 8.1 + */ + public function testIsClassyInvocation81(string $source, array $expected): void + { + self::assertClassyInvocation($source, $expected); + } + + public function provideIsClassyInvocation81Cases(): \Generator + { + yield [ + ' false, 8 => false], + ]; + } + private static function assertClassyInvocation(string $source, array $expected): void { $tokens = Tokens::fromCode($source); From 89106bccfb33fdac02397f231966f37d14bf4e07 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Mon, 6 Sep 2021 11:30:43 +0200 Subject: [PATCH 66/80] IntegerLiteralCaseFixer - introduction --- doc/ruleSets/Symfony.rst | 1 + doc/rules/casing/integer_literal_case.rst | 32 +++++++ doc/rules/index.rst | 2 + src/Fixer/Basic/EncodingFixer.php | 2 +- src/Fixer/Casing/IntegerLiteralCaseFixer.php | 69 +++++++++++++++ src/RuleSet/Sets/SymfonySet.php | 1 + .../Casing/IntegerLiteralCaseFixerTest.php | 84 +++++++++++++++++++ 7 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 doc/rules/casing/integer_literal_case.rst create mode 100644 src/Fixer/Casing/IntegerLiteralCaseFixer.php create mode 100644 tests/Fixer/Casing/IntegerLiteralCaseFixerTest.php diff --git a/doc/ruleSets/Symfony.rst b/doc/ruleSets/Symfony.rst index 73ddf3ca5de..69c504cbef4 100644 --- a/doc/ruleSets/Symfony.rst +++ b/doc/ruleSets/Symfony.rst @@ -38,6 +38,7 @@ Rules ``['replacements' => ['inheritDocs' => 'inheritDoc']]`` - `include <./../rules/control_structure/include.rst>`_ - `increment_style <./../rules/operator/increment_style.rst>`_ +- `integer_literal_case <./../rules/casing/integer_literal_case.rst>`_ - `lambda_not_used_import <./../rules/function_notation/lambda_not_used_import.rst>`_ - `linebreak_after_opening_tag <./../rules/php_tag/linebreak_after_opening_tag.rst>`_ - `magic_constant_casing <./../rules/casing/magic_constant_casing.rst>`_ diff --git a/doc/rules/casing/integer_literal_case.rst b/doc/rules/casing/integer_literal_case.rst new file mode 100644 index 00000000000..bf9a21c9b5c --- /dev/null +++ b/doc/rules/casing/integer_literal_case.rst @@ -0,0 +1,32 @@ +============================= +Rule ``integer_literal_case`` +============================= + +Integer literals must be in correct case. + +Examples +-------- + +Example #1 +~~~~~~~~~~ + +.. code-block:: diff + + --- Original + +++ New + `_ rule set will enable the ``integer_literal_case`` rule. + +@Symfony + Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``integer_literal_case`` rule. diff --git a/doc/rules/index.rst b/doc/rules/index.rst index b2a4133e0be..ca530a00baf 100644 --- a/doc/rules/index.rst +++ b/doc/rules/index.rst @@ -63,6 +63,8 @@ Casing - `constant_case <./casing/constant_case.rst>`_ The PHP constants ``true``, ``false``, and ``null`` MUST be written using the correct casing. +- `integer_literal_case <./casing/integer_literal_case.rst>`_ + Integer literals must be in correct case. - `lowercase_keywords <./casing/lowercase_keywords.rst>`_ PHP keywords MUST be in lower case. - `lowercase_static_reference <./casing/lowercase_static_reference.rst>`_ diff --git a/src/Fixer/Basic/EncodingFixer.php b/src/Fixer/Basic/EncodingFixer.php index 4e256e51f55..50044e3aa6a 100644 --- a/src/Fixer/Basic/EncodingFixer.php +++ b/src/Fixer/Basic/EncodingFixer.php @@ -37,7 +37,7 @@ public function __construct() { parent::__construct(); - $this->BOM = pack('CCC', 0xef, 0xbb, 0xbf); + $this->BOM = pack('CCC', 0xEF, 0xBB, 0xBF); } /** diff --git a/src/Fixer/Casing/IntegerLiteralCaseFixer.php b/src/Fixer/Casing/IntegerLiteralCaseFixer.php new file mode 100644 index 00000000000..5d262ffef14 --- /dev/null +++ b/src/Fixer/Casing/IntegerLiteralCaseFixer.php @@ -0,0 +1,69 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Fixer\Casing; + +use PhpCsFixer\AbstractFixer; +use PhpCsFixer\FixerDefinition\CodeSample; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Preg; +use PhpCsFixer\Tokenizer\Token; +use PhpCsFixer\Tokenizer\Tokens; + +final class IntegerLiteralCaseFixer extends AbstractFixer +{ + /** + * {@inheritdoc} + */ + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition( + 'Integer literals must be in correct case.', + [ + new CodeSample( + "isTokenKindFound(T_LNUMBER); + } + + protected function applyFix(\SplFileInfo $file, Tokens $tokens): void + { + foreach ($tokens as $index => $token) { + if (!$token->isGivenKind(T_LNUMBER)) { + continue; + } + + $content = $token->getContent(); + + if (1 !== Preg::match('#^0[bxoBXO][0-9a-fA-F]+$#', $content)) { + continue; + } + + $newContent = '0'.strtolower($content[1]).strtoupper(substr($content, 2)); + + if ($content === $newContent) { + continue; + } + + $tokens[$index] = new Token([T_LNUMBER, $newContent]); + } + } +} diff --git a/src/RuleSet/Sets/SymfonySet.php b/src/RuleSet/Sets/SymfonySet.php index 635f64d0125..ad7a652c09e 100644 --- a/src/RuleSet/Sets/SymfonySet.php +++ b/src/RuleSet/Sets/SymfonySet.php @@ -60,6 +60,7 @@ public function getRules(): array ], 'include' => true, 'increment_style' => true, + 'integer_literal_case' => true, 'lambda_not_used_import' => true, 'linebreak_after_opening_tag' => true, 'magic_constant_casing' => true, diff --git a/tests/Fixer/Casing/IntegerLiteralCaseFixerTest.php b/tests/Fixer/Casing/IntegerLiteralCaseFixerTest.php new file mode 100644 index 00000000000..e8611f91392 --- /dev/null +++ b/tests/Fixer/Casing/IntegerLiteralCaseFixerTest.php @@ -0,0 +1,84 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Fixer\Casing; + +use PhpCsFixer\Tests\Test\AbstractFixerTestCase; + +/** + * @internal + * + * @covers \PhpCsFixer\Fixer\Casing\IntegerLiteralCaseFixer + */ +final class IntegerLiteralCaseFixerTest extends AbstractFixerTestCase +{ + /** + * @dataProvider provideFixCases + */ + public function testFix(string $expected, string $input): void + { + $this->doTest($expected, $input); + } + + public function provideFixCases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public static function provideFix74Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public static function provideFix80Cases(): \Generator + { + yield [ + ' Date: Sun, 5 Sep 2021 20:47:27 +0000 Subject: [PATCH 67/80] DX: use modernize_strpos --- .php-cs-fixer.dist.php | 1 + composer.json | 1 + src/AbstractLinesBeforeNamespaceFixer.php | 2 +- src/Console/ConfigurationResolver.php | 2 +- src/DocBlock/Line.php | 4 ++-- src/DocBlock/TypeExpression.php | 2 +- src/Fixer/Alias/EregToPregFixer.php | 2 +- src/Fixer/Basic/BracesFixer.php | 14 +++++++------- src/Fixer/Basic/NonPrintableCharacterFixer.php | 2 +- src/Fixer/Basic/PsrAutoloadingFixer.php | 2 +- .../ClassAttributesSeparationFixer.php | 4 ++-- src/Fixer/ClassNotation/ClassDefinitionFixer.php | 8 ++++---- .../ClassNotation/FinalInternalClassFixer.php | 2 +- .../NoNullPropertyInitializationFixer.php | 2 +- src/Fixer/Comment/CommentToPhpdocFixer.php | 6 +++--- src/Fixer/Comment/HeaderCommentFixer.php | 2 +- .../MultilineCommentOpeningClosingFixer.php | 2 +- src/Fixer/Comment/SingleLineCommentStyleFixer.php | 2 +- .../DoctrineAnnotationIndentationFixer.php | 8 ++++---- .../DoctrineAnnotationSpacesFixer.php | 2 +- src/Fixer/FunctionNotation/FopenFlagsFixer.php | 2 +- .../FunctionNotation/MethodArgumentSpaceFixer.php | 6 +++--- ...ableTypeDeclarationForDefaultNullValueFixer.php | 2 +- .../FunctionNotation/SingleLineThrowFixer.php | 4 ++-- .../FunctionNotation/UseArrowFunctionsFixer.php | 2 +- .../Import/FullyQualifiedStrictTypesFixer.php | 2 +- src/Fixer/Import/GlobalNamespaceImportFixer.php | 8 ++++---- src/Fixer/Import/NoUnusedImportsFixer.php | 6 +++--- src/Fixer/Import/OrderedImportsFixer.php | 2 +- src/Fixer/Import/SingleImportPerStatementFixer.php | 2 +- .../LanguageConstruct/ClassKeywordRemoveFixer.php | 2 +- .../SingleSpaceAfterConstructFixer.php | 10 +++++----- src/Fixer/Operator/BinaryOperatorSpacesFixer.php | 14 +++++++------- src/Fixer/Operator/ConcatSpaceFixer.php | 2 +- src/Fixer/Operator/OperatorLinebreakFixer.php | 2 +- src/Fixer/Operator/TernaryOperatorSpacesFixer.php | 2 +- src/Fixer/PhpTag/BlankLineAfterOpeningTagFixer.php | 6 +++--- src/Fixer/PhpTag/LinebreakAfterOpeningTagFixer.php | 4 ++-- src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php | 4 ++-- .../PhpUnitNoExpectationAnnotationFixer.php | 2 +- src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php | 12 ++++++------ .../PhpUnitTestClassRequiresCoversFixer.php | 2 +- src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php | 2 +- .../PhpdocAddMissingParamAnnotationFixer.php | 2 +- .../MultilineWhitespaceBeforeSemicolonsFixer.php | 4 ++-- src/Fixer/Strict/DeclareStrictTypesFixer.php | 2 +- .../EscapeImplicitBackslashesFixer.php | 2 +- src/Fixer/StringNotation/HeredocToNowdocFixer.php | 2 +- src/Fixer/StringNotation/SingleQuoteFixer.php | 2 +- .../Whitespace/BlankLineBeforeStatementFixer.php | 2 +- src/Fixer/Whitespace/IndentationTypeFixer.php | 2 +- src/Fixer/Whitespace/NoExtraBlankLinesFixer.php | 6 +++--- .../Whitespace/NoSpacesInsideParenthesisFixer.php | 2 +- src/Linter/ProcessLinter.php | 2 +- src/RuleSet/AbstractRuleSetDescription.php | 2 +- src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php | 2 +- src/Tokenizer/Analyzer/CommentsAnalyzer.php | 4 ++-- src/Tokenizer/Analyzer/WhitespacesAnalyzer.php | 2 +- src/Tokenizer/Tokens.php | 4 ++-- src/Tokenizer/TokensAnalyzer.php | 2 +- tests/AutoReview/CommandTest.php | 2 +- tests/AutoReview/FixerFactoryTest.php | 2 +- tests/AutoReview/ProjectCodeTest.php | 2 +- .../NoUnneededControlParenthesesFixerTest.php | 2 +- .../MethodArgumentSpaceFixerTest.php | 4 ++-- tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php | 2 +- tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php | 2 +- .../Fixer/Whitespace/IndentationTypeFixerTest.php | 2 +- tests/FixerFactoryTest.php | 2 +- tests/RuleSet/RuleSetTest.php | 2 +- 70 files changed, 119 insertions(+), 117 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 29df7d8e5ed..998e341702e 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -43,6 +43,7 @@ '@PhpCsFixer:risky' => true, 'general_phpdoc_annotation_remove' => ['annotations' => ['expectedDeprecation']], // one should use PHPUnit built-in method instead 'header_comment' => ['header' => $header], + 'modernize_strpos' => true, // needs PHP 8+ or polyfill ]) ->setFinder($finder) ; diff --git a/composer.json b/composer.json index 980184e423b..f83e227f1b6 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "symfony/finder": "^4.4.20 || ^5.0", "symfony/options-resolver": "^4.4.20 || ^5.0", "symfony/polyfill-php72": "^1.23", + "symfony/polyfill-php80": "^1.23", "symfony/polyfill-php81": "^1.23", "symfony/process": "^4.4.20 || ^5.0", "symfony/stopwatch": "^4.4.20 || ^5.0" diff --git a/src/AbstractLinesBeforeNamespaceFixer.php b/src/AbstractLinesBeforeNamespaceFixer.php index 9e38e6eb6bc..3fdd94f7f92 100644 --- a/src/AbstractLinesBeforeNamespaceFixer.php +++ b/src/AbstractLinesBeforeNamespaceFixer.php @@ -48,7 +48,7 @@ protected function fixLinesBeforeNamespace(Tokens $tokens, int $index, int $expe if ($token->isGivenKind(T_OPEN_TAG)) { $openingToken = $token; $openingTokenIndex = $index - $i; - $newlineInOpening = false !== strpos($token->getContent(), "\n"); + $newlineInOpening = str_contains($token->getContent(), "\n"); if ($newlineInOpening) { ++$precedingNewlines; } diff --git a/src/Console/ConfigurationResolver.php b/src/Console/ConfigurationResolver.php index 9a7b71e342f..3be2fd0b930 100644 --- a/src/Console/ConfigurationResolver.php +++ b/src/Console/ConfigurationResolver.php @@ -881,7 +881,7 @@ static function (\SplFileInfo $current) use ($pathsByType): bool { } foreach ($pathsByType['dir'] as $path) { - if (0 === strpos($currentRealPath, $path)) { + if (str_starts_with($currentRealPath, $path)) { return true; } } diff --git a/src/DocBlock/Line.php b/src/DocBlock/Line.php index 0cf1ffc586a..d54c53da6f9 100644 --- a/src/DocBlock/Line.php +++ b/src/DocBlock/Line.php @@ -81,7 +81,7 @@ public function containsATag(): bool */ public function isTheStart(): bool { - return false !== strpos($this->content, '/**'); + return str_contains($this->content, '/**'); } /** @@ -89,7 +89,7 @@ public function isTheStart(): bool */ public function isTheEnd(): bool { - return false !== strpos($this->content, '*/'); + return str_contains($this->content, '*/'); } /** diff --git a/src/DocBlock/TypeExpression.php b/src/DocBlock/TypeExpression.php index 9f3ee56a64b..3e45550d620 100644 --- a/src/DocBlock/TypeExpression.php +++ b/src/DocBlock/TypeExpression.php @@ -261,7 +261,7 @@ private function normalize(string $type): string return $matches[1]; } - if (0 === strpos($type, '\\')) { + if (str_starts_with($type, '\\')) { return substr($type, 1); } diff --git a/src/Fixer/Alias/EregToPregFixer.php b/src/Fixer/Alias/EregToPregFixer.php index 80a75db5e7b..80151cf7a31 100644 --- a/src/Fixer/Alias/EregToPregFixer.php +++ b/src/Fixer/Alias/EregToPregFixer.php @@ -164,7 +164,7 @@ private function getBestDelimiter(string $pattern): string // try do find something that's not used $delimiters = []; foreach (self::$delimiters as $k => $d) { - if (false === strpos($pattern, $d)) { + if (!str_contains($pattern, $d)) { return $d; } diff --git a/src/Fixer/Basic/BracesFixer.php b/src/Fixer/Basic/BracesFixer.php index 9c03dbf03e5..f0dd9824caa 100644 --- a/src/Fixer/Basic/BracesFixer.php +++ b/src/Fixer/Basic/BracesFixer.php @@ -237,7 +237,7 @@ private function fixCommentBeforeBrace(Tokens $tokens): void $commentIndex = $tokens->getNextNonWhitespace($prevIndex); $commentToken = $tokens[$commentIndex]; - if (!$commentToken->isGivenKind(T_COMMENT) || 0 === strpos($commentToken->getContent(), '/*')) { + if (!$commentToken->isGivenKind(T_COMMENT) || str_starts_with($commentToken->getContent(), '/*')) { continue; } @@ -599,7 +599,7 @@ static function (int $item): bool { if ( !$isAnonymousClass && $tokens[$closingParenthesisIndex - 1]->isWhitespace() - && false !== strpos($tokens[$closingParenthesisIndex - 1]->getContent(), "\n") + && str_contains($tokens[$closingParenthesisIndex - 1]->getContent(), "\n") ) { if (!$tokens[$startBraceIndex - 2]->isComment()) { $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, ' '); @@ -888,8 +888,8 @@ private function ensureWhitespaceAtIndexAndIndentMultilineComment(Tokens $tokens $previousToken->isWhitespace() && 1 === Preg::match('/\R$/', $previousToken->getContent()) && ( - (0 === strpos($nextTokenContent, '//'.$this->whitespacesConfig->getIndent()) || '//' === $nextTokenContent) - || (0 === strpos($nextTokenContent, '#'.$this->whitespacesConfig->getIndent()) || '#' === $nextTokenContent) + (str_starts_with($nextTokenContent, '//'.$this->whitespacesConfig->getIndent()) || '//' === $nextTokenContent) + || (str_starts_with($nextTokenContent, '#'.$this->whitespacesConfig->getIndent()) || '#' === $nextTokenContent) ) ) { return; @@ -911,7 +911,7 @@ private function ensureWhitespaceAtIndexAndIndentMultilineComment(Tokens $tokens private function isMultilined(Tokens $tokens, int $startParenthesisIndex, int $endParenthesisIndex): bool { for ($i = $startParenthesisIndex; $i < $endParenthesisIndex; ++$i) { - if (false !== strpos($tokens[$i]->getContent(), "\n")) { + if (str_contains($tokens[$i]->getContent(), "\n")) { return true; } } @@ -933,7 +933,7 @@ private function isCommentWithFixableIndentation(Tokens $tokens, int $index): bo return false; } - if (0 === strpos($tokens[$index]->getContent(), '/*')) { + if (str_starts_with($tokens[$index]->getContent(), '/*')) { return true; } @@ -979,7 +979,7 @@ private function getSiblingContinuousSingleLineComment(Tokens $tokens, int $inde if (null === $siblingIndex) { return null; } - } while (0 === strpos($tokens[$siblingIndex]->getContent(), '/*')); + } while (str_starts_with($tokens[$siblingIndex]->getContent(), '/*')); $newLines = 0; for ($i = min($siblingIndex, $index) + 1, $max = max($siblingIndex, $index); $i < $max; ++$i) { diff --git a/src/Fixer/Basic/NonPrintableCharacterFixer.php b/src/Fixer/Basic/NonPrintableCharacterFixer.php index b36ed4fe486..3df6fefdbaf 100644 --- a/src/Fixer/Basic/NonPrintableCharacterFixer.php +++ b/src/Fixer/Basic/NonPrintableCharacterFixer.php @@ -139,7 +139,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ($previousToken->isGivenKind(T_START_HEREDOC)) { $previousTokenContent = $previousToken->getContent(); - if (false !== strpos($previousTokenContent, '\'')) { + if (str_contains($previousTokenContent, '\'')) { $tokens[$index - 1] = new Token([T_START_HEREDOC, str_replace('\'', '', $previousTokenContent)]); $stringTypeChanged = true; } diff --git a/src/Fixer/Basic/PsrAutoloadingFixer.php b/src/Fixer/Basic/PsrAutoloadingFixer.php index 96a86c92a0a..71dbe216a00 100644 --- a/src/Fixer/Basic/PsrAutoloadingFixer.php +++ b/src/Fixer/Basic/PsrAutoloadingFixer.php @@ -153,7 +153,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { - if (null !== $this->configuration['dir'] && 0 !== strpos($file->getRealPath(), $this->configuration['dir'])) { + if (null !== $this->configuration['dir'] && !str_starts_with($file->getRealPath(), $this->configuration['dir'])) { return; } diff --git a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php index 7e50ba1e10a..06e60b6f421 100644 --- a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php +++ b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php @@ -545,7 +545,7 @@ private function getLastTokenIndexOfClassElement(Tokens $tokens, array $class, a $singleLineElement = true; for ($i = $element['index'] + 1; $i < $elementEndIndex; ++$i) { - if (false !== strpos($tokens[$i]->getContent(), "\n")) { + if (str_contains($tokens[$i]->getContent(), "\n")) { $singleLineElement = false; break; @@ -556,7 +556,7 @@ private function getLastTokenIndexOfClassElement(Tokens $tokens, array $class, a while (true) { $nextToken = $tokens[$elementEndIndex + 1]; - if (($nextToken->isComment() || $nextToken->isWhitespace()) && false === strpos($nextToken->getContent(), "\n")) { + if (($nextToken->isComment() || $nextToken->isWhitespace()) && !str_contains($nextToken->getContent(), "\n")) { ++$elementEndIndex; } else { break; diff --git a/src/Fixer/ClassNotation/ClassDefinitionFixer.php b/src/Fixer/ClassNotation/ClassDefinitionFixer.php index 1fb578dd1b2..428db45251f 100644 --- a/src/Fixer/ClassNotation/ClassDefinitionFixer.php +++ b/src/Fixer/ClassNotation/ClassDefinitionFixer.php @@ -248,7 +248,7 @@ private function fixClassyDefinitionOpenSpacing(Tokens $tokens, array $classDefI $openIndex = $tokens->getNextTokenOfKind($classDefInfo['classy'], ['{']); - if (' ' !== $spacing && false !== strpos($tokens[$openIndex - 1]->getContent(), "\n")) { + if (' ' !== $spacing && str_contains($tokens[$openIndex - 1]->getContent(), "\n")) { return $openIndex; } @@ -315,7 +315,7 @@ private function getClassyInheritanceInfo(Tokens $tokens, int $startIndex, strin continue; } - if (!$implementsInfo['multiLine'] && false !== strpos($tokens[$i]->getContent(), "\n")) { + if (!$implementsInfo['multiLine'] && str_contains($tokens[$i]->getContent(), "\n")) { $implementsInfo['multiLine'] = true; } } @@ -378,7 +378,7 @@ private function makeClassyDefinitionSingleLine(Tokens $tokens, int $startIndex, continue; } - if (!$tokens[$i + 1]->isWhitespace() && !$tokens[$i + 1]->isComment() && false === strpos($tokens[$i]->getContent(), "\n")) { + if (!$tokens[$i + 1]->isWhitespace() && !$tokens[$i + 1]->isComment() && !str_contains($tokens[$i]->getContent(), "\n")) { $tokens->insertAt($i + 1, new Token([T_WHITESPACE, ' '])); } @@ -405,7 +405,7 @@ private function makeClassyInheritancePartMultiLine(Tokens $tokens, int $startIn $isOnOwnLine = false; for ($j = $breakAtIndex; $j > $previousInterfaceImplementingIndex; --$j) { - if (false !== strpos($tokens[$j]->getContent(), "\n")) { + if (str_contains($tokens[$j]->getContent(), "\n")) { $isOnOwnLine = true; break; diff --git a/src/Fixer/ClassNotation/FinalInternalClassFixer.php b/src/Fixer/ClassNotation/FinalInternalClassFixer.php index 0d143f5bafc..f49b970576c 100644 --- a/src/Fixer/ClassNotation/FinalInternalClassFixer.php +++ b/src/Fixer/ClassNotation/FinalInternalClassFixer.php @@ -201,7 +201,7 @@ private function isClassCandidate(Tokens $tokens, int $index): bool } $tag = strtolower(substr(array_shift($matches), 1)); foreach ($this->configuration['annotation_exclude'] as $tagStart => $true) { - if (0 === strpos($tag, $tagStart)) { + if (str_starts_with($tag, $tagStart)) { return false; // ignore class: class-level PHPDoc contains tag that has been excluded through configuration } } diff --git a/src/Fixer/ClassNotation/NoNullPropertyInitializationFixer.php b/src/Fixer/ClassNotation/NoNullPropertyInitializationFixer.php index 01adc32731e..176a2a675bd 100644 --- a/src/Fixer/ClassNotation/NoNullPropertyInitializationFixer.php +++ b/src/Fixer/ClassNotation/NoNullPropertyInitializationFixer.php @@ -130,7 +130,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ($tokens[$index]->equals([T_STRING, 'null'], false)) { for ($i = $varTokenIndex + 1; $i <= $index; ++$i) { if ( - !($tokens[$i]->isWhitespace() && false !== strpos($tokens[$i]->getContent(), "\n")) + !($tokens[$i]->isWhitespace() && str_contains($tokens[$i]->getContent(), "\n")) && !$tokens[$i]->isComment() ) { $tokens->clearAt($i); diff --git a/src/Fixer/Comment/CommentToPhpdocFixer.php b/src/Fixer/Comment/CommentToPhpdocFixer.php index f6cc93542c8..b887b18757a 100644 --- a/src/Fixer/Comment/CommentToPhpdocFixer.php +++ b/src/Fixer/Comment/CommentToPhpdocFixer.php @@ -206,7 +206,7 @@ private function fixCommentMultiLine(Tokens $tokens, array $indices): void if (!$tokens[$index]->isComment()) { continue; } - if (false !== strpos($tokens[$index]->getContent(), '*/')) { + if (str_contains($tokens[$index]->getContent(), '*/')) { return; } $message = $this->getMessage($tokens[$index]->getContent()); @@ -227,10 +227,10 @@ private function fixCommentMultiLine(Tokens $tokens, array $indices): void private function getMessage(string $content): string { - if (0 === strpos($content, '#')) { + if (str_starts_with($content, '#')) { return substr($content, 1); } - if (0 === strpos($content, '//')) { + if (str_starts_with($content, '//')) { return substr($content, 2); } diff --git a/src/Fixer/Comment/HeaderCommentFixer.php b/src/Fixer/Comment/HeaderCommentFixer.php index a22e2500568..2eadbfe7ccf 100644 --- a/src/Fixer/Comment/HeaderCommentFixer.php +++ b/src/Fixer/Comment/HeaderCommentFixer.php @@ -208,7 +208,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn return ''; } - if (false !== strpos($value, '*/')) { + if (str_contains($value, '*/')) { throw new InvalidFixerConfigurationException($fixerName, 'Cannot use \'*/\' in header.'); } diff --git a/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php b/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php index 7e32153f785..d27585ea0b1 100644 --- a/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php +++ b/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php @@ -75,7 +75,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ( !$token->isGivenKind(T_DOC_COMMENT) - && !($token->isGivenKind(T_COMMENT) && 0 === strpos($originalContent, '/*')) + && !($token->isGivenKind(T_COMMENT) && str_starts_with($originalContent, '/*')) ) { continue; } diff --git a/src/Fixer/Comment/SingleLineCommentStyleFixer.php b/src/Fixer/Comment/SingleLineCommentStyleFixer.php index ff81467d12c..91fb80431c6 100644 --- a/src/Fixer/Comment/SingleLineCommentStyleFixer.php +++ b/src/Fixer/Comment/SingleLineCommentStyleFixer.php @@ -145,7 +145,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ( !$this->asteriskEnabled - || false !== strpos($commentContent, '?>') + || str_contains($commentContent, '?>') || '/*' !== substr($content, 0, 2) || 1 === Preg::match('/[^\s\*].*\R.*[^\s\*]/s', $commentContent) ) { diff --git a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php index 8a5f25498b2..199e008d0da 100644 --- a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php +++ b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php @@ -82,7 +82,7 @@ protected function fixAnnotations(Tokens $doctrineAnnotationTokens): void $indentLevel = 0; foreach ($doctrineAnnotationTokens as $index => $token) { - if (!$token->isType(DocLexer::T_NONE) || false === strpos($token->getContent(), "\n")) { + if (!$token->isType(DocLexer::T_NONE) || !str_contains($token->getContent(), "\n")) { continue; } @@ -125,7 +125,7 @@ private function getLineBracesCount(Tokens $tokens, int $index): array while (isset($tokens[++$index])) { $token = $tokens[$index]; - if ($token->isType(DocLexer::T_NONE) && false !== strpos($token->getContent(), "\n")) { + if ($token->isType(DocLexer::T_NONE) && str_contains($token->getContent(), "\n")) { break; } @@ -154,7 +154,7 @@ private function isClosingLineWithMeaningfulContent(Tokens $tokens, int $index): while (isset($tokens[++$index])) { $token = $tokens[$index]; if ($token->isType(DocLexer::T_NONE)) { - if (false !== strpos($token->getContent(), "\n")) { + if (str_contains($token->getContent(), "\n")) { return false; } @@ -181,7 +181,7 @@ private function indentationCanBeFixed(Tokens $tokens, int $newLineTokenIndex, a for ($index = $newLineTokenIndex + 1, $max = \count($tokens); $index < $max; ++$index) { $token = $tokens[$index]; - if (false !== strpos($token->getContent(), "\n")) { + if (str_contains($token->getContent(), "\n")) { return false; } diff --git a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php index 50ccf7f992b..49ca2a60983 100644 --- a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php +++ b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php @@ -170,7 +170,7 @@ private function fixSpacesAroundParentheses(Tokens $tokens): void } if ($token->isType(DocLexer::T_NONE)) { - if (false !== strpos($token->getContent(), "\n")) { + if (str_contains($token->getContent(), "\n")) { continue; } diff --git a/src/Fixer/FunctionNotation/FopenFlagsFixer.php b/src/Fixer/FunctionNotation/FopenFlagsFixer.php index 5ae2354997c..301639a2fd0 100644 --- a/src/Fixer/FunctionNotation/FopenFlagsFixer.php +++ b/src/Fixer/FunctionNotation/FopenFlagsFixer.php @@ -95,7 +95,7 @@ protected function fixFopenFlagToken(Tokens $tokens, int $argumentStartIndex, in $mode = str_replace('t', '', $mode); if ($this->configuration['b_mode']) { - if (false === strpos($mode, 'b')) { + if (!str_contains($mode, 'b')) { $mode .= 'b'; } } else { diff --git a/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php b/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php index e73505aa7c8..e34ad84f862 100644 --- a/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php +++ b/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php @@ -297,7 +297,7 @@ private function ensureSingleLine(Tokens $tokens, int $index): bool { $previousToken = $tokens[$index - 1]; - if ($previousToken->isComment() && 0 !== strpos($previousToken->getContent(), '/*')) { + if ($previousToken->isComment() && !str_starts_with($previousToken->getContent(), '/*')) { return false; } @@ -324,7 +324,7 @@ private function ensureFunctionFullyMultiline(Tokens $tokens, int $startFunction $searchIndex = $prevWhitespaceTokenIndex; } while (null !== $prevWhitespaceTokenIndex - && false === strpos($tokens[$prevWhitespaceTokenIndex]->getContent(), "\n") + && !str_contains($tokens[$prevWhitespaceTokenIndex]->getContent(), "\n") ); if (null === $prevWhitespaceTokenIndex) { @@ -482,6 +482,6 @@ private function isCommentLastLineToken(Tokens $tokens, int $index): bool */ private function isNewline(Token $token): bool { - return $token->isWhitespace() && false !== strpos($token->getContent(), "\n"); + return $token->isWhitespace() && str_contains($token->getContent(), "\n"); } } diff --git a/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php b/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php index 117eab20ddb..8aca8026a82 100644 --- a/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php +++ b/src/Fixer/FunctionNotation/NullableTypeDeclarationForDefaultNullValueFixer.php @@ -128,7 +128,7 @@ private function fixFunctionParameters(Tokens $tokens, array $arguments): void // - doesn't have a type declaration !$argumentInfo->hasTypeAnalysis() // type is a union - || false !== strpos($argumentInfo->getTypeAnalysis()->getName(), '|') + || str_contains($argumentInfo->getTypeAnalysis()->getName(), '|') // - a default value is not null we can continue || !$argumentInfo->hasDefault() || 'null' !== strtolower($argumentInfo->getDefault()) ) { diff --git a/src/Fixer/FunctionNotation/SingleLineThrowFixer.php b/src/Fixer/FunctionNotation/SingleLineThrowFixer.php index f8599dd395b..da61d6f473b 100644 --- a/src/Fixer/FunctionNotation/SingleLineThrowFixer.php +++ b/src/Fixer/FunctionNotation/SingleLineThrowFixer.php @@ -95,10 +95,10 @@ private function trimNewLines(Tokens $tokens, int $startIndex, int $endIndex): v $content = $tokens[$index]->getContent(); if ($tokens[$index]->isGivenKind(T_COMMENT)) { - if (0 === strpos($content, '//')) { + if (str_starts_with($content, '//')) { $content = '/*'.substr($content, 2).' */'; $tokens->clearAt($index + 1); - } elseif (0 === strpos($content, '#')) { + } elseif (str_starts_with($content, '#')) { $content = '/*'.substr($content, 1).' */'; $tokens->clearAt($index + 1); } elseif (false !== Preg::match('/\R/', $content)) { diff --git a/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php b/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php index 5448fdf8343..8a5733745c5 100644 --- a/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php +++ b/src/Fixer/FunctionNotation/UseArrowFunctionsFixer.php @@ -177,7 +177,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void private function isMultilined(Tokens $tokens, int $start, int $end): bool { for ($i = $start; $i < $end; ++$i) { - if (false !== strpos($tokens[$i]->getContent(), "\n")) { + if (str_contains($tokens[$i]->getContent(), "\n")) { return true; } } diff --git a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php index 91de9bd983c..26027cdad2d 100644 --- a/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php +++ b/src/Fixer/Import/FullyQualifiedStrictTypesFixer.php @@ -150,7 +150,7 @@ private function detectAndReplaceTypeWithShortType( foreach ($this->getSimpleTypes($tokens, $typeStartIndex, $type->getEndIndex()) as $simpleType) { $typeName = $tokens->generatePartialCode($simpleType['start'], $simpleType['end']); - if (0 !== strpos($typeName, '\\')) { + if (!str_starts_with($typeName, '\\')) { continue; } diff --git a/src/Fixer/Import/GlobalNamespaceImportFixer.php b/src/Fixer/Import/GlobalNamespaceImportFixer.php index 269f820d900..3f7e13ceffe 100644 --- a/src/Fixer/Import/GlobalNamespaceImportFixer.php +++ b/src/Fixer/Import/GlobalNamespaceImportFixer.php @@ -315,7 +315,7 @@ private function importClasses(Tokens $tokens, array $useDeclarations): array $docBlocks[$index] = new DocBlock($token->getContent()); $this->traverseDocBlockTypes($docBlocks[$index], static function (string $type) use ($global, &$other): void { - if (false !== strpos($type, '\\')) { + if (str_contains($type, '\\')) { return; } @@ -386,7 +386,7 @@ private function importClasses(Tokens $tokens, array $useDeclarations): array $name = substr($type, 1); $checkName = strtolower($name); - if (false !== strpos($checkName, '\\') || isset($other[$checkName])) { + if (str_contains($checkName, '\\') || isset($other[$checkName])) { return $type; } @@ -453,7 +453,7 @@ private function insertImports(Tokens $tokens, array $imports, array $useDeclara $lineEnding = $this->whitespacesConfig->getLineEnding(); - if (!$tokens[$index]->isWhitespace() || false === strpos($tokens[$index]->getContent(), "\n")) { + if (!$tokens[$index]->isWhitespace() || !str_contains($tokens[$index]->getContent(), "\n")) { $tokens->insertAt($index, new Token([T_WHITESPACE, $lineEnding])); } @@ -640,7 +640,7 @@ private function filterUseDeclarations(array $declarations, callable $callback, $fullName = ltrim($declaration->getFullName(), '\\'); - if (false !== strpos($fullName, '\\')) { + if (str_contains($fullName, '\\')) { $name = $caseSensitive ? $declaration->getShortName() : strtolower($declaration->getShortName()); $other[$name] = true; diff --git a/src/Fixer/Import/NoUnusedImportsFixer.php b/src/Fixer/Import/NoUnusedImportsFixer.php index 359dbb849be..2f8f5ce8c37 100644 --- a/src/Fixer/Import/NoUnusedImportsFixer.php +++ b/src/Fixer/Import/NoUnusedImportsFixer.php @@ -203,7 +203,7 @@ private function removeUseDeclaration(Tokens $tokens, NamespaceUseAnalysis $useD continue; } - if (!$tokens[$index]->isWhitespace() || false === strpos($tokens[$index]->getContent(), "\n")) { + if (!$tokens[$index]->isWhitespace() || !str_contains($tokens[$index]->getContent(), "\n")) { $tokens->clearTokenAndMergeSurroundingWhitespace($index); continue; @@ -295,13 +295,13 @@ private function removeUsesInSameNamespace(Tokens $tokens, array $useDeclaration $useDeclarationFullName = ltrim($useDeclaration->getFullName(), '\\'); - if (0 !== strpos($useDeclarationFullName, $namespace.'\\')) { + if (!str_starts_with($useDeclarationFullName, $namespace.'\\')) { continue; } $partName = substr($useDeclarationFullName, $nsLength); - if (false === strpos($partName, '\\')) { + if (!str_contains($partName, '\\')) { $this->removeUseDeclaration($tokens, $useDeclaration); } } diff --git a/src/Fixer/Import/OrderedImportsFixer.php b/src/Fixer/Import/OrderedImportsFixer.php index ca2ba1466f4..d2434c7b4a9 100644 --- a/src/Fixer/Import/OrderedImportsFixer.php +++ b/src/Fixer/Import/OrderedImportsFixer.php @@ -406,7 +406,7 @@ private function getNewOrder(array $uses, Tokens $tokens): array if ( '' === $firstIndent && $namespaceTokens[$k2]->isWhitespace() - && false !== strpos($namespaceTokens[$k2]->getContent(), $lineEnding) + && str_contains($namespaceTokens[$k2]->getContent(), $lineEnding) ) { $lastIndent = $lineEnding; $firstIndent = $lineEnding.$this->whitespacesConfig->getIndent(); diff --git a/src/Fixer/Import/SingleImportPerStatementFixer.php b/src/Fixer/Import/SingleImportPerStatementFixer.php index 48b68733289..0c36a402fff 100644 --- a/src/Fixer/Import/SingleImportPerStatementFixer.php +++ b/src/Fixer/Import/SingleImportPerStatementFixer.php @@ -231,7 +231,7 @@ private function fixMultipleUse(Tokens $tokens, int $index, int $endIndex): void if ($tokens[$i - 1]->isWhitespace()) { $tokens[$i - 1] = new Token([T_WHITESPACE, $ending.$indent]); - } elseif (false === strpos($tokens[$i - 1]->getContent(), "\n")) { + } elseif (!str_contains($tokens[$i - 1]->getContent(), "\n")) { $tokens->insertAt($i, new Token([T_WHITESPACE, $ending.$indent])); } } diff --git a/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php b/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php index 5f932e2e988..23b2b48142b 100644 --- a/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php +++ b/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php @@ -216,7 +216,7 @@ private function replaceClassKeyword(Tokens $tokens, string $namespacePrefix, in } for ($i = $classBeginIndex; $i <= $classIndex; ++$i) { - if (!$tokens[$i]->isComment() && !($tokens[$i]->isWhitespace() && false !== strpos($tokens[$i]->getContent(), "\n"))) { + if (!$tokens[$i]->isComment() && !($tokens[$i]->isWhitespace() && str_contains($tokens[$i]->getContent(), "\n"))) { $tokens->clearAt($i); } } diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index 74647457063..5d3f64f57fd 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -219,7 +219,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } if ($token->isGivenKind(T_OPEN_TAG)) { - if ($tokens[$whitespaceTokenIndex]->equals([T_WHITESPACE]) && false === strpos($token->getContent(), "\n")) { + if ($tokens[$whitespaceTokenIndex]->equals([T_WHITESPACE]) && !str_contains($token->getContent(), "\n")) { $tokens->clearAt($whitespaceTokenIndex); } @@ -239,7 +239,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } if ($token->isComment() || $token->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { - if ($tokens[$whitespaceTokenIndex]->equals([T_WHITESPACE]) && false !== strpos($tokens[$whitespaceTokenIndex]->getContent(), "\n")) { + if ($tokens[$whitespaceTokenIndex]->equals([T_WHITESPACE]) && str_contains($tokens[$whitespaceTokenIndex]->getContent(), "\n")) { continue; } } @@ -281,7 +281,7 @@ private function isMultiLineReturn(Tokens $tokens, int $index): bool if ( !$tokenFollowingReturn->isGivenKind(T_WHITESPACE) - || false === strpos($tokenFollowingReturn->getContent(), "\n") + || !str_contains($tokenFollowingReturn->getContent(), "\n") ) { return false; } @@ -289,7 +289,7 @@ private function isMultiLineReturn(Tokens $tokens, int $index): bool $nestedCount = 0; for ($indexEnd = \count($tokens) - 1, ++$index; $index < $indexEnd; ++$index) { - if (false !== strpos($tokens[$index]->getContent(), "\n")) { + if (str_contains($tokens[$index]->getContent(), "\n")) { return true; } @@ -322,7 +322,7 @@ private function isMultilineExtendsOrImplementsWithMoreThanOneAncestor(Tokens $t return false; } - if ($hasMoreThanOneAncestor && false !== strpos($token->getContent(), "\n")) { + if ($hasMoreThanOneAncestor && str_contains($token->getContent(), "\n")) { return true; } } diff --git a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php index 2a8f49ec9b9..dbcd8fab0c7 100644 --- a/src/Fixer/Operator/BinaryOperatorSpacesFixer.php +++ b/src/Fixer/Operator/BinaryOperatorSpacesFixer.php @@ -388,7 +388,7 @@ private function fixWhiteSpaceAroundOperatorToSingleSpace(Tokens $tokens, int $i // fix white space after operator if ($tokens[$index + 1]->isWhitespace()) { $content = $tokens[$index + 1]->getContent(); - if (' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getNextNonWhitespace($index + 1)]->isComment()) { + if (' ' !== $content && !str_contains($content, "\n") && !$tokens[$tokens->getNextNonWhitespace($index + 1)]->isComment()) { $tokens[$index + 1] = new Token([T_WHITESPACE, ' ']); } } else { @@ -398,7 +398,7 @@ private function fixWhiteSpaceAroundOperatorToSingleSpace(Tokens $tokens, int $i // fix white space before operator if ($tokens[$index - 1]->isWhitespace()) { $content = $tokens[$index - 1]->getContent(); - if (' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) { + if (' ' !== $content && !str_contains($content, "\n") && !$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) { $tokens[$index - 1] = new Token([T_WHITESPACE, ' ']); } } else { @@ -411,7 +411,7 @@ private function fixWhiteSpaceAroundOperatorToNoSpace(Tokens $tokens, int $index // fix white space after operator if ($tokens[$index + 1]->isWhitespace()) { $content = $tokens[$index + 1]->getContent(); - if (false === strpos($content, "\n") && !$tokens[$tokens->getNextNonWhitespace($index + 1)]->isComment()) { + if (!str_contains($content, "\n") && !$tokens[$tokens->getNextNonWhitespace($index + 1)]->isComment()) { $tokens->clearAt($index + 1); } } @@ -419,7 +419,7 @@ private function fixWhiteSpaceAroundOperatorToNoSpace(Tokens $tokens, int $index // fix white space before operator if ($tokens[$index - 1]->isWhitespace()) { $content = $tokens[$index - 1]->getContent(); - if (false === strpos($content, "\n") && !$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) { + if (!str_contains($content, "\n") && !$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) { $tokens->clearAt($index - 1); } } @@ -624,7 +624,7 @@ private function injectAlignmentPlaceholdersForArrow(Tokens $tokens, int $startA if ($token->equals(',')) { for ($i = $index; $i < $endAt - 1; ++$i) { - if (false !== strpos($tokens[$i - 1]->getContent(), "\n")) { + if (str_contains($tokens[$i - 1]->getContent(), "\n")) { break; } @@ -672,7 +672,7 @@ private function fixWhiteSpaceBeforeOperator(Tokens $tokens, int $index, string } $content = $tokens[$index - 1]->getContent(); - if (' ' !== $content && false === strpos($content, "\n")) { + if (' ' !== $content && !str_contains($content, "\n")) { $tokens[$index - 1] = new Token([T_WHITESPACE, ' ']); } } @@ -687,7 +687,7 @@ private function replacePlaceholders(Tokens $tokens, string $alignStrategy): str for ($j = 0; $j <= $this->deepestLevel; ++$j) { $placeholder = sprintf(self::ALIGN_PLACEHOLDER, $j); - if (false === strpos($tmpCode, $placeholder)) { + if (!str_contains($tmpCode, $placeholder)) { continue; } diff --git a/src/Fixer/Operator/ConcatSpaceFixer.php b/src/Fixer/Operator/ConcatSpaceFixer.php index f146b072c9f..91ecc8b4140 100644 --- a/src/Fixer/Operator/ConcatSpaceFixer.php +++ b/src/Fixer/Operator/ConcatSpaceFixer.php @@ -154,7 +154,7 @@ private function fixWhiteSpaceAroundConcatToken(Tokens $tokens, int $index, int return; } - if (false !== strpos($tokens[$offsetIndex]->getContent(), "\n")) { + if (str_contains($tokens[$offsetIndex]->getContent(), "\n")) { return; } diff --git a/src/Fixer/Operator/OperatorLinebreakFixer.php b/src/Fixer/Operator/OperatorLinebreakFixer.php index 4904b628d50..45052121712 100644 --- a/src/Fixer/Operator/OperatorLinebreakFixer.php +++ b/src/Fixer/Operator/OperatorLinebreakFixer.php @@ -295,7 +295,7 @@ static function (int $index) use ($tokens, $direction): Token { private function isMultiline(Tokens $tokens, int $indexStart, int $indexEnd): bool { for ($index = $indexStart; $index <= $indexEnd; ++$index) { - if (false !== strpos($tokens[$index]->getContent(), "\n")) { + if (str_contains($tokens[$index]->getContent(), "\n")) { return true; } } diff --git a/src/Fixer/Operator/TernaryOperatorSpacesFixer.php b/src/Fixer/Operator/TernaryOperatorSpacesFixer.php index a03639d05fb..6929d609ee5 100644 --- a/src/Fixer/Operator/TernaryOperatorSpacesFixer.php +++ b/src/Fixer/Operator/TernaryOperatorSpacesFixer.php @@ -165,7 +165,7 @@ private function ensureWhitespaceExistence(Tokens $tokens, int $index, bool $aft { if ($tokens[$index]->isWhitespace()) { if ( - false === strpos($tokens[$index]->getContent(), "\n") + !str_contains($tokens[$index]->getContent(), "\n") && !$tokens[$index - 1]->isComment() ) { $tokens[$index] = new Token([T_WHITESPACE, ' ']); diff --git a/src/Fixer/PhpTag/BlankLineAfterOpeningTagFixer.php b/src/Fixer/PhpTag/BlankLineAfterOpeningTagFixer.php index 81a381785d2..897bd1fc472 100644 --- a/src/Fixer/PhpTag/BlankLineAfterOpeningTagFixer.php +++ b/src/Fixer/PhpTag/BlankLineAfterOpeningTagFixer.php @@ -72,7 +72,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $newlineFound = false; /** @var Token $token */ foreach ($tokens as $token) { - if ($token->isWhitespace() && false !== strpos($token->getContent(), "\n")) { + if ($token->isWhitespace() && str_contains($token->getContent(), "\n")) { $newlineFound = true; break; @@ -86,11 +86,11 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $token = $tokens[0]; - if (false === strpos($token->getContent(), "\n")) { + if (!str_contains($token->getContent(), "\n")) { $tokens[0] = new Token([$token->getId(), rtrim($token->getContent()).$lineEnding]); } - if (false === strpos($tokens[1]->getContent(), "\n")) { + if (!str_contains($tokens[1]->getContent(), "\n")) { if ($tokens[1]->isWhitespace()) { $tokens[1] = new Token([T_WHITESPACE, $lineEnding.$tokens[1]->getContent()]); } else { diff --git a/src/Fixer/PhpTag/LinebreakAfterOpeningTagFixer.php b/src/Fixer/PhpTag/LinebreakAfterOpeningTagFixer.php index aaacb4f2a08..74727d10168 100644 --- a/src/Fixer/PhpTag/LinebreakAfterOpeningTagFixer.php +++ b/src/Fixer/PhpTag/LinebreakAfterOpeningTagFixer.php @@ -57,13 +57,13 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } // ignore if linebreak already present - if (false !== strpos($tokens[0]->getContent(), "\n")) { + if (str_contains($tokens[0]->getContent(), "\n")) { return; } $newlineFound = false; foreach ($tokens as $token) { - if ($token->isWhitespace() && false !== strpos($token->getContent(), "\n")) { + if ($token->isWhitespace() && str_contains($token->getContent(), "\n")) { $newlineFound = true; break; diff --git a/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php b/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php index 0aeffb63eca..5764d424f34 100644 --- a/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitMethodCasingFixer.php @@ -162,7 +162,7 @@ private function isTestMethod(Tokens $tokens, int $index): bool return $this->isPHPDoc($tokens, $docBlockIndex) // If the function doesn't have test in its name, and no doc block, it's not a test - && false !== strpos($tokens[$docBlockIndex]->getContent(), '@test') + && str_contains($tokens[$docBlockIndex]->getContent(), '@test') ; } @@ -186,7 +186,7 @@ private function updateDocBlock(Tokens $tokens, int $docBlockIndex): void $docBlockNeedsUpdate = false; for ($inc = 0; $inc < \count($lines); ++$inc) { $lineContent = $lines[$inc]->getContent(); - if (false === strpos($lineContent, '@depends')) { + if (!str_contains($lineContent, '@depends')) { continue; } diff --git a/src/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixer.php b/src/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixer.php index e468536025e..0ed433df41e 100644 --- a/src/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixer.php @@ -247,7 +247,7 @@ private function annotationsToParamList(array $annotations): array { $params = []; $exceptionClass = ltrim($annotations['expectedException'], '\\'); - if (false !== strpos($exceptionClass, '*')) { + if (str_contains($exceptionClass, '*')) { $exceptionClass = substr($exceptionClass, 0, strpos($exceptionClass, '*')); } $exceptionClass = trim($exceptionClass); diff --git a/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php b/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php index c3b708b0bb8..0cae5b03bb8 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php @@ -185,7 +185,7 @@ private function isTestMethod(Tokens $tokens, int $index): bool // If the function doesn't have test in its name, and no doc block, its not a test return $this->isPHPDoc($tokens, $docBlockIndex) - && false !== strpos($tokens[$docBlockIndex]->getContent(), '@test') + && str_contains($tokens[$docBlockIndex]->getContent(), '@test') ; } @@ -198,7 +198,7 @@ private function isMethod(Tokens $tokens, int $index): bool private function hasTestPrefix(string $functionName): bool { - return 0 === strpos($functionName, 'test'); + return str_starts_with($functionName, 'test'); } private function hasProperTestAnnotation(Tokens $tokens, int $index): bool @@ -270,15 +270,15 @@ private function updateLines(array $lines, Tokens $tokens, int $docBlockIndex): } if (!$needsAnnotation - && false !== strpos($lines[$i]->getContent(), ' @test') - && false === strpos($lines[$i]->getContent(), '@testWith') - && false === strpos($lines[$i]->getContent(), '@testdox') + && str_contains($lines[$i]->getContent(), ' @test') + && !str_contains($lines[$i]->getContent(), '@testWith') + && !str_contains($lines[$i]->getContent(), '@testdox') ) { // We remove @test from the doc block $lines[$i] = new Line(str_replace(' @test', '', $lines[$i]->getContent())); } // ignore the line if it isn't @depends - if (false === strpos($lines[$i]->getContent(), '@depends')) { + if (!str_contains($lines[$i]->getContent(), '@depends')) { continue; } diff --git a/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php b/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php index 4323a747e99..2539ccd9a34 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php @@ -79,7 +79,7 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en $docContent = $tokens[$docIndex]->getContent(); // ignore one-line phpdocs like `/** foo */`, as there is no place to put new annotations - if (false === strpos($docContent, "\n")) { + if (!str_contains($docContent, "\n")) { return; } diff --git a/src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php b/src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php index a45f36b6a05..9906942957f 100644 --- a/src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php +++ b/src/Fixer/Phpdoc/GeneralPhpdocTagRenameFixer.php @@ -116,7 +116,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn )); } - if (1 !== Preg::match('#^\S+$#', $to) || false !== strpos($to, '*/')) { + if (1 !== Preg::match('#^\S+$#', $to) || str_contains($to, '*/')) { throw new InvalidOptionsException(sprintf( 'Tag "%s" cannot be replaced by invalid tag "%s".', $from, diff --git a/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php b/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php index 9c99630e498..514593d4cb1 100644 --- a/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php +++ b/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php @@ -119,7 +119,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } // ignore one-line phpdocs like `/** foo */`, as there is no place to put new annotations - if (false === strpos($tokenContent, "\n")) { + if (!str_contains($tokenContent, "\n")) { continue; } diff --git a/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php b/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php index 79b900434c2..a7b3d4767db 100644 --- a/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php +++ b/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php @@ -134,12 +134,12 @@ private function applyNoMultiLineFix(Tokens $tokens): void $previousIndex = $index - 1; $previous = $tokens[$previousIndex]; - if (!$previous->isWhitespace() || false === strpos($previous->getContent(), "\n")) { + if (!$previous->isWhitespace() || !str_contains($previous->getContent(), "\n")) { continue; } $content = $previous->getContent(); - if (0 === strpos($content, $lineEnding) && $tokens[$index - 2]->isComment()) { + if (str_starts_with($content, $lineEnding) && $tokens[$index - 2]->isComment()) { $tokens->ensureWhitespaceAtIndex($previousIndex, 0, $lineEnding); } else { $tokens->clearAt($previousIndex); diff --git a/src/Fixer/Strict/DeclareStrictTypesFixer.php b/src/Fixer/Strict/DeclareStrictTypesFixer.php index 077deca99ea..cbb7388a162 100644 --- a/src/Fixer/Strict/DeclareStrictTypesFixer.php +++ b/src/Fixer/Strict/DeclareStrictTypesFixer.php @@ -131,7 +131,7 @@ private function insertSequence(Tokens $tokens): void // start index of the sequence is always 1 here, 0 is always open tag // transform "getContent(), "\n")) { + if (str_contains($tokens[0]->getContent(), "\n")) { $tokens[0] = new Token([$tokens[0]->getId(), trim($tokens[0]->getContent()).' ']); } diff --git a/src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php b/src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php index bcae727af44..d05e5139f92 100644 --- a/src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php +++ b/src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php @@ -110,7 +110,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ($token->equalsAny(['"', 'b"', 'B"'])) { $doubleQuoteOpened = !$doubleQuoteOpened; } - if (!$token->isGivenKind([T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING]) || false === strpos($content, '\\')) { + if (!$token->isGivenKind([T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING]) || !str_contains($content, '\\')) { continue; } diff --git a/src/Fixer/StringNotation/HeredocToNowdocFixer.php b/src/Fixer/StringNotation/HeredocToNowdocFixer.php index 343fad5376d..185cc8bcaae 100644 --- a/src/Fixer/StringNotation/HeredocToNowdocFixer.php +++ b/src/Fixer/StringNotation/HeredocToNowdocFixer.php @@ -71,7 +71,7 @@ public function isCandidate(Tokens $tokens): bool protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { foreach ($tokens as $index => $token) { - if (!$token->isGivenKind(T_START_HEREDOC) || false !== strpos($token->getContent(), "'")) { + if (!$token->isGivenKind(T_START_HEREDOC) || str_contains($token->getContent(), "'")) { continue; } diff --git a/src/Fixer/StringNotation/SingleQuoteFixer.php b/src/Fixer/StringNotation/SingleQuoteFixer.php index 959b8cc6663..b269b418cd7 100644 --- a/src/Fixer/StringNotation/SingleQuoteFixer.php +++ b/src/Fixer/StringNotation/SingleQuoteFixer.php @@ -94,7 +94,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ( '"' === $content[0] - && (true === $this->configuration['strings_containing_single_quote_chars'] || false === strpos($content, "'")) + && (true === $this->configuration['strings_containing_single_quote_chars'] || !str_contains($content, "'")) // regex: odd number of backslashes, not followed by double quote or dollar && !Preg::match('/(?isComment()) { for ($j = $prevNonWhitespace - 1; $j >= 0; --$j) { - if (false !== strpos($tokens[$j]->getContent(), "\n")) { + if (str_contains($tokens[$j]->getContent(), "\n")) { return false; } diff --git a/src/Fixer/Whitespace/IndentationTypeFixer.php b/src/Fixer/Whitespace/IndentationTypeFixer.php index fe69de8d8e0..14a1d29e56b 100644 --- a/src/Fixer/Whitespace/IndentationTypeFixer.php +++ b/src/Fixer/Whitespace/IndentationTypeFixer.php @@ -114,7 +114,7 @@ private function fixIndentToken(Tokens $tokens, int $index): Token $previousTokenHasTrailingLinebreak = false; // @TODO this can be removed when we have a transformer for "T_OPEN_TAG" to "T_OPEN_TAG + T_WHITESPACE" - if (false !== strpos($tokens[$index - 1]->getContent(), "\n")) { + if (str_contains($tokens[$index - 1]->getContent(), "\n")) { $content = "\n".$content; $previousTokenHasTrailingLinebreak = true; } diff --git a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php index 403ddcdaa86..fb183f6514a 100644 --- a/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php +++ b/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php @@ -373,7 +373,7 @@ private function fixAfterToken(int $index): void return; } - if ($this->tokens[$i]->isWhitespace() && false !== strpos($this->tokens[$i]->getContent(), "\n")) { + if ($this->tokens[$i]->isWhitespace() && str_contains($this->tokens[$i]->getContent(), "\n")) { break; } } @@ -400,7 +400,7 @@ private function fixStructureOpenCloseIfMultiLine(int $index): void $bodyEnd = $this->tokens->findBlockEnd($blockTypeInfo['type'], $index); for ($i = $bodyEnd - 1; $i >= $index; --$i) { - if (false !== strpos($this->tokens[$i]->getContent(), "\n")) { + if (str_contains($this->tokens[$i]->getContent(), "\n")) { $this->removeEmptyLinesAfterLineWithTokenAt($i); $this->removeEmptyLinesAfterLineWithTokenAt($index); @@ -416,7 +416,7 @@ private function removeEmptyLinesAfterLineWithTokenAt(int $index): void for ($end = $index; $end < $tokenCount; ++$end) { if ( $this->tokens[$end]->equals('}') - || false !== strpos($this->tokens[$end]->getContent(), "\n") + || str_contains($this->tokens[$end]->getContent(), "\n") ) { break; } diff --git a/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php b/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php index 0ce81c19f1d..998171e0a25 100644 --- a/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php +++ b/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php @@ -104,7 +104,7 @@ private function removeSpaceAroundToken(Tokens $tokens, int $index): void { $token = $tokens[$index]; - if ($token->isWhitespace() && false === strpos($token->getContent(), "\n")) { + if ($token->isWhitespace() && !str_contains($token->getContent(), "\n")) { $tokens->clearAt($index); } } diff --git a/src/Linter/ProcessLinter.php b/src/Linter/ProcessLinter.php index da418ce6f5f..d19b69e2ae7 100644 --- a/src/Linter/ProcessLinter.php +++ b/src/Linter/ProcessLinter.php @@ -60,7 +60,7 @@ public function __construct(?string $executable = null) } if ('phpdbg' === \PHP_SAPI) { - if (false === strpos($executable, 'phpdbg')) { + if (!str_contains($executable, 'phpdbg')) { throw new UnavailableLinterException('Automatically found PHP executable is non-standard phpdbg. Could not find proper PHP executable.'); } diff --git a/src/RuleSet/AbstractRuleSetDescription.php b/src/RuleSet/AbstractRuleSetDescription.php index 4556d0f19bd..d822ffccaf2 100644 --- a/src/RuleSet/AbstractRuleSetDescription.php +++ b/src/RuleSet/AbstractRuleSetDescription.php @@ -32,6 +32,6 @@ public function getName(): string public function isRisky(): bool { - return false !== strpos(static::class, 'Risky'); + return str_contains(static::class, 'Risky'); } } diff --git a/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php b/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php index a2511f56488..01d71bcd4f8 100644 --- a/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php +++ b/src/Tokenizer/Analyzer/Analysis/TypeAnalysis.php @@ -71,7 +71,7 @@ public function __construct(string $name, int $startIndex, int $endIndex) $this->name = $name; $this->nullable = false; - if (0 === strpos($name, '?')) { + if (str_starts_with($name, '?')) { $this->name = substr($name, 1); $this->nullable = true; } diff --git a/src/Tokenizer/Analyzer/CommentsAnalyzer.php b/src/Tokenizer/Analyzer/CommentsAnalyzer.php index 7e0ab311926..47fbbdf0163 100644 --- a/src/Tokenizer/Analyzer/CommentsAnalyzer.php +++ b/src/Tokenizer/Analyzer/CommentsAnalyzer.php @@ -205,7 +205,7 @@ private function isValidControl(Tokens $tokens, Token $docsToken, int $controlIn if ( $token->isGivenKind(T_VARIABLE) - && false !== strpos($docsContent, $token->getContent()) + && str_contains($docsContent, $token->getContent()) ) { return true; } @@ -244,7 +244,7 @@ private function isValidLanguageConstruct(Tokens $tokens, Token $docsToken, int for ($index = $languageConstructIndex + 1; $index < $endIndex; ++$index) { $token = $tokens[$index]; - if ($token->isGivenKind(T_VARIABLE) && false !== strpos($docsContent, $token->getContent())) { + if ($token->isGivenKind(T_VARIABLE) && str_contains($docsContent, $token->getContent())) { return true; } } diff --git a/src/Tokenizer/Analyzer/WhitespacesAnalyzer.php b/src/Tokenizer/Analyzer/WhitespacesAnalyzer.php index 7b1d596368d..0845ce40336 100644 --- a/src/Tokenizer/Analyzer/WhitespacesAnalyzer.php +++ b/src/Tokenizer/Analyzer/WhitespacesAnalyzer.php @@ -32,7 +32,7 @@ public static function detectIndent(Tokens $tokens, int $index): string $whitespaceToken = $tokens[$whitespaceIndex]; - if (false !== strpos($whitespaceToken->getContent(), "\n")) { + if (str_contains($whitespaceToken->getContent(), "\n")) { break; } diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index 9b88119488f..be5b10b4190 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -365,7 +365,7 @@ public function ensureWhitespaceAtIndex(int $index, int $indexOffset, string $wh $token = $tokens[$index]; if (1 === $indexOffset && $token->isGivenKind(T_OPEN_TAG)) { - if (0 === strpos($whitespace, "\r\n")) { + if (str_starts_with($whitespace, "\r\n")) { $tokens[$index] = new Token([T_OPEN_TAG, rtrim($token->getContent())."\r\n"]); return \strlen($whitespace) > 2 // can be removed on PHP 7; https://php.net/manual/en/function.substr.php @@ -1103,7 +1103,7 @@ public function isMonolithicPhp(): bool public function isPartialCodeMultiline(int $start, int $end): bool { for ($i = $start; $i <= $end; ++$i) { - if (false !== strpos($this[$i]->getContent(), "\n")) { + if (str_contains($this[$i]->getContent(), "\n")) { return true; } } diff --git a/src/Tokenizer/TokensAnalyzer.php b/src/Tokenizer/TokensAnalyzer.php index 8ec5a97e3c0..8a58f7d8881 100644 --- a/src/Tokenizer/TokensAnalyzer.php +++ b/src/Tokenizer/TokensAnalyzer.php @@ -164,7 +164,7 @@ public function isBlockMultiline(Tokens $tokens, int $index): bool if ( $token->isWhitespace() && !$tokens[$index - 1]->isGivenKind(T_END_HEREDOC) - && false !== strpos($token->getContent(), "\n") + && str_contains($token->getContent(), "\n") ) { return true; } diff --git a/tests/AutoReview/CommandTest.php b/tests/AutoReview/CommandTest.php index 5135701de93..d419bf3420f 100644 --- a/tests/AutoReview/CommandTest.php +++ b/tests/AutoReview/CommandTest.php @@ -47,7 +47,7 @@ public function provideCommandHasNameConstCases(): array // is not an alias !\in_array($name, $commands[$name]->getAliases(), true) // and is our command - && 0 === strpos(\get_class($commands[$name]), 'PhpCsFixer\\') + && str_starts_with(\get_class($commands[$name]), 'PhpCsFixer\\') ; }); diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 17437b7409f..7797e2a74d8 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -326,7 +326,7 @@ public function provideFixersPrioritySpecialPhpdocCases() $docFixerNames = array_filter( array_keys($fixers), static function (string $name): bool { - return false !== strpos($name, 'phpdoc'); + return str_contains($name, 'phpdoc'); } ); diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index 93cb6e229ed..8affe78b65a 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -671,7 +671,7 @@ public function providePhpUnitFixerExtendsAbstractPhpUnitFixerCases(): \Generato $factory->registerBuiltInFixers(); foreach ($factory->getFixers() as $fixer) { - if (0 !== strpos($fixer->getName(), 'php_unit_')) { + if (!str_starts_with($fixer->getName(), 'php_unit_')) { continue; } diff --git a/tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php b/tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php index 4bf04e45612..3f7227a06c0 100644 --- a/tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php +++ b/tests/Fixer/ControlStructure/NoUnneededControlParenthesesFixerTest.php @@ -507,7 +507,7 @@ private function fixerTest(string $expected, ?string $input = null, ?string $fix if ($input && (!$fixStatement || $fixStatement === $statement)) { foreach (explode('_', $statement) as $singleStatement) { - if (false !== strpos($input, $singleStatement)) { + if (str_contains($input, $singleStatement)) { $withInput = true; break; diff --git a/tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php b/tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php index 59092a7d841..32f87792e5f 100644 --- a/tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php +++ b/tests/Fixer/FunctionNotation/MethodArgumentSpaceFixerTest.php @@ -40,13 +40,13 @@ public function testFix(string $expected, ?string $input = null, array $configur $indent = ' '; $lineEnding = "\n"; - if (false !== strpos($expected, "\t")) { + if (str_contains($expected, "\t")) { $indent = "\t"; } elseif (preg_match('/\n \S/', $expected)) { $indent = ' '; } - if (false !== strpos($expected, "\r")) { + if (str_contains($expected, "\r")) { $lineEnding = "\r\n"; } diff --git a/tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php index 84a8f073252..6088d72cf9f 100644 --- a/tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitConstructFixerTest.php @@ -43,7 +43,7 @@ public function testFix(string $expected, ?string $input = null): void $this->fixer->configure(['assertions' => [$method]]); $this->doTest( $expected, - $input && false !== strpos($input, $method) ? $input : null + $input && str_contains($input, $method) ? $input : null ); } } diff --git a/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php index a256ff6940a..2d02d477e15 100644 --- a/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php @@ -272,7 +272,7 @@ public static function provideClassIsFixedCases(): \Generator $classmap = require __DIR__.'/../../../vendor/composer/autoload_classmap.php'; foreach (array_keys($classmap) as $class) { - if (0 !== strpos($class, 'PHPUnit_')) { + if (!str_starts_with($class, 'PHPUnit_')) { continue; } yield [$class]; diff --git a/tests/Fixer/Whitespace/IndentationTypeFixerTest.php b/tests/Fixer/Whitespace/IndentationTypeFixerTest.php index 0ff2ffed5aa..231e1dd6893 100644 --- a/tests/Fixer/Whitespace/IndentationTypeFixerTest.php +++ b/tests/Fixer/Whitespace/IndentationTypeFixerTest.php @@ -312,7 +312,7 @@ public function provideMessyWhitespacesReversedCases() return array_filter( $this->provideMessyWhitespacesCases(), static function (string $key): bool { - return false === strpos($key, 'mix indentation'); + return !str_contains($key, 'mix indentation'); }, ARRAY_FILTER_USE_KEY ); diff --git a/tests/FixerFactoryTest.php b/tests/FixerFactoryTest.php index cf69927bb3b..df72d0d921d 100644 --- a/tests/FixerFactoryTest.php +++ b/tests/FixerFactoryTest.php @@ -74,7 +74,7 @@ public function testRegisterBuiltInFixers(): void static function (string $className): bool { $class = new \ReflectionClass($className); - return !$class->isAbstract() && $class->implementsInterface(FixerInterface::class) && 0 === strpos($class->getNamespaceName(), 'PhpCsFixer\\Fixer\\'); + return !$class->isAbstract() && $class->implementsInterface(FixerInterface::class) && str_starts_with($class->getNamespaceName(), 'PhpCsFixer\\Fixer\\'); } ); diff --git a/tests/RuleSet/RuleSetTest.php b/tests/RuleSet/RuleSetTest.php index 44d7894d09b..89c783842ce 100644 --- a/tests/RuleSet/RuleSetTest.php +++ b/tests/RuleSet/RuleSetTest.php @@ -292,7 +292,7 @@ public function provideSafeSetCases(): \Generator foreach (RuleSets::getSetDefinitionNames() as $name) { yield $name => [ [$name => true], - false === strpos($name, ':risky'), + !str_contains($name, ':risky'), ]; } From 0b64c2a5cf1f9f5538e9fc13a0640c5c854f5f80 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Mon, 6 Sep 2021 20:44:20 +0200 Subject: [PATCH 68/80] Tree shake PHP8.1 PRs --- src/AbstractPhpdocTypesFixer.php | 9 ++- src/DocBlock/DocBlock.php | 4 +- .../ArrayNotation/TrimArraySpacesFixer.php | 2 +- src/Fixer/Casing/MagicMethodCasingFixer.php | 3 +- .../ClassNotation/ClassDefinitionFixer.php | 4 +- .../OrderedClassElementsFixer.php | 9 ++- .../NoTrailingWhitespaceInCommentFixer.php | 2 +- .../Comment/SingleLineCommentStyleFixer.php | 2 +- .../NoAlternativeSyntaxFixer.php | 10 ++- .../PhpdocAnnotationWithoutDotFixer.php | 2 +- .../Phpdoc/PhpdocReturnSelfReferenceFixer.php | 5 +- src/Fixer/Phpdoc/PhpdocTypesFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php | 2 +- .../SimpleToComplexStringVariableFixer.php | 2 +- .../AbstractMigrationSetDescription.php | 38 +++++++++++ src/RuleSet/Sets/PHP54MigrationSet.php | 9 +-- src/RuleSet/Sets/PHP56MigrationRiskySet.php | 9 +-- src/RuleSet/Sets/PHP70MigrationRiskySet.php | 9 +-- src/RuleSet/Sets/PHP70MigrationSet.php | 9 +-- src/RuleSet/Sets/PHP71MigrationRiskySet.php | 9 +-- src/RuleSet/Sets/PHP71MigrationSet.php | 9 +-- src/RuleSet/Sets/PHP73MigrationSet.php | 9 +-- src/RuleSet/Sets/PHP74MigrationRiskySet.php | 9 +-- src/RuleSet/Sets/PHP74MigrationSet.php | 9 +-- src/RuleSet/Sets/PHP80MigrationRiskySet.php | 9 +-- src/RuleSet/Sets/PHP80MigrationSet.php | 9 +-- .../Sets/PHPUnit30MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit32MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit35MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit43MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit48MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit50MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit52MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit54MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit55MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit56MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit57MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit60MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit75MigrationRiskySet.php | 9 +-- .../Sets/PHPUnit84MigrationRiskySet.php | 9 +-- src/Tokenizer/Tokens.php | 2 +- src/ToolInfo.php | 2 +- tests/AutoReview/FixerFactoryTest.php | 4 +- tests/AutoReview/ProjectCodeTest.php | 64 ++++++++++++------- .../ProjectFixerConfigurationTest.php | 2 - tests/AutoReview/TransformerTest.php | 1 - ...dForEnvFixerConfigurationExceptionTest.php | 2 - tests/Console/ApplicationTest.php | 2 - .../Console/Command/SelfUpdateCommandTest.php | 4 +- tests/Console/Output/ErrorOutputTest.php | 2 - tests/Console/Output/NullOutputTest.php | 2 - .../Report/FixReport/ReportSummaryTest.php | 2 - tests/Differ/DiffConsoleFormatterTest.php | 2 - tests/Differ/FullDifferTest.php | 2 - tests/Differ/UnifiedDifferTest.php | 2 - tests/Fixer/Alias/ArrayPushFixerTest.php | 2 - .../NoAliasLanguageConstructCallFixerTest.php | 2 - .../Fixer/Alias/NoMixedEchoPrintFixerTest.php | 3 +- .../Alias/PowToExponentiationFixerTest.php | 2 - tests/Fixer/Alias/SetTypeToCastFixerTest.php | 2 - .../ArrayNotation/ArraySyntaxFixerTest.php | 1 - tests/Fixer/Casing/ConstantCaseFixerTest.php | 10 ++- .../Casing/MagicMethodCasingFixerTest.php | 2 - .../Casing/NativeFunctionCasingFixerTest.php | 2 - ...FunctionTypeDeclarationCasingFixerTest.php | 2 - .../CastNotation/LowercaseCastFixerTest.php | 2 - .../ModernizeTypesCastingFixerTest.php | 4 +- .../CastNotation/ShortScalarCastFixerTest.php | 2 - .../ClassDefinitionFixerTest.php | 2 - .../FinalInternalClassFixerTest.php | 2 - ...SingleTraitInsertPerStatementFixerTest.php | 2 - .../VisibilityRequiredFixerTest.php | 1 - .../Fixer/Comment/NoEmptyCommentFixerTest.php | 2 - .../EmptyLoopBodyFixerTest.php | 2 - .../EmptyLoopConditionFixerTest.php | 2 - .../ControlStructure/IncludeFixerTest.php | 1 - .../NoBreakCommentFixerTest.php | 5 +- .../NoUnneededCurlyBracesFixerTest.php | 2 - .../NoUselessElseFixerTest.php | 2 - .../SwitchCaseSemicolonToColonFixerTest.php | 2 - .../ControlStructure/YodaStyleFixerTest.php | 1 - .../FopenFlagOrderFixerTest.php | 2 - .../FunctionNotation/FopenFlagsFixerTest.php | 2 - .../LambdaNotUsedImportFixerTest.php | 2 - .../NativeFunctionInvocationFixerTest.php | 3 +- ...eclarationForDefaultNullValueFixerTest.php | 4 +- .../StaticLambdaFixerTest.php | 2 - .../SingleImportPerStatementFixerTest.php | 1 - .../CombineConsecutiveIssetsFixerTest.php | 2 - .../CombineConsecutiveUnsetsFixerTest.php | 2 - .../DeclareEqualNormalizeFixerTest.php | 1 - .../FunctionToConstantFixerTest.php | 2 - .../ListNotation/ListSyntaxFixerTest.php | 4 +- .../BinaryOperatorSpacesFixerTest.php | 1 - tests/Fixer/Operator/ConcatSpaceFixerTest.php | 1 - .../TernaryToElvisOperatorFixerTest.php | 2 - .../PhpUnitDedicateAssertFixerTest.php | 2 - tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php | 2 - .../PhpdocInlineTagNormalizerFixerTest.php | 4 +- .../Phpdoc/PhpdocNoAliasTagFixerTest.php | 1 - .../PhpdocNoUselessInheritdocFixerTest.php | 2 - .../PhpdocReturnSelfReferenceFixerTest.php | 2 - .../PhpdocSingleLineVarSpacingFixerTest.php | 2 - .../NoUselessReturnFixerTest.php | 2 - .../ReturnAssignmentFixerTest.php | 2 - .../Semicolon/NoEmptyStatementFixerTest.php | 1 - .../SemicolonAfterInstructionFixerTest.php | 2 - .../SpaceAfterSemicolonFixerTest.php | 2 - .../Strict/DeclareStrictTypesFixerTest.php | 2 - .../BlankLineBeforeStatementFixerTest.php | 1 - .../Fixer/Whitespace/LineEndingFixerTest.php | 1 - .../Whitespace/NoExtraBlankLinesFixerTest.php | 2 +- .../FixerConfigurationResolverTest.php | 2 +- .../InvalidOptionsForEnvExceptionTest.php | 2 - tests/FixerFileProcessedEventTest.php | 2 - tests/Fixtures/.php-cs-fixer.custom.php | 4 +- .../Fixtures/FixCommand/TextDiffTestInput.php | 2 - tests/Fixtures/Integration/misc/PHP8_1.test | 6 ++ .../Integration/set/@PSR12_php71.test-in.php | 1 + .../Integration/set/@PSR12_php71.test-out.php | 1 + .../PhpUnitTestCaseIndicatorTest.php | 2 - tests/IntegrationTest.php | 2 - tests/Linter/ProcessLintingResultTest.php | 2 - tests/Linter/TokenizerLintingResultTest.php | 2 - tests/PharCheckerTest.php | 2 - tests/RuleSet/RuleSetsTest.php | 2 +- tests/RuleSet/Sets/AbstractSetTest.php | 4 +- tests/Runner/FileFilterIteratorTest.php | 2 - tests/Runner/FileLintingIteratorTest.php | 2 - tests/Smoke/InstallViaComposerTest.php | 2 +- tests/Test/AbstractFixerTestCase.php | 2 +- tests/Test/AbstractIntegrationTestCase.php | 2 - tests/Test/IntegrationCase.php | 16 ++--- tests/TextDiffTest.php | 2 - tests/Tokenizer/AbstractTransformerTest.php | 2 - .../Analyzer/CommentsAnalyzerTest.php | 1 - .../Analyzer/FunctionsAnalyzerTest.php | 5 ++ tests/Tokenizer/CodeHasherTest.php | 2 - tests/Tokenizer/TokensAnalyzerTest.php | 1 - tests/Tokenizer/TokensTest.php | 1 - .../SquareBraceTransformerTest.php | 1 - tests/ToolInfoTest.php | 2 - 142 files changed, 210 insertions(+), 408 deletions(-) create mode 100644 src/RuleSet/AbstractMigrationSetDescription.php diff --git a/src/AbstractPhpdocTypesFixer.php b/src/AbstractPhpdocTypesFixer.php index fa9b0bb250b..844ef7e2943 100644 --- a/src/AbstractPhpdocTypesFixer.php +++ b/src/AbstractPhpdocTypesFixer.php @@ -120,10 +120,9 @@ private function normalizeTypes(array $types): array */ private function normalizeType(string $type): string { - if ('[]' === substr($type, -2)) { - return $this->normalizeType(substr($type, 0, -2)).'[]'; - } - - return $this->normalize($type); + return str_ends_with($type, '[]') + ? $this->normalizeType(substr($type, 0, -2)).'[]' + : $this->normalize($type) + ; } } diff --git a/src/DocBlock/DocBlock.php b/src/DocBlock/DocBlock.php index ccdfe82723e..e73fd6a81f5 100644 --- a/src/DocBlock/DocBlock.php +++ b/src/DocBlock/DocBlock.php @@ -253,9 +253,9 @@ private function getSingleLineDocBlockEntry(Line $line): string $lineString = str_replace('*/', '', $lineString); $lineString = trim($lineString); - if ('/**' === substr($lineString, 0, 3)) { + if (str_starts_with($lineString, '/**')) { $lineString = substr($lineString, 3); - } elseif ('*' === substr($lineString, 0, 1)) { + } elseif (str_starts_with($lineString, '*')) { $lineString = substr($lineString, 1); } diff --git a/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php b/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php index 00f0d114c86..d2e19bfb7ac 100644 --- a/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php +++ b/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php @@ -88,7 +88,7 @@ private static function fixArray(Tokens $tokens, int $index): void !$nextNonWhitespaceToken->isComment() || $nextNonWhitespaceIndex === $prevNonWhitespaceIndex || $tokenAfterNextNonWhitespaceToken->isWhitespace(" \t") - || '/*' === substr($nextNonWhitespaceToken->getContent(), 0, 2) + || str_starts_with($nextNonWhitespaceToken->getContent(), '/*') ) ) { $tokens->clearAt($nextIndex); diff --git a/src/Fixer/Casing/MagicMethodCasingFixer.php b/src/Fixer/Casing/MagicMethodCasingFixer.php index c5bf50e6b36..b0611219dbd 100644 --- a/src/Fixer/Casing/MagicMethodCasingFixer.php +++ b/src/Fixer/Casing/MagicMethodCasingFixer.php @@ -113,7 +113,8 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $content = $tokens[$index]->getContent(); - if ('__' !== substr($content, 0, 2)) { + + if (!str_starts_with($content, '__')) { continue; // cheap look ahead } diff --git a/src/Fixer/ClassNotation/ClassDefinitionFixer.php b/src/Fixer/ClassNotation/ClassDefinitionFixer.php index 428db45251f..1ed02a79411 100644 --- a/src/Fixer/ClassNotation/ClassDefinitionFixer.php +++ b/src/Fixer/ClassNotation/ClassDefinitionFixer.php @@ -330,10 +330,10 @@ private function makeClassyDefinitionSingleLine(Tokens $tokens, int $startIndex, if ($tokens[$i - 1]->isComment() || $tokens[$i + 1]->isComment()) { $content = $tokens[$i - 1]->getContent(); - if (!('#' === $content || '//' === substr($content, 0, 2))) { + if (!('#' === $content || str_starts_with($content, '//'))) { $content = $tokens[$i + 1]->getContent(); - if (!('#' === $content || '//' === substr($content, 0, 2))) { + if (!('#' === $content || str_starts_with($content, '//'))) { $tokens[$i] = new Token([T_WHITESPACE, ' ']); } } diff --git a/src/Fixer/ClassNotation/OrderedClassElementsFixer.php b/src/Fixer/ClassNotation/OrderedClassElementsFixer.php index 5ae0cdb7357..5108ca2aa61 100644 --- a/src/Fixer/ClassNotation/OrderedClassElementsFixer.php +++ b/src/Fixer/ClassNotation/OrderedClassElementsFixer.php @@ -401,11 +401,10 @@ private function detectElementType(Tokens $tokens, int $index) return ['phpunit', strtolower($nameToken->getContent())]; } - if ('__' === substr($nameToken->getContent(), 0, 2)) { - return 'magic'; - } - - return 'method'; + return str_starts_with($nameToken->getContent(), '__') + ? 'magic' + : 'method' + ; } private function findElementEnd(Tokens $tokens, int $index): int diff --git a/src/Fixer/Comment/NoTrailingWhitespaceInCommentFixer.php b/src/Fixer/Comment/NoTrailingWhitespaceInCommentFixer.php index eac9a969485..9e893ff7b02 100644 --- a/src/Fixer/Comment/NoTrailingWhitespaceInCommentFixer.php +++ b/src/Fixer/Comment/NoTrailingWhitespaceInCommentFixer.php @@ -72,7 +72,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } if ($token->isGivenKind(T_COMMENT)) { - if ('/*' === substr($token->getContent(), 0, 2)) { + if (str_starts_with($token->getContent(), '/*')) { $tokens[$index] = new Token([T_COMMENT, Preg::replace('/(*ANY)[\h]+$/m', '', $token->getContent())]); } elseif (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) { $trimmedContent = ltrim($tokens[$index + 1]->getContent(), " \t"); diff --git a/src/Fixer/Comment/SingleLineCommentStyleFixer.php b/src/Fixer/Comment/SingleLineCommentStyleFixer.php index 91fb80431c6..09fabc7b1c2 100644 --- a/src/Fixer/Comment/SingleLineCommentStyleFixer.php +++ b/src/Fixer/Comment/SingleLineCommentStyleFixer.php @@ -146,7 +146,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ( !$this->asteriskEnabled || str_contains($commentContent, '?>') - || '/*' !== substr($content, 0, 2) + || !str_starts_with($content, '/*') || 1 === Preg::match('/[^\s\*].*\R.*[^\s\*]/s', $commentContent) ) { continue; diff --git a/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php b/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php index 38bf6c111e7..e94a21bfab6 100644 --- a/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php +++ b/src/Fixer/ControlStructure/NoAlternativeSyntaxFixer.php @@ -98,12 +98,10 @@ private function findParenthesisEnd(Tokens $tokens, int $structureTokenIndex): i $nextIndex = $tokens->getNextMeaningfulToken($structureTokenIndex); $nextToken = $tokens[$nextIndex]; - // return if next token is not opening parenthesis - if (!$nextToken->equals('(')) { - return $structureTokenIndex; - } - - return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex); + return $nextToken->equals('(') + ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex) + : $structureTokenIndex // return if next token is not opening parenthesis + ; } /** diff --git a/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php b/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php index eadade37bf7..3a5516adac8 100644 --- a/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php +++ b/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php @@ -119,7 +119,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void : ''; $content = Preg::replaceCallback( '/^(\s*\*\s*@\w+\s+'.$optionalTypeRegEx.')(\p{Lu}?(?=\p{Ll}|\p{Zs}))(.*)$/', - static function (array $matches) { + static function (array $matches): string { if (\function_exists('mb_strtolower')) { return $matches[1].mb_strtolower($matches[2]).$matches[3]; } diff --git a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php index 2d959099195..e2b6b3f7b49 100644 --- a/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php +++ b/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php @@ -147,8 +147,9 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn return new FixerConfigurationResolver([ (new FixerOptionBuilder('replacements', 'Mapping between replaced return types with new ones.')) ->setAllowedTypes(['array']) - ->setNormalizer(static function (Options $options, $value) use ($default) { + ->setNormalizer(static function (Options $options, array $value) use ($default): array { $normalizedValue = []; + foreach ($value as $from => $to) { if (\is_string($from)) { $from = strtolower($from); @@ -157,7 +158,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn if (!isset($default[$from])) { throw new InvalidOptionsException(sprintf( 'Unknown key "%s", expected any of "%s".', - \is_object($from) ? \get_class($from) : \gettype($from).(\is_resource($from) ? '' : '#'.$from), + \gettype($from).'#'.$from, implode('", "', array_keys($default)) )); } diff --git a/src/Fixer/Phpdoc/PhpdocTypesFixer.php b/src/Fixer/Phpdoc/PhpdocTypesFixer.php index 7abebd358e0..7371b6b3fd1 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesFixer.php @@ -80,7 +80,7 @@ public function configure(array $configuration): void { parent::configure($configuration); - $this->typesToFix = array_merge(...array_map(static function (string $group) { + $this->typesToFix = array_merge(...array_map(static function (string $group): array { return self::$possibleTypes[$group]; }, $this->configuration['groups'])); } diff --git a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php index 8596815da13..01437fa413c 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php @@ -147,7 +147,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // fix @method parameters types $line = $doc->getLine($annotation->getStart()); $line->setContent(Preg::replaceCallback('/(@method\s+.+?\s+\w+\()(.*)\)/', function (array $matches) { - $sorted = Preg::replaceCallback('/([^\s,]+)([\s]+\$[^\s,]+)/', function (array $matches) { + $sorted = Preg::replaceCallback('/([^\s,]+)([\s]+\$[^\s,]+)/', function (array $matches): string { return $this->sortJoinedTypes($matches[1]).$matches[2]; }, $matches[2]); diff --git a/src/Fixer/StringNotation/SimpleToComplexStringVariableFixer.php b/src/Fixer/StringNotation/SimpleToComplexStringVariableFixer.php index 8ad39153d4a..53ccabae3bf 100644 --- a/src/Fixer/StringNotation/SimpleToComplexStringVariableFixer.php +++ b/src/Fixer/StringNotation/SimpleToComplexStringVariableFixer.php @@ -100,7 +100,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $tokenOfStringBeforeToken = $tokens[$index - 1]; $stringContent = $tokenOfStringBeforeToken->getContent(); - if ('$' === substr($stringContent, -1) && '\\$' !== substr($stringContent, -2)) { + if (str_ends_with($stringContent, '$') && !str_ends_with($stringContent, '\\$')) { $newContent = substr($stringContent, 0, -1).'\\$'; $tokenOfStringBeforeToken = new Token([T_ENCAPSED_AND_WHITESPACE, $newContent]); } diff --git a/src/RuleSet/AbstractMigrationSetDescription.php b/src/RuleSet/AbstractMigrationSetDescription.php new file mode 100644 index 00000000000..9c36c3c79b1 --- /dev/null +++ b/src/RuleSet/AbstractMigrationSetDescription.php @@ -0,0 +1,38 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\RuleSet; + +use PhpCsFixer\Preg; + +/** + * @internal + */ +abstract class AbstractMigrationSetDescription extends AbstractRuleSetDescription +{ + public function getDescription(): string + { + $name = $this->getName(); + + if (0 !== Preg::match('#^@PHPUnit([\d]{2})Migration.*$#', $name, $matches)) { + return sprintf('Rules to improve tests code for PHPUnit %d.%d compatibility.', $matches[1][0], $matches[1][1]); + } + + if (0 !== Preg::match('#^@PHP([\d]{2})Migration.*$#', $name, $matches)) { + return sprintf('Rules to improve code for PHP %d.%d compatibility.', $matches[1][0], $matches[1][1]); + } + + throw new \RuntimeException(sprintf('Cannot generate description for "%s" "%s".', static::class, $name)); + } +} diff --git a/src/RuleSet/Sets/PHP54MigrationSet.php b/src/RuleSet/Sets/PHP54MigrationSet.php index 7986c7471b4..bb877922220 100644 --- a/src/RuleSet/Sets/PHP54MigrationSet.php +++ b/src/RuleSet/Sets/PHP54MigrationSet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP54MigrationSet extends AbstractRuleSetDescription +final class PHP54MigrationSet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -27,9 +27,4 @@ public function getRules(): array 'array_syntax' => true, ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 5.4 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP56MigrationRiskySet.php b/src/RuleSet/Sets/PHP56MigrationRiskySet.php index 0b8127b6d9b..848b3501ebd 100644 --- a/src/RuleSet/Sets/PHP56MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHP56MigrationRiskySet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP56MigrationRiskySet extends AbstractRuleSetDescription +final class PHP56MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -27,9 +27,4 @@ public function getRules(): array 'pow_to_exponentiation' => true, ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 5.6 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP70MigrationRiskySet.php b/src/RuleSet/Sets/PHP70MigrationRiskySet.php index 9a1f88ec332..a7fcb21160c 100644 --- a/src/RuleSet/Sets/PHP70MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHP70MigrationRiskySet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP70MigrationRiskySet extends AbstractRuleSetDescription +final class PHP70MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -36,9 +36,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 7.0 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP70MigrationSet.php b/src/RuleSet/Sets/PHP70MigrationSet.php index 0775376700d..62b0ad99176 100644 --- a/src/RuleSet/Sets/PHP70MigrationSet.php +++ b/src/RuleSet/Sets/PHP70MigrationSet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP70MigrationSet extends AbstractRuleSetDescription +final class PHP70MigrationSet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -28,9 +28,4 @@ public function getRules(): array 'ternary_to_null_coalescing' => true, ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 7.0 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP71MigrationRiskySet.php b/src/RuleSet/Sets/PHP71MigrationRiskySet.php index 632b203a4d9..5a57f26246b 100644 --- a/src/RuleSet/Sets/PHP71MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHP71MigrationRiskySet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP71MigrationRiskySet extends AbstractRuleSetDescription +final class PHP71MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -28,9 +28,4 @@ public function getRules(): array 'void_return' => true, ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 7.1 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP71MigrationSet.php b/src/RuleSet/Sets/PHP71MigrationSet.php index 6f06df387ac..9379628dc65 100644 --- a/src/RuleSet/Sets/PHP71MigrationSet.php +++ b/src/RuleSet/Sets/PHP71MigrationSet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP71MigrationSet extends AbstractRuleSetDescription +final class PHP71MigrationSet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -29,9 +29,4 @@ public function getRules(): array 'visibility_required' => true, ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 7.1 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP73MigrationSet.php b/src/RuleSet/Sets/PHP73MigrationSet.php index 3b4ca5e99bb..aa0ed8fb255 100644 --- a/src/RuleSet/Sets/PHP73MigrationSet.php +++ b/src/RuleSet/Sets/PHP73MigrationSet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP73MigrationSet extends AbstractRuleSetDescription +final class PHP73MigrationSet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array 'trailing_comma_in_multiline' => ['after_heredoc' => true], ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 7.3 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP74MigrationRiskySet.php b/src/RuleSet/Sets/PHP74MigrationRiskySet.php index 078d577b57e..0a1bc17dd3a 100644 --- a/src/RuleSet/Sets/PHP74MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHP74MigrationRiskySet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP74MigrationRiskySet extends AbstractRuleSetDescription +final class PHP74MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -30,9 +30,4 @@ public function getRules(): array 'use_arrow_functions' => true, ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 7.4 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP74MigrationSet.php b/src/RuleSet/Sets/PHP74MigrationSet.php index e0d8af27b1e..09d372f4f3d 100644 --- a/src/RuleSet/Sets/PHP74MigrationSet.php +++ b/src/RuleSet/Sets/PHP74MigrationSet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP74MigrationSet extends AbstractRuleSetDescription +final class PHP74MigrationSet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -29,9 +29,4 @@ public function getRules(): array 'short_scalar_cast' => true, ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 7.4 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP80MigrationRiskySet.php b/src/RuleSet/Sets/PHP80MigrationRiskySet.php index 23970d6ffbf..e3daabf5284 100644 --- a/src/RuleSet/Sets/PHP80MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHP80MigrationRiskySet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP80MigrationRiskySet extends AbstractRuleSetDescription +final class PHP80MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -36,9 +36,4 @@ public function getRules(): array 'no_unreachable_default_argument_value' => true, ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 8.0 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHP80MigrationSet.php b/src/RuleSet/Sets/PHP80MigrationSet.php index 43f3a9fb79c..8b49a55c6b6 100644 --- a/src/RuleSet/Sets/PHP80MigrationSet.php +++ b/src/RuleSet/Sets/PHP80MigrationSet.php @@ -14,12 +14,12 @@ namespace PhpCsFixer\RuleSet\Sets; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHP80MigrationSet extends AbstractRuleSetDescription +final class PHP80MigrationSet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -29,9 +29,4 @@ public function getRules(): array 'no_unset_cast' => true, ]; } - - public function getDescription(): string - { - return 'Rules to improve code for PHP 8.0 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit30MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit30MigrationRiskySet.php index 753b3db166a..1cabfc04b92 100644 --- a/src/RuleSet/Sets/PHPUnit30MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit30MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit30MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit30MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -30,9 +30,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 3.0 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit32MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit32MigrationRiskySet.php index 265c5be9bb5..fb4cbfb5797 100644 --- a/src/RuleSet/Sets/PHPUnit32MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit32MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit32MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit32MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 3.2 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit35MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit35MigrationRiskySet.php index 3e5e45a52e4..6a52afac5af 100644 --- a/src/RuleSet/Sets/PHPUnit35MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit35MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit35MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit35MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 3.5 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit43MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit43MigrationRiskySet.php index 4945ef1cf95..13927970c9e 100644 --- a/src/RuleSet/Sets/PHPUnit43MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit43MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit43MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit43MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 4.3 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit48MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit48MigrationRiskySet.php index 6c84b021965..fcb1b57e6c5 100644 --- a/src/RuleSet/Sets/PHPUnit48MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit48MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit48MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit48MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 4.8 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit50MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit50MigrationRiskySet.php index 93de1083f54..38474584b17 100644 --- a/src/RuleSet/Sets/PHPUnit50MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit50MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit50MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit50MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 5.0 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit52MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit52MigrationRiskySet.php index a170c28ed39..d0f71ee3bf5 100644 --- a/src/RuleSet/Sets/PHPUnit52MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit52MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit52MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit52MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 5.2 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit54MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit54MigrationRiskySet.php index fa1ee5b0e20..b7c87922dcc 100644 --- a/src/RuleSet/Sets/PHPUnit54MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit54MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit54MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit54MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 5.4 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit55MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit55MigrationRiskySet.php index b895d2e49a0..e3c1647de4a 100644 --- a/src/RuleSet/Sets/PHPUnit55MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit55MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit55MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit55MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 5.5 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit56MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit56MigrationRiskySet.php index f58cff53cfb..a1038bf809c 100644 --- a/src/RuleSet/Sets/PHPUnit56MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit56MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit56MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit56MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -34,9 +34,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 5.6 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit57MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit57MigrationRiskySet.php index 5fcd183a79c..84076e119dd 100644 --- a/src/RuleSet/Sets/PHPUnit57MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit57MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit57MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit57MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 5.7 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit60MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit60MigrationRiskySet.php index 8894febd331..6bc7f711059 100644 --- a/src/RuleSet/Sets/PHPUnit60MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit60MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit60MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit60MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 6.0 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit75MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit75MigrationRiskySet.php index 43ff35a4c7e..a7efa2347aa 100644 --- a/src/RuleSet/Sets/PHPUnit75MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit75MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit75MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit75MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -31,9 +31,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 7.5 compatibility.'; - } } diff --git a/src/RuleSet/Sets/PHPUnit84MigrationRiskySet.php b/src/RuleSet/Sets/PHPUnit84MigrationRiskySet.php index cab174a070c..aaf5fc312ac 100644 --- a/src/RuleSet/Sets/PHPUnit84MigrationRiskySet.php +++ b/src/RuleSet/Sets/PHPUnit84MigrationRiskySet.php @@ -15,12 +15,12 @@ namespace PhpCsFixer\RuleSet\Sets; use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion; -use PhpCsFixer\RuleSet\AbstractRuleSetDescription; +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; /** * @internal */ -final class PHPUnit84MigrationRiskySet extends AbstractRuleSetDescription +final class PHPUnit84MigrationRiskySet extends AbstractMigrationSetDescription { public function getRules(): array { @@ -32,9 +32,4 @@ public function getRules(): array ], ]; } - - public function getDescription(): string - { - return 'Rules to improve tests code for PHPUnit 8.4 compatibility.'; - } } diff --git a/src/Tokenizer/Tokens.php b/src/Tokenizer/Tokens.php index be5b10b4190..5c56efe33ed 100644 --- a/src/Tokenizer/Tokens.php +++ b/src/Tokenizer/Tokens.php @@ -587,7 +587,7 @@ public function getPrevTokenOfKind(int $index, array $tokens = [], bool $caseSen */ public function getTokenOfKindSibling(int $index, int $direction, array $tokens = [], bool $caseSensitive = true): ?int { - $tokens = array_filter($tokens, function ($token) { + $tokens = array_filter($tokens, function ($token): bool { return $this->isTokenKindFound($this->extractTokenKind($token)); }); diff --git a/src/ToolInfo.php b/src/ToolInfo.php index 554f9f4ca1c..f8e2aba388e 100644 --- a/src/ToolInfo.php +++ b/src/ToolInfo.php @@ -86,7 +86,7 @@ public function getVersion(): string public function isInstalledAsPhar(): bool { - return 'phar://' === substr(__DIR__, 0, 7); + return str_starts_with(__DIR__, 'phar://'); } public function isInstalledByComposer(): bool diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 7797e2a74d8..3059547d88b 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -51,7 +51,7 @@ public function testFixersPriority(FixerInterface $first, FixerInterface $second static::assertLessThan($first->getPriority(), $second->getPriority(), sprintf('"%s" should have less priority than "%s"', \get_class($second), \get_class($first))); } - public function provideFixersPriorityCases() + public function provideFixersPriorityCases(): array { $factory = new FixerFactory(); $factory->registerBuiltInFixers(); @@ -295,7 +295,7 @@ public function provideFixersPriorityCases() ]; } - public function provideFixersPrioritySpecialPhpdocCases() + public function provideFixersPrioritySpecialPhpdocCases(): array { $factory = new FixerFactory(); $factory->registerBuiltInFixers(); diff --git a/tests/AutoReview/ProjectCodeTest.php b/tests/AutoReview/ProjectCodeTest.php index 8affe78b65a..768bc9c5e4e 100644 --- a/tests/AutoReview/ProjectCodeTest.php +++ b/tests/AutoReview/ProjectCodeTest.php @@ -227,6 +227,8 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bo if ([] === $publicMethods) { $this->addToAssertionCount(1); // no methods to test, all good! + + return; } foreach ($publicMethods as $method) { @@ -243,20 +245,20 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bo */ public function testThatTestDataProvidersAreCorrectlyNamed(string $testClassName): void { - $usedDataProviderMethodNames = $this->getUsedDataProviderMethodNames($testClassName); - - if (empty($usedDataProviderMethodNames)) { - $this->addToAssertionCount(1); // no data providers to test, all good! - - return; - } + $asserts = 0; - foreach ($usedDataProviderMethodNames as $dataProviderMethodName) { + foreach ($this->getUsedDataProviderMethodNames($testClassName) as $dataProviderMethodName) { static::assertMatchesRegularExpression('/^provide[A-Z]\S+Cases$/', $dataProviderMethodName, sprintf( 'Data provider in "%s" with name "%s" is not correctly named.', $testClassName, $dataProviderMethodName )); + + ++$asserts; + } + + if (0 === $asserts) { + $this->addToAssertionCount(1); // no data providers to test, all good! } } @@ -271,15 +273,21 @@ public function testThatTestDataProvidersAreUsed(string $testClassName): void $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC), static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bool { return $reflectionMethod->getDeclaringClass()->getName() === $reflectionClass->getName() - && 'provide' === substr($reflectionMethod->getName(), 0, 7); + && str_starts_with($reflectionMethod->getName(), 'provide'); } ); if ([] === $definedDataProviders) { $this->addToAssertionCount(1); // no methods to test, all good! + + return; } - $usedDataProviderMethodNames = $this->getUsedDataProviderMethodNames($testClassName); + $usedDataProviderMethodNames = []; + + foreach ($this->getUsedDataProviderMethodNames($testClassName) as $providerName) { + $usedDataProviderMethodNames[] = $providerName; + } foreach ($definedDataProviders as $definedDataProvider) { static::assertContains( @@ -406,7 +414,7 @@ static function (\ReflectionMethod $reflectionMethod) use ($reflectionClass): bo } } - $expected = array_filter($expected, function ($item) { return false !== $item; }); + $expected = array_filter($expected, static function ($item): bool { return false !== $item; }); if (\count($expected) < 2) { $this->addToAssertionCount(1); // not enough parameters to test, all good! @@ -710,27 +718,35 @@ public function testConstantsAreInUpperCase(string $className): void } } - private function getUsedDataProviderMethodNames(string $testClassName): array + private function getUsedDataProviderMethodNames(string $testClassName): \Generator + { + foreach ($this->getAnnotationsOfTestClass($testClassName, 'dataProvider') as $methodName => $dataProviderAnnotation) { + if (1 === preg_match('/@dataProvider\s+(?P\w+)/', $dataProviderAnnotation->getContent(), $matches)) { + yield $methodName => $matches['methodName']; + } + } + } + + private function getAnnotationsOfTestClass(string $testClassName, string $annotation): \Generator { - $dataProviderMethodNames = []; $tokens = Tokens::fromCode(file_get_contents( str_replace('\\', \DIRECTORY_SEPARATOR, preg_replace('#^PhpCsFixer\\\Tests#', 'tests', $testClassName)).'.php' )); - foreach ($tokens as $token) { - if ($token->isGivenKind(T_DOC_COMMENT)) { - $docBlock = new DocBlock($token->getContent()); - $dataProviderAnnotations = $docBlock->getAnnotationsOfType('dataProvider'); + foreach ($tokens as $index => $token) { + if (!$token->isGivenKind(T_DOC_COMMENT)) { + continue; + } + + $methodName = $tokens[$tokens->getNextTokenOfKind($index, [[T_STRING]])]->getContent(); - foreach ($dataProviderAnnotations as $dataProviderAnnotation) { - if (1 === preg_match('/@dataProvider\s+(?P\w+)/', $dataProviderAnnotation->getContent(), $matches)) { - $dataProviderMethodNames[] = $matches['methodName']; - } - } + $docBlock = new DocBlock($token->getContent()); + $dataProviderAnnotations = $docBlock->getAnnotationsOfType($annotation); + + foreach ($dataProviderAnnotations as $dataProviderAnnotation) { + yield $methodName => $dataProviderAnnotation; } } - - return array_unique($dataProviderMethodNames); } private function getSrcClasses() diff --git a/tests/AutoReview/ProjectFixerConfigurationTest.php b/tests/AutoReview/ProjectFixerConfigurationTest.php index 9a938c200a5..6cd18d40553 100644 --- a/tests/AutoReview/ProjectFixerConfigurationTest.php +++ b/tests/AutoReview/ProjectFixerConfigurationTest.php @@ -20,8 +20,6 @@ use PhpCsFixer\ToolInfo; /** - * @author SpacePossum - * * @internal * * @coversNothing diff --git a/tests/AutoReview/TransformerTest.php b/tests/AutoReview/TransformerTest.php index 1ca4d645b65..efe455254c3 100644 --- a/tests/AutoReview/TransformerTest.php +++ b/tests/AutoReview/TransformerTest.php @@ -19,7 +19,6 @@ use PhpCsFixer\Tokenizer\Transformers; /** - * @author SpacePossum * @author Dave van der Brugge * * @internal diff --git a/tests/ConfigurationException/InvalidForEnvFixerConfigurationExceptionTest.php b/tests/ConfigurationException/InvalidForEnvFixerConfigurationExceptionTest.php index e5101860207..14116ad8acd 100644 --- a/tests/ConfigurationException/InvalidForEnvFixerConfigurationExceptionTest.php +++ b/tests/ConfigurationException/InvalidForEnvFixerConfigurationExceptionTest.php @@ -20,8 +20,6 @@ use PhpCsFixer\Tests\TestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\ConfigurationException\InvalidForEnvFixerConfigurationException diff --git a/tests/Console/ApplicationTest.php b/tests/Console/ApplicationTest.php index 3559008595c..5939b348e7c 100644 --- a/tests/Console/ApplicationTest.php +++ b/tests/Console/ApplicationTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\Tests\TestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Console\Application diff --git a/tests/Console/Command/SelfUpdateCommandTest.php b/tests/Console/Command/SelfUpdateCommandTest.php index bd33a40f599..8b227a04bc6 100644 --- a/tests/Console/Command/SelfUpdateCommandTest.php +++ b/tests/Console/Command/SelfUpdateCommandTest.php @@ -348,14 +348,14 @@ private function execute(Command $command, array $input, $decorated): CommandTes return $commandTester; } - private function assertDisplay(string $expectedDisplay, CommandTester $commandTester): void + private static function assertDisplay(string $expectedDisplay, CommandTester $commandTester): void { if (!$commandTester->getOutput()->isDecorated()) { $expectedDisplay = preg_replace("/\033\\[(\\d+;)*\\d+m/", '', $expectedDisplay); } // TODO drop preg_replace() usage when symfony/console is bumped - $cleanDisplay = function (string $display) { + $cleanDisplay = static function (string $display) { return preg_replace("/\033\\[39(;49)?m/", "\033[0m", $display); }; diff --git a/tests/Console/Output/ErrorOutputTest.php b/tests/Console/Output/ErrorOutputTest.php index df588de4b07..e739030c7da 100644 --- a/tests/Console/Output/ErrorOutputTest.php +++ b/tests/Console/Output/ErrorOutputTest.php @@ -22,8 +22,6 @@ use Symfony\Component\Console\Output\StreamOutput; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Console\Output\ErrorOutput diff --git a/tests/Console/Output/NullOutputTest.php b/tests/Console/Output/NullOutputTest.php index a48e3e6b6c4..dbab3104d03 100644 --- a/tests/Console/Output/NullOutputTest.php +++ b/tests/Console/Output/NullOutputTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\Tests\TestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Console\Output\NullOutput diff --git a/tests/Console/Report/FixReport/ReportSummaryTest.php b/tests/Console/Report/FixReport/ReportSummaryTest.php index 77847632a00..4280e09c0ce 100644 --- a/tests/Console/Report/FixReport/ReportSummaryTest.php +++ b/tests/Console/Report/FixReport/ReportSummaryTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\Tests\TestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Console\Report\FixReport\ReportSummary diff --git a/tests/Differ/DiffConsoleFormatterTest.php b/tests/Differ/DiffConsoleFormatterTest.php index 8ab9d94b2eb..0f1a696405b 100644 --- a/tests/Differ/DiffConsoleFormatterTest.php +++ b/tests/Differ/DiffConsoleFormatterTest.php @@ -19,8 +19,6 @@ use Symfony\Component\Console\Formatter\OutputFormatter; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Differ\DiffConsoleFormatter diff --git a/tests/Differ/FullDifferTest.php b/tests/Differ/FullDifferTest.php index 36a97afd4cc..3776a2d9857 100644 --- a/tests/Differ/FullDifferTest.php +++ b/tests/Differ/FullDifferTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Differ\FullDiffer; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Differ\FullDiffer diff --git a/tests/Differ/UnifiedDifferTest.php b/tests/Differ/UnifiedDifferTest.php index a693c89d21a..26c19e0ce61 100644 --- a/tests/Differ/UnifiedDifferTest.php +++ b/tests/Differ/UnifiedDifferTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Differ\UnifiedDiffer; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Differ\UnifiedDiffer diff --git a/tests/Fixer/Alias/ArrayPushFixerTest.php b/tests/Fixer/Alias/ArrayPushFixerTest.php index ab9b2f3494b..baa4ddaad94 100644 --- a/tests/Fixer/Alias/ArrayPushFixerTest.php +++ b/tests/Fixer/Alias/ArrayPushFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Alias\ArrayPushFixer diff --git a/tests/Fixer/Alias/NoAliasLanguageConstructCallFixerTest.php b/tests/Fixer/Alias/NoAliasLanguageConstructCallFixerTest.php index a18025dc246..be0ccbe4e24 100644 --- a/tests/Fixer/Alias/NoAliasLanguageConstructCallFixerTest.php +++ b/tests/Fixer/Alias/NoAliasLanguageConstructCallFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Alias\NoAliasLanguageConstructCallFixer diff --git a/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php b/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php index f9af4fc26c0..c1e1203d2b4 100644 --- a/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php +++ b/tests/Fixer/Alias/NoMixedEchoPrintFixerTest.php @@ -20,7 +20,6 @@ /** * @author Sullivan Senechal - * @author SpacePossum * * @internal * @@ -325,7 +324,7 @@ public function provideWrongConfigCases(): array ]; } - private static function assertCandidateTokenType($expected, AbstractFixer $fixer): void + private static function assertCandidateTokenType(int $expected, AbstractFixer $fixer): void { $reflectionProperty = new \ReflectionProperty($fixer, 'candidateTokenType'); $reflectionProperty->setAccessible(true); diff --git a/tests/Fixer/Alias/PowToExponentiationFixerTest.php b/tests/Fixer/Alias/PowToExponentiationFixerTest.php index db019d759d1..3b4a23ce641 100644 --- a/tests/Fixer/Alias/PowToExponentiationFixerTest.php +++ b/tests/Fixer/Alias/PowToExponentiationFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\AbstractFunctionReferenceFixer diff --git a/tests/Fixer/Alias/SetTypeToCastFixerTest.php b/tests/Fixer/Alias/SetTypeToCastFixerTest.php index 2c564362931..03575a50aac 100644 --- a/tests/Fixer/Alias/SetTypeToCastFixerTest.php +++ b/tests/Fixer/Alias/SetTypeToCastFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Alias\SetTypeToCastFixer diff --git a/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php b/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php index 5d057672dde..26f0b4750e0 100644 --- a/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php +++ b/tests/Fixer/ArrayNotation/ArraySyntaxFixerTest.php @@ -20,7 +20,6 @@ /** * @author Sebastiaan Stok * @author Gregor Harlan - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/Casing/ConstantCaseFixerTest.php b/tests/Fixer/Casing/ConstantCaseFixerTest.php index 4a42e7173ff..21f028999a0 100644 --- a/tests/Fixer/Casing/ConstantCaseFixerTest.php +++ b/tests/Fixer/Casing/ConstantCaseFixerTest.php @@ -18,7 +18,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal * @@ -138,8 +137,15 @@ public function provideFixCases(): array class Foo { const TRUE = 1; - const FALSE = 2; + const FALSE = true; const NULL = null; + }', + ''], diff --git a/tests/Fixer/Casing/MagicMethodCasingFixerTest.php b/tests/Fixer/Casing/MagicMethodCasingFixerTest.php index 589519137cf..a3a5d494d9b 100644 --- a/tests/Fixer/Casing/MagicMethodCasingFixerTest.php +++ b/tests/Fixer/Casing/MagicMethodCasingFixerTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Casing\MagicMethodCasingFixer diff --git a/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php b/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php index cd5798a88e5..93888ad7e2a 100644 --- a/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php +++ b/tests/Fixer/Casing/NativeFunctionCasingFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer diff --git a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php index c72fd2234d9..86880dc3ce4 100644 --- a/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php +++ b/tests/Fixer/Casing/NativeFunctionTypeDeclarationCasingFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Casing\NativeFunctionTypeDeclarationCasingFixer diff --git a/tests/Fixer/CastNotation/LowercaseCastFixerTest.php b/tests/Fixer/CastNotation/LowercaseCastFixerTest.php index 0ea96fd5a3e..195cf2609bc 100644 --- a/tests/Fixer/CastNotation/LowercaseCastFixerTest.php +++ b/tests/Fixer/CastNotation/LowercaseCastFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer diff --git a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php index b929e67c813..3647f2c85f1 100644 --- a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php +++ b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php @@ -75,7 +75,7 @@ public function intval($x) public function usesInval() { - // that's why it risky + // that's why it is risky return intval(mt_rand(0, 100)); } } @@ -93,7 +93,7 @@ public function intval($x) public function usesInval() { - // that's why it risky + // that's why it is risky return (int) (mt_rand(0, 100)); } } diff --git a/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php b/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php index 7ebe12e859e..70d33ee92f9 100644 --- a/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php +++ b/tests/Fixer/CastNotation/ShortScalarCastFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer diff --git a/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php b/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php index e31ea140dab..82c30afab35 100644 --- a/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php +++ b/tests/Fixer/ClassNotation/ClassDefinitionFixerTest.php @@ -21,8 +21,6 @@ use PhpCsFixer\WhitespacesFixerConfig; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer diff --git a/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php b/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php index 2964639ed1a..daffd22dd0e 100644 --- a/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php +++ b/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\ClassNotation\FinalInternalClassFixer diff --git a/tests/Fixer/ClassNotation/SingleTraitInsertPerStatementFixerTest.php b/tests/Fixer/ClassNotation/SingleTraitInsertPerStatementFixerTest.php index b5e16f5aede..c99af166e37 100644 --- a/tests/Fixer/ClassNotation/SingleTraitInsertPerStatementFixerTest.php +++ b/tests/Fixer/ClassNotation/SingleTraitInsertPerStatementFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\ClassNotation\SingleTraitInsertPerStatementFixer diff --git a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php index 21279863c22..15bb23161c0 100644 --- a/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php +++ b/tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php @@ -19,7 +19,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/Comment/NoEmptyCommentFixerTest.php b/tests/Fixer/Comment/NoEmptyCommentFixerTest.php index 79daa068986..e2b88adbee5 100644 --- a/tests/Fixer/Comment/NoEmptyCommentFixerTest.php +++ b/tests/Fixer/Comment/NoEmptyCommentFixerTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\Tokenizer\Tokens; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer diff --git a/tests/Fixer/ControlStructure/EmptyLoopBodyFixerTest.php b/tests/Fixer/ControlStructure/EmptyLoopBodyFixerTest.php index 27a9b306d06..c9d6b927394 100644 --- a/tests/Fixer/ControlStructure/EmptyLoopBodyFixerTest.php +++ b/tests/Fixer/ControlStructure/EmptyLoopBodyFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\ControlStructure\EmptyLoopBodyFixer diff --git a/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php b/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php index e1e6877bc39..9dc4e3a80df 100644 --- a/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php +++ b/tests/Fixer/ControlStructure/EmptyLoopConditionFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\ControlStructure\EmptyLoopConditionFixer diff --git a/tests/Fixer/ControlStructure/IncludeFixerTest.php b/tests/Fixer/ControlStructure/IncludeFixerTest.php index d3273d4bc83..c1700a60e14 100644 --- a/tests/Fixer/ControlStructure/IncludeFixerTest.php +++ b/tests/Fixer/ControlStructure/IncludeFixerTest.php @@ -18,7 +18,6 @@ /** * @author Хаша ĐĄŃ‚Đ°ĐŒĐ”ĐœĐșĐŸĐČоћ - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php index b4117c5357d..e7cd8e1de77 100644 --- a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php +++ b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php @@ -1008,12 +1008,13 @@ public function provideTestFixWithDifferentCommentTextCases(): array foreach ($cases as &$case) { $case[0] = $replaceCommentText($case[0]); + if (isset($case[1])) { $case[1] = $replaceCommentText($case[1]); } } - $cases = array_merge($cases, [ + return array_merge($cases, [ [ ' - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/FunctionNotation/FopenFlagOrderFixerTest.php b/tests/Fixer/FunctionNotation/FopenFlagOrderFixerTest.php index d0701baf194..765b443d7b5 100644 --- a/tests/Fixer/FunctionNotation/FopenFlagOrderFixerTest.php +++ b/tests/Fixer/FunctionNotation/FopenFlagOrderFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\AbstractFopenFlagFixer diff --git a/tests/Fixer/FunctionNotation/FopenFlagsFixerTest.php b/tests/Fixer/FunctionNotation/FopenFlagsFixerTest.php index b1ce62185c1..6da37924db1 100644 --- a/tests/Fixer/FunctionNotation/FopenFlagsFixerTest.php +++ b/tests/Fixer/FunctionNotation/FopenFlagsFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\AbstractFopenFlagFixer diff --git a/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php b/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php index 105df6b9952..818ff035c7b 100644 --- a/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php +++ b/tests/Fixer/FunctionNotation/LambdaNotUsedImportFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\FunctionNotation\LambdaNotUsedImportFixer diff --git a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php index ab7f8446ccc..cb0117a1055 100644 --- a/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php +++ b/tests/Fixer/FunctionNotation/NativeFunctionInvocationFixerTest.php @@ -21,7 +21,6 @@ /** * @author Andreas Möller - * @author SpacePossum * * @internal * @@ -632,7 +631,7 @@ public function testFix80(string $expected, ?string $input = null, array $config $this->doTest($expected, $input); } - public function provideFix80Cases() + public function provideFix80Cases(): \Generator { yield 'attribute and strict' => [ 'provideFixPhp74Cases()); } @@ -483,7 +483,7 @@ public function bbb(int | null $bar = null, $baz = 1) {} ]; } - public function provideInvertedFix80Cases() + public function provideInvertedFix80Cases(): iterable { return TestCaseUtils::swapExpectedInputTestCases($this->provideFix80Cases()); } diff --git a/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php b/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php index 77e56fe3248..05f56749785 100644 --- a/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php +++ b/tests/Fixer/FunctionNotation/StaticLambdaFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\FunctionNotation\StaticLambdaFixer diff --git a/tests/Fixer/Import/SingleImportPerStatementFixerTest.php b/tests/Fixer/Import/SingleImportPerStatementFixerTest.php index 49615e0d8ae..124fe2c70c1 100644 --- a/tests/Fixer/Import/SingleImportPerStatementFixerTest.php +++ b/tests/Fixer/Import/SingleImportPerStatementFixerTest.php @@ -19,7 +19,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixerTest.php b/tests/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixerTest.php index 58fe30fe13b..471a6e16d4a 100644 --- a/tests/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixerTest.php +++ b/tests/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveIssetsFixer diff --git a/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php b/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php index 30ac2660deb..57278ffc6bf 100644 --- a/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php +++ b/tests/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\LanguageConstruct\CombineConsecutiveUnsetsFixer diff --git a/tests/Fixer/LanguageConstruct/DeclareEqualNormalizeFixerTest.php b/tests/Fixer/LanguageConstruct/DeclareEqualNormalizeFixerTest.php index e8c0b313fd5..395e8e2117a 100644 --- a/tests/Fixer/LanguageConstruct/DeclareEqualNormalizeFixerTest.php +++ b/tests/Fixer/LanguageConstruct/DeclareEqualNormalizeFixerTest.php @@ -19,7 +19,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php b/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php index 991d39c5890..2d8bdfe0b98 100644 --- a/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php +++ b/tests/Fixer/LanguageConstruct/FunctionToConstantFixerTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer diff --git a/tests/Fixer/ListNotation/ListSyntaxFixerTest.php b/tests/Fixer/ListNotation/ListSyntaxFixerTest.php index 115c697fcde..67411162737 100644 --- a/tests/Fixer/ListNotation/ListSyntaxFixerTest.php +++ b/tests/Fixer/ListNotation/ListSyntaxFixerTest.php @@ -20,8 +20,6 @@ /** * @requires PHP 7.1 * - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer @@ -65,7 +63,7 @@ public function provideFixToLongSyntaxCases(): array } // the reverse of this is different because of all the comments and white space, - // therefore we override with a similar case case here + // therefore we override with a similar case here $cases['comment case'] = [ ' * @author Gregor Harlan * @author Carlos Cirello - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/Operator/ConcatSpaceFixerTest.php b/tests/Fixer/Operator/ConcatSpaceFixerTest.php index 922f299b622..bda8f5cff54 100644 --- a/tests/Fixer/Operator/ConcatSpaceFixerTest.php +++ b/tests/Fixer/Operator/ConcatSpaceFixerTest.php @@ -19,7 +19,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php b/tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php index 7e9def10537..e17504a6bb4 100644 --- a/tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php +++ b/tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Operator\TernaryToElvisOperatorFixer diff --git a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php index 38852df63f8..c9dcc0cb2e2 100644 --- a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php @@ -19,8 +19,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertFixer diff --git a/tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php b/tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php index 4cb955b3fb5..9e5db73081b 100644 --- a/tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php +++ b/tests/Fixer/Phpdoc/NoEmptyPhpdocFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer diff --git a/tests/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixerTest.php b/tests/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixerTest.php index 1b8c1885c01..fd2f088f1cd 100644 --- a/tests/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocInlineTagNormalizerFixerTest.php @@ -51,7 +51,7 @@ public function provideFixCases(): array * {@inheritdoc foo bar.} d * {@inheritdoc foo bar.} e * {@inheritdoc test} f - * end comment {@inheritdoc here we are done} @spacepossum {1} + * end comment {@inheritdoc here we are done} @foo {1} */ ', ' * @author Dariusz RumiƄski - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixerTest.php b/tests/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixerTest.php index 37e71c4f60c..28161a13ce5 100644 --- a/tests/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixerTest.php @@ -19,8 +19,6 @@ /** * @internal * - * @author SpacePossum - * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocNoUselessInheritdocFixer */ final class PhpdocNoUselessInheritdocFixerTest extends AbstractFixerTestCase diff --git a/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php b/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php index 728b7fa86f7..f1981d24acc 100644 --- a/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixerTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer diff --git a/tests/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixerTest.php b/tests/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixerTest.php index a08303b812d..300e96eca0d 100644 --- a/tests/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocSingleLineVarSpacingFixer diff --git a/tests/Fixer/ReturnNotation/NoUselessReturnFixerTest.php b/tests/Fixer/ReturnNotation/NoUselessReturnFixerTest.php index 05a6efe8841..0aa7163e141 100644 --- a/tests/Fixer/ReturnNotation/NoUselessReturnFixerTest.php +++ b/tests/Fixer/ReturnNotation/NoUselessReturnFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\ReturnNotation\NoUselessReturnFixer diff --git a/tests/Fixer/ReturnNotation/ReturnAssignmentFixerTest.php b/tests/Fixer/ReturnNotation/ReturnAssignmentFixerTest.php index 010f6a0273b..bc2904db34f 100644 --- a/tests/Fixer/ReturnNotation/ReturnAssignmentFixerTest.php +++ b/tests/Fixer/ReturnNotation/ReturnAssignmentFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\ReturnNotation\ReturnAssignmentFixer diff --git a/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php b/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php index fd8ebdf7173..6a0baba348e 100644 --- a/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php +++ b/tests/Fixer/Semicolon/NoEmptyStatementFixerTest.php @@ -17,7 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum * @author Dariusz RumiƄski * * @internal diff --git a/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php b/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php index 66c7a0086db..a5d8691c11e 100644 --- a/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php +++ b/tests/Fixer/Semicolon/SemicolonAfterInstructionFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Semicolon\SemicolonAfterInstructionFixer diff --git a/tests/Fixer/Semicolon/SpaceAfterSemicolonFixerTest.php b/tests/Fixer/Semicolon/SpaceAfterSemicolonFixerTest.php index 1161c10c866..ed33ae2dc02 100644 --- a/tests/Fixer/Semicolon/SpaceAfterSemicolonFixerTest.php +++ b/tests/Fixer/Semicolon/SpaceAfterSemicolonFixerTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Semicolon\SpaceAfterSemicolonFixer diff --git a/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php b/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php index 10b5ff8d62c..0272edd280b 100644 --- a/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php +++ b/tests/Fixer/Strict/DeclareStrictTypesFixerTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\WhitespacesFixerConfig; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer diff --git a/tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php b/tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php index 885e87d2f24..7c9ac91a65c 100644 --- a/tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php +++ b/tests/Fixer/Whitespace/BlankLineBeforeStatementFixerTest.php @@ -21,7 +21,6 @@ /** * @author Dariusz RumiƄski * @author Andreas Möller - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/Whitespace/LineEndingFixerTest.php b/tests/Fixer/Whitespace/LineEndingFixerTest.php index 1af23a49500..ceba54408c4 100644 --- a/tests/Fixer/Whitespace/LineEndingFixerTest.php +++ b/tests/Fixer/Whitespace/LineEndingFixerTest.php @@ -19,7 +19,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal * diff --git a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php index 04c4f299359..e9863146d92 100644 --- a/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php +++ b/tests/Fixer/Whitespace/NoExtraBlankLinesFixerTest.php @@ -1122,7 +1122,7 @@ public function provideFix80Cases(): \Generator ' $config) { static::assertIsString($rule, $setName); - if ('@' === substr($rule, 0, 1)) { + if (str_starts_with($rule, '@')) { static::assertFalse($sawRule, sprintf('Ruleset "%s" should define all sets it extends first and than list by rule configuration overrides.', $setName)); RuleSets::getSetDefinition($setName); } else { $sawRule = true; - static::assertTrue($factory->hasRule($rule)); + static::assertTrue($factory->hasRule($rule), $rule); } } diff --git a/tests/Runner/FileFilterIteratorTest.php b/tests/Runner/FileFilterIteratorTest.php index 9c288e2c5c4..c44a09decee 100644 --- a/tests/Runner/FileFilterIteratorTest.php +++ b/tests/Runner/FileFilterIteratorTest.php @@ -20,8 +20,6 @@ use Symfony\Component\EventDispatcher\EventDispatcher; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Runner\FileFilterIterator diff --git a/tests/Runner/FileLintingIteratorTest.php b/tests/Runner/FileLintingIteratorTest.php index 7bff816249e..e718e1200ff 100644 --- a/tests/Runner/FileLintingIteratorTest.php +++ b/tests/Runner/FileLintingIteratorTest.php @@ -20,8 +20,6 @@ use PhpCsFixer\Tests\TestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Runner\FileLintingIterator diff --git a/tests/Smoke/InstallViaComposerTest.php b/tests/Smoke/InstallViaComposerTest.php index 99af5863757..1ce0d014018 100644 --- a/tests/Smoke/InstallViaComposerTest.php +++ b/tests/Smoke/InstallViaComposerTest.php @@ -137,7 +137,7 @@ public function testInstallationViaArtifactIsPossible(): void $cwd = __DIR__.'/../..'; $stepsToInitializeArtifact = [ - // Clone current version of project to new location, as we gonna modify it. + // Clone current version of project to new location, as we are going to modify it. // Warning! Only already committed changes will be cloned! "git clone --depth=1 . {$tmpArtifactPath}", ]; diff --git a/tests/Test/AbstractFixerTestCase.php b/tests/Test/AbstractFixerTestCase.php index f642b11c481..6398765fe65 100644 --- a/tests/Test/AbstractFixerTestCase.php +++ b/tests/Test/AbstractFixerTestCase.php @@ -128,7 +128,7 @@ final public function testFixerDefinitions(): void static::assertNotEmpty($code, sprintf('[%s] Sample #%d', $fixerName, $sampleCounter)); if (!($this->fixer instanceof SingleBlankLineAtEofFixer)) { - static::assertSame("\n", substr($code, -1), sprintf('[%s] Sample #%d must end with linebreak', $fixerName, $sampleCounter)); + static::assertStringEndsWith("\n", $code, sprintf('[%s] Sample #%d must end with linebreak', $fixerName, $sampleCounter)); } $config = $sample->getConfiguration(); diff --git a/tests/Test/AbstractIntegrationTestCase.php b/tests/Test/AbstractIntegrationTestCase.php index 3366bbc7c2f..5845f6f71d9 100644 --- a/tests/Test/AbstractIntegrationTestCase.php +++ b/tests/Test/AbstractIntegrationTestCase.php @@ -59,8 +59,6 @@ * * Section or any line in it may be omitted. * ** PHP minimum version. Default to current running php version (no effect). * - * @author SpacePossum - * * @internal */ abstract class AbstractIntegrationTestCase extends TestCase diff --git a/tests/Test/IntegrationCase.php b/tests/Test/IntegrationCase.php index cc61f610e41..90b94f4a391 100644 --- a/tests/Test/IntegrationCase.php +++ b/tests/Test/IntegrationCase.php @@ -89,22 +89,22 @@ public function hasInputCode(): bool return null !== $this->inputCode; } - public function getConfig() + public function getConfig(): array { return $this->config; } - public function getExpectedCode() + public function getExpectedCode(): string { return $this->expectedCode; } - public function getFileName() + public function getFileName(): string { return $this->fileName; } - public function getInputCode() + public function getInputCode(): ?string { return $this->inputCode; } @@ -125,22 +125,22 @@ public function getRequirement(string $name) return $this->requirements[$name]; } - public function getRequirements() + public function getRequirements(): array { return $this->requirements; } - public function getRuleset() + public function getRuleset(): RuleSet { return $this->ruleset; } - public function getSettings() + public function getSettings(): array { return $this->settings; } - public function getTitle() + public function getTitle(): string { return $this->title; } diff --git a/tests/TextDiffTest.php b/tests/TextDiffTest.php index e502eef6a17..6c26eb1ffe0 100644 --- a/tests/TextDiffTest.php +++ b/tests/TextDiffTest.php @@ -21,8 +21,6 @@ use Symfony\Component\Console\Tester\CommandTester; /** - * @author SpacePossum - * * @internal * * @coversNothing diff --git a/tests/Tokenizer/AbstractTransformerTest.php b/tests/Tokenizer/AbstractTransformerTest.php index 3b014a4b5a5..448472fa338 100644 --- a/tests/Tokenizer/AbstractTransformerTest.php +++ b/tests/Tokenizer/AbstractTransformerTest.php @@ -18,8 +18,6 @@ use PhpCsFixer\Tests\TestCase; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\Tokenizer\AbstractTransformer diff --git a/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php b/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php index ad50bc74d85..7f3054e5610 100644 --- a/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php @@ -20,7 +20,6 @@ /** * @author Kuba WerƂos - * @author SpacePossum * * @internal * diff --git a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php index 2a2469a9b27..ce2c43be16a 100644 --- a/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/FunctionsAnalyzerTest.php @@ -46,6 +46,11 @@ public function provideIsGlobalFunctionCallCases(): \Generator [], ]; + yield [ + ' * @author Max Voloshin * @author Gregor Harlan - * @author SpacePossum * * @internal * diff --git a/tests/Tokenizer/TokensTest.php b/tests/Tokenizer/TokensTest.php index 25ae75b969f..8530700db59 100644 --- a/tests/Tokenizer/TokensTest.php +++ b/tests/Tokenizer/TokensTest.php @@ -21,7 +21,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal * diff --git a/tests/Tokenizer/Transformer/SquareBraceTransformerTest.php b/tests/Tokenizer/Transformer/SquareBraceTransformerTest.php index 695f5aee3ff..8ffc4d13a87 100644 --- a/tests/Tokenizer/Transformer/SquareBraceTransformerTest.php +++ b/tests/Tokenizer/Transformer/SquareBraceTransformerTest.php @@ -21,7 +21,6 @@ /** * @author Dariusz RumiƄski - * @author SpacePossum * * @internal * diff --git a/tests/ToolInfoTest.php b/tests/ToolInfoTest.php index 1ca6b74d3bf..9db083ac3b8 100644 --- a/tests/ToolInfoTest.php +++ b/tests/ToolInfoTest.php @@ -17,8 +17,6 @@ use PhpCsFixer\ToolInfo; /** - * @author SpacePossum - * * @internal * * @covers \PhpCsFixer\ToolInfo From 6b5f819285c125c31ac561a7e90c0fc46f64886b Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Mon, 6 Sep 2021 11:38:22 +0200 Subject: [PATCH 69/80] PHP8.1 - Explicit octal integer literal notation --- doc/ruleSets/PHP81Migration.rst | 11 +++ doc/ruleSets/index.rst | 1 + doc/rules/array_notation/array_syntax.rst | 3 + .../no_whitespace_before_comma_in_array.rst | 5 ++ .../array_notation/normalize_index_brace.rst | 3 + doc/rules/basic/octal_notation.rst | 26 +++++++ doc/rules/cast_notation/no_unset_cast.rst | 3 + doc/rules/cast_notation/short_scalar_cast.rst | 3 + .../class_notation/visibility_required.rst | 3 + .../trailing_comma_in_multiline.rst | 5 ++ .../method_argument_space.rst | 5 ++ doc/rules/index.rst | 2 + doc/rules/list_notation/list_syntax.rst | 3 + .../namespace_notation/clean_namespace.rst | 3 + .../operator/ternary_to_null_coalescing.rst | 3 + doc/rules/whitespace/heredoc_indentation.rst | 3 + src/Fixer/Basic/OctalNotationFixer.php | 74 +++++++++++++++++++ .../EmptyLoopConditionFixer.php | 3 - src/RuleSet/Sets/PHP81MigrationSet.php | 31 ++++++++ tests/Fixer/Basic/OctalNotationFixerTest.php | 72 ++++++++++++++++++ tests/Fixtures/Integration/misc/PHP8_1.test | 8 ++ .../Integration/set/@PHP81Migration.test | 6 ++ .../set/@PHP81Migration.test-in.php | 4 + .../set/@PHP81Migration.test-out.php | 4 + tests/RuleSet/Sets/PHP81MigrationSetTest.php | 24 ++++++ 25 files changed, 305 insertions(+), 3 deletions(-) create mode 100644 doc/ruleSets/PHP81Migration.rst create mode 100644 doc/rules/basic/octal_notation.rst create mode 100644 src/Fixer/Basic/OctalNotationFixer.php create mode 100644 src/RuleSet/Sets/PHP81MigrationSet.php create mode 100644 tests/Fixer/Basic/OctalNotationFixerTest.php create mode 100644 tests/Fixtures/Integration/set/@PHP81Migration.test create mode 100644 tests/Fixtures/Integration/set/@PHP81Migration.test-in.php create mode 100644 tests/Fixtures/Integration/set/@PHP81Migration.test-out.php create mode 100644 tests/RuleSet/Sets/PHP81MigrationSetTest.php diff --git a/doc/ruleSets/PHP81Migration.rst b/doc/ruleSets/PHP81Migration.rst new file mode 100644 index 00000000000..8b2b592cb72 --- /dev/null +++ b/doc/ruleSets/PHP81Migration.rst @@ -0,0 +1,11 @@ +============================ +Rule set ``@PHP81Migration`` +============================ + +Rules to improve code for PHP 8.1 compatibility. + +Rules +----- + +- `@PHP80Migration <./PHP80Migration.rst>`_ +- `octal_notation <./../rules/basic/octal_notation.rst>`_ diff --git a/doc/ruleSets/index.rst b/doc/ruleSets/index.rst index c0a9d0c0845..6f6b8e0857b 100644 --- a/doc/ruleSets/index.rst +++ b/doc/ruleSets/index.rst @@ -13,6 +13,7 @@ List of Available Rule sets - `@PHP74Migration:risky <./PHP74MigrationRisky.rst>`_ - `@PHP80Migration <./PHP80Migration.rst>`_ - `@PHP80Migration:risky <./PHP80MigrationRisky.rst>`_ +- `@PHP81Migration <./PHP81Migration.rst>`_ - `@PHPUnit30Migration:risky <./PHPUnit30MigrationRisky.rst>`_ - `@PHPUnit32Migration:risky <./PHPUnit32MigrationRisky.rst>`_ - `@PHPUnit35Migration:risky <./PHPUnit35MigrationRisky.rst>`_ diff --git a/doc/rules/array_notation/array_syntax.rst b/doc/rules/array_notation/array_syntax.rst index d0f00c65f08..6f27f8a50b9 100644 --- a/doc/rules/array_notation/array_syntax.rst +++ b/doc/rules/array_notation/array_syntax.rst @@ -68,6 +68,9 @@ The rule is part of the following rule sets: @PHP80Migration Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config. +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``array_syntax`` rule with the default config. + @PhpCsFixer Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``array_syntax`` rule with the default config. diff --git a/doc/rules/array_notation/no_whitespace_before_comma_in_array.rst b/doc/rules/array_notation/no_whitespace_before_comma_in_array.rst index cac0987947d..15d55610664 100644 --- a/doc/rules/array_notation/no_whitespace_before_comma_in_array.rst +++ b/doc/rules/array_notation/no_whitespace_before_comma_in_array.rst @@ -68,6 +68,11 @@ The rule is part of the following rule sets: ``['after_heredoc' => true]`` +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``no_whitespace_before_comma_in_array`` rule with the config below: + + ``['after_heredoc' => true]`` + @PhpCsFixer Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``no_whitespace_before_comma_in_array`` rule with the default config. diff --git a/doc/rules/array_notation/normalize_index_brace.rst b/doc/rules/array_notation/normalize_index_brace.rst index 6886082e9b2..53a741b3269 100644 --- a/doc/rules/array_notation/normalize_index_brace.rst +++ b/doc/rules/array_notation/normalize_index_brace.rst @@ -29,6 +29,9 @@ The rule is part of the following rule sets: @PHP80Migration Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``normalize_index_brace`` rule. +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``normalize_index_brace`` rule. + @PhpCsFixer Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``normalize_index_brace`` rule. diff --git a/doc/rules/basic/octal_notation.rst b/doc/rules/basic/octal_notation.rst new file mode 100644 index 00000000000..5b2d1f6e747 --- /dev/null +++ b/doc/rules/basic/octal_notation.rst @@ -0,0 +1,26 @@ +======================= +Rule ``octal_notation`` +======================= + +Literal octal must be in ``0o`` notation. + +Examples +-------- + +Example #1 +~~~~~~~~~~ + +.. code-block:: diff + + --- Original + +++ New + -`_ rule set will enable the ``octal_notation`` rule. diff --git a/doc/rules/cast_notation/no_unset_cast.rst b/doc/rules/cast_notation/no_unset_cast.rst index f972fb8e451..3ae4f9bd7a7 100644 --- a/doc/rules/cast_notation/no_unset_cast.rst +++ b/doc/rules/cast_notation/no_unset_cast.rst @@ -26,6 +26,9 @@ The rule is part of the following rule sets: @PHP80Migration Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``no_unset_cast`` rule. +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``no_unset_cast`` rule. + @PhpCsFixer Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``no_unset_cast`` rule. diff --git a/doc/rules/cast_notation/short_scalar_cast.rst b/doc/rules/cast_notation/short_scalar_cast.rst index e470fb356d8..47b4dc098e0 100644 --- a/doc/rules/cast_notation/short_scalar_cast.rst +++ b/doc/rules/cast_notation/short_scalar_cast.rst @@ -58,6 +58,9 @@ The rule is part of the following rule sets: @PHP80Migration Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``short_scalar_cast`` rule. +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``short_scalar_cast`` rule. + @PSR12 Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``short_scalar_cast`` rule. diff --git a/doc/rules/class_notation/visibility_required.rst b/doc/rules/class_notation/visibility_required.rst index 9f33855f0f6..cf01f40adeb 100644 --- a/doc/rules/class_notation/visibility_required.rst +++ b/doc/rules/class_notation/visibility_required.rst @@ -77,6 +77,9 @@ The rule is part of the following rule sets: @PHP80Migration Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the default config. +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``visibility_required`` rule with the default config. + @PSR12 Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``visibility_required`` rule with the default config. diff --git a/doc/rules/control_structure/trailing_comma_in_multiline.rst b/doc/rules/control_structure/trailing_comma_in_multiline.rst index ca12d7d94e8..ece2a1ab42f 100644 --- a/doc/rules/control_structure/trailing_comma_in_multiline.rst +++ b/doc/rules/control_structure/trailing_comma_in_multiline.rst @@ -118,6 +118,11 @@ The rule is part of the following rule sets: ``['after_heredoc' => true]`` +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``trailing_comma_in_multiline`` rule with the config below: + + ``['after_heredoc' => true]`` + @PhpCsFixer Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``trailing_comma_in_multiline`` rule with the default config. diff --git a/doc/rules/function_notation/method_argument_space.rst b/doc/rules/function_notation/method_argument_space.rst index e6ffc9a80c2..15c2bb9f5cd 100644 --- a/doc/rules/function_notation/method_argument_space.rst +++ b/doc/rules/function_notation/method_argument_space.rst @@ -224,6 +224,11 @@ The rule is part of the following rule sets: ``['after_heredoc' => true]`` +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``method_argument_space`` rule with the config below: + + ``['after_heredoc' => true]`` + @PSR12 Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``method_argument_space`` rule with the config below: diff --git a/doc/rules/index.rst b/doc/rules/index.rst index ca530a00baf..64a4ce9748f 100644 --- a/doc/rules/index.rst +++ b/doc/rules/index.rst @@ -55,6 +55,8 @@ Basic PHP code MUST use only UTF-8 without BOM (remove BOM). - `non_printable_character <./basic/non_printable_character.rst>`_ *(risky)* Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and other invisible unicode symbols. +- `octal_notation <./basic/octal_notation.rst>`_ + Literal octal must be in ``0o`` notation. - `psr_autoloading <./basic/psr_autoloading.rst>`_ *(risky)* Classes must be in a path that matches their namespace, be at least one namespace deep and the class name should match the file name. diff --git a/doc/rules/list_notation/list_syntax.rst b/doc/rules/list_notation/list_syntax.rst index de69e275ffc..294d5da8486 100644 --- a/doc/rules/list_notation/list_syntax.rst +++ b/doc/rules/list_notation/list_syntax.rst @@ -62,3 +62,6 @@ The rule is part of the following rule sets: @PHP80Migration Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the default config. + +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``list_syntax`` rule with the default config. diff --git a/doc/rules/namespace_notation/clean_namespace.rst b/doc/rules/namespace_notation/clean_namespace.rst index 255444dc78b..52fc1694acd 100644 --- a/doc/rules/namespace_notation/clean_namespace.rst +++ b/doc/rules/namespace_notation/clean_namespace.rst @@ -37,6 +37,9 @@ The rule is part of the following rule sets: @PHP80Migration Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``clean_namespace`` rule. +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``clean_namespace`` rule. + @PhpCsFixer Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``clean_namespace`` rule. diff --git a/doc/rules/operator/ternary_to_null_coalescing.rst b/doc/rules/operator/ternary_to_null_coalescing.rst index 38d4f6c00bf..40ba724c10b 100644 --- a/doc/rules/operator/ternary_to_null_coalescing.rst +++ b/doc/rules/operator/ternary_to_null_coalescing.rst @@ -37,3 +37,6 @@ The rule is part of the following rule sets: @PHP80Migration Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``ternary_to_null_coalescing`` rule. + +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``ternary_to_null_coalescing`` rule. diff --git a/doc/rules/whitespace/heredoc_indentation.rst b/doc/rules/whitespace/heredoc_indentation.rst index 27f3f2f9b7e..a0695f6e6a9 100644 --- a/doc/rules/whitespace/heredoc_indentation.rst +++ b/doc/rules/whitespace/heredoc_indentation.rst @@ -87,3 +87,6 @@ The rule is part of the following rule sets: @PHP80Migration Using the `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_ rule set will enable the ``heredoc_indentation`` rule with the default config. + +@PHP81Migration + Using the `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_ rule set will enable the ``heredoc_indentation`` rule with the default config. diff --git a/src/Fixer/Basic/OctalNotationFixer.php b/src/Fixer/Basic/OctalNotationFixer.php new file mode 100644 index 00000000000..1e6755f3e4f --- /dev/null +++ b/src/Fixer/Basic/OctalNotationFixer.php @@ -0,0 +1,74 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Fixer\Basic; + +use PhpCsFixer\AbstractFixer; +use PhpCsFixer\FixerDefinition\FixerDefinition; +use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\FixerDefinition\VersionSpecification; +use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample; +use PhpCsFixer\Preg; +use PhpCsFixer\Tokenizer\Token; +use PhpCsFixer\Tokenizer\Tokens; + +final class OctalNotationFixer extends AbstractFixer +{ + /** + * {@inheritdoc} + */ + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition( + 'Literal octal must be in `0o` notation.', + [ + new VersionSpecificCodeSample( + "= 80100 && $tokens->isTokenKindFound(T_LNUMBER); + } + + /** + * {@inheritdoc} + */ + protected function applyFix(\SplFileInfo $file, Tokens $tokens): void + { + foreach ($tokens as $index => $token) { + if (!$token->isGivenKind(T_LNUMBER)) { + continue; + } + + $content = $token->getContent(); + + if (1 !== Preg::match('#^0\d+$#', $content)) { + continue; + } + + $tokens[$index] = 1 === Preg::match('#^0+$#', $content) + ? new Token([T_LNUMBER, '0']) + : new Token([T_LNUMBER, '0o'.substr($content, 1)]) + ; + } + } +} diff --git a/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php b/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php index 71ca6ce286a..7f82fc4aae5 100644 --- a/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php +++ b/src/Fixer/ControlStructure/EmptyLoopConditionFixer.php @@ -25,9 +25,6 @@ use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; -/** - * @author SpacePossum - */ final class EmptyLoopConditionFixer extends AbstractFixer implements ConfigurableFixerInterface { private const STYLE_FOR = 'for'; diff --git a/src/RuleSet/Sets/PHP81MigrationSet.php b/src/RuleSet/Sets/PHP81MigrationSet.php new file mode 100644 index 00000000000..eaa27e9d26e --- /dev/null +++ b/src/RuleSet/Sets/PHP81MigrationSet.php @@ -0,0 +1,31 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\RuleSet\Sets; + +use PhpCsFixer\RuleSet\AbstractMigrationSetDescription; + +/** + * @internal + */ +final class PHP81MigrationSet extends AbstractMigrationSetDescription +{ + public function getRules(): array + { + return [ + '@PHP80Migration' => true, + 'octal_notation' => true, + ]; + } +} diff --git a/tests/Fixer/Basic/OctalNotationFixerTest.php b/tests/Fixer/Basic/OctalNotationFixerTest.php new file mode 100644 index 00000000000..2fb865cbf37 --- /dev/null +++ b/tests/Fixer/Basic/OctalNotationFixerTest.php @@ -0,0 +1,72 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Fixer\Basic; + +use PhpCsFixer\Tests\Test\AbstractFixerTestCase; + +/** + * @author SpacePossum + * + * @internal + * + * @covers \PhpCsFixer\Fixer\Basic\OctalNotationFixer + */ +final class OctalNotationFixerTest extends AbstractFixerTestCase +{ + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public static function provideFix81Cases(): \Generator + { + yield [ + ' + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\RuleSet\Sets; + +/** + * @internal + * + * @covers \PhpCsFixer\RuleSet\Sets\PHP81MigrationSet + */ +final class PHP81MigrationSetTest extends AbstractSetTest +{ +} From e5200d73542a5f6db27d2b46e5c7a98fb88f9bd0 Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Tue, 7 Sep 2021 11:37:07 +0200 Subject: [PATCH 70/80] PHP8.0 - union types --- .../Casing/LowercaseStaticReferenceFixer.php | 5 +- .../SingleClassElementPerStatementFixer.php | 6 +- .../LowercaseStaticReferenceFixerTest.php | 72 ++++++++++++++++++- ...ingleClassElementPerStatementFixerTest.php | 28 ++++++++ 4 files changed, 106 insertions(+), 5 deletions(-) diff --git a/src/Fixer/Casing/LowercaseStaticReferenceFixer.php b/src/Fixer/Casing/LowercaseStaticReferenceFixer.php index 50dbcae22e4..770e66a1c5e 100644 --- a/src/Fixer/Casing/LowercaseStaticReferenceFixer.php +++ b/src/Fixer/Casing/LowercaseStaticReferenceFixer.php @@ -18,6 +18,7 @@ use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -86,12 +87,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $prevIndex = $tokens->getPrevMeaningfulToken($index); - if ($tokens[$prevIndex]->isGivenKind([T_CONST, T_DOUBLE_COLON, T_FUNCTION, T_NAMESPACE, T_NS_SEPARATOR, T_PRIVATE, T_PROTECTED, T_PUBLIC]) || $tokens[$prevIndex]->isObjectOperator()) { + if ($tokens[$prevIndex]->isGivenKind([T_CONST, T_DOUBLE_COLON, T_FUNCTION, T_NAMESPACE, T_NS_SEPARATOR]) || $tokens[$prevIndex]->isObjectOperator()) { continue; } $nextIndex = $tokens->getNextMeaningfulToken($index); - if ($tokens[$nextIndex]->isGivenKind([T_FUNCTION, T_NS_SEPARATOR, T_PRIVATE, T_PROTECTED, T_PUBLIC])) { + if ($tokens[$nextIndex]->isGivenKind([T_FUNCTION, T_NS_SEPARATOR, T_PRIVATE, T_PROTECTED, T_PUBLIC, T_STRING, CT::T_NULLABLE_TYPE])) { continue; } diff --git a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php index 60782fec0fa..1b7f4c9f8ac 100644 --- a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php +++ b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php @@ -161,8 +161,10 @@ private function fixElement(Tokens $tokens, string $type, int $index): void private function expandElement(Tokens $tokens, string $type, int $startIndex, int $endIndex): void { $divisionContent = null; + if ($tokens[$startIndex - 1]->isWhitespace()) { $divisionContent = $tokens[$startIndex - 1]->getContent(); + if (Preg::match('#(\n|\r\n)#', $divisionContent, $matches)) { $divisionContent = $matches[0].trim($divisionContent, "\r\n"); } @@ -189,6 +191,7 @@ private function expandElement(Tokens $tokens, string $type, int $startIndex, in } $tokens[$i] = new Token(';'); + if ($tokens[$i + 1]->isWhitespace()) { $tokens->clearAt($i + 1); } @@ -209,12 +212,13 @@ private function expandElement(Tokens $tokens, string $type, int $startIndex, in private function getModifiersSequences(Tokens $tokens, string $type, int $startIndex, int $endIndex): array { if ('property' === $type) { - $tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_VAR, T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT]; + $tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_VAR, T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; } else { $tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_CONST]; } $sequence = []; + for ($i = $startIndex; $i < $endIndex - 1; ++$i) { if ($tokens[$i]->isComment()) { continue; diff --git a/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php b/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php index cdc057468c9..7bfb88e3d70 100644 --- a/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php +++ b/tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php @@ -197,10 +197,78 @@ public function provideFix71Cases(): array } /** + * @dataProvider provideFix74Cases + * @requires PHP 7.4 + */ + public function testFix74(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix74Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix80Cases(): \Generator { - $this->doTest('Self();'); + yield ['Self();']; + + yield [ + 'doTest($expected, $input); + } + + public function provideFix80Cases(): \Generator + { + yield [ + ' Date: Fri, 3 Sep 2021 13:16:50 +0200 Subject: [PATCH 71/80] PHP8.1 - "readonly" property modifier support --- .composer-require-checker.json | 3 +- src/AbstractDoctrineAnnotationFixer.php | 8 +- .../ClassAttributesSeparationFixer.php | 6 +- .../SingleClassElementPerStatementFixer.php | 4 + .../ClassNotation/VisibilityRequiredFixer.php | 32 +++++-- .../SingleSpaceAfterConstructFixer.php | 4 + .../Phpdoc/NoSuperfluousPhpdocTagsFixer.php | 8 ++ src/Fixer/Phpdoc/PhpdocLineSpanFixer.php | 4 + .../Phpdoc/PhpdocVarWithoutNameFixer.php | 4 + src/Tokenizer/Analyzer/CommentsAnalyzer.php | 40 +++++---- src/Tokenizer/Token.php | 2 +- .../Transformer/NullableTypeTransformer.php | 39 +++++---- .../TypeAlternationTransformer.php | 6 ++ .../Casing/LowercaseKeywordsFixerTest.php | 48 +++++++++++ .../ClassAttributesSeparationFixerTest.php | 33 +++++++ .../NoNullPropertyInitializationFixerTest.php | 20 +++++ .../NoUnneededFinalMethodFixerTest.php | 32 +++++++ .../ProtectedToPrivateFixerTest.php | 46 ++++++++++ ...ingleClassElementPerStatementFixerTest.php | 41 +++++++++ .../VisibilityRequiredFixerTest.php | 44 ++++++++++ ...rineAnnotationArrayAssignmentFixerTest.php | 57 +++++++++++++ .../PhpdocToPropertyTypeFixerTest.php | 16 ++++ .../SingleSpaceAfterConstructFixerTest.php | 35 ++++++++ .../NoSuperfluousPhpdocTagsFixerTest.php | 46 ++++++++++ .../Fixer/Phpdoc/PhpdocLineSpanFixerTest.php | 51 +++++++++++ .../Phpdoc/PhpdocVarWithoutNameFixerTest.php | 58 +++++++++++++ .../Fixer/Whitespace/TypesSpacesFixerTest.php | 29 +++++++ tests/Fixtures/Integration/misc/PHP8_1.test | 14 +++ .../Analyzer/CommentsAnalyzerTest.php | 28 ++++++ tests/Tokenizer/TokensAnalyzerTest.php | 49 +++++++++++ .../ConstructorPromotionTransformerTest.php | 36 ++++++++ .../NullableTypeTransformerTest.php | 85 +++++++++++++------ .../TypeAlternationTransformerTest.php | 44 ++++++++++ 33 files changed, 904 insertions(+), 68 deletions(-) diff --git a/.composer-require-checker.json b/.composer-require-checker.json index 183841e09f9..ccc607ed571 100644 --- a/.composer-require-checker.json +++ b/.composer-require-checker.json @@ -14,7 +14,8 @@ "T_NAME_FULLY_QUALIFIED", "T_NAME_QUALIFIED", "T_NAME_RELATIVE", - "T_NULLSAFE_OBJECT_OPERATOR" + "T_NULLSAFE_OBJECT_OPERATOR", + "T_READONLY" ], "php-core-extensions" : [ "dom", "mbstring", "Phar", diff --git a/src/AbstractDoctrineAnnotationFixer.php b/src/AbstractDoctrineAnnotationFixer.php index 0399b0f71bb..857067e1c2f 100644 --- a/src/AbstractDoctrineAnnotationFixer.php +++ b/src/AbstractDoctrineAnnotationFixer.php @@ -218,7 +218,13 @@ private function nextElementAcceptsDoctrineAnnotations(Tokens $tokens, int $inde return true; } - while ($tokens[$index]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_NS_SEPARATOR, T_STRING, CT::T_NULLABLE_TYPE])) { + $modifierKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_NS_SEPARATOR, T_STRING, CT::T_NULLABLE_TYPE]; + + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $modifierKinds[] = T_READONLY; + } + + while ($tokens[$index]->isGivenKind($modifierKinds)) { $index = $tokens->getNextMeaningfulToken($index); } diff --git a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php index 06e60b6f421..d4c70625900 100644 --- a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php +++ b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php @@ -499,7 +499,11 @@ private function getElementsByClass(Tokens $tokens): \Generator private function getFirstTokenIndexOfClassElement(Tokens $tokens, array $class, array $element): int { - static $modifierTypes = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; + $modifierTypes = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; + + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $modifierTypes[] = T_READONLY; + } $firstElementAttributeIndex = $element['index']; diff --git a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php index 1b7f4c9f8ac..db7811fec9c 100644 --- a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php +++ b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php @@ -213,6 +213,10 @@ private function getModifiersSequences(Tokens $tokens, string $type, int $startI { if ('property' === $type) { $tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_VAR, T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; + + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $tokenKinds[] = T_READONLY; + } } else { $tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_CONST]; } diff --git a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php index 8d0ec21b2d1..c8fd622624e 100644 --- a/src/Fixer/ClassNotation/VisibilityRequiredFixer.php +++ b/src/Fixer/ClassNotation/VisibilityRequiredFixer.php @@ -100,6 +100,16 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $propertyTypeDeclarationKinds = [T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION]; + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $propertyReadOnlyType = T_READONLY; + $propertyTypeDeclarationKinds[] = T_READONLY; + } else { + $propertyReadOnlyType = -999; + } + + $expectedKindsGeneric = [T_ABSTRACT, T_FINAL, T_PRIVATE, T_PROTECTED, T_PUBLIC, T_STATIC, T_VAR]; + $expectedKindsPropertyKinds = array_merge($expectedKindsGeneric, $propertyTypeDeclarationKinds); + foreach (array_reverse($tokensAnalyzer->getClassyElements(), true) as $index => $element) { if (!\in_array($element['type'], $this->configuration['elements'], true)) { continue; @@ -109,18 +119,20 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $visibilityIndex = null; $staticIndex = null; $typeIndex = null; + $readOnlyIndex = null; $prevIndex = $tokens->getPrevMeaningfulToken($index); - $expectedKinds = [T_ABSTRACT, T_FINAL, T_PRIVATE, T_PROTECTED, T_PUBLIC, T_STATIC, T_VAR]; - - if ('property' === $element['type']) { - $expectedKinds = array_merge($expectedKinds, $propertyTypeDeclarationKinds); - } + $expectedKinds = 'property' === $element['type'] + ? $expectedKindsPropertyKinds + : $expectedKindsGeneric + ; while ($tokens[$prevIndex]->isGivenKind($expectedKinds)) { if ($tokens[$prevIndex]->isGivenKind([T_ABSTRACT, T_FINAL])) { $abstractFinalIndex = $prevIndex; } elseif ($tokens[$prevIndex]->isGivenKind(T_STATIC)) { $staticIndex = $prevIndex; + } elseif ($tokens[$prevIndex]->isGivenKind($propertyReadOnlyType)) { + $readOnlyIndex = $prevIndex; } elseif ($tokens[$prevIndex]->isGivenKind($propertyTypeDeclarationKinds)) { $typeIndex = $prevIndex; } else { @@ -138,11 +150,13 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - if (null !== $staticIndex) { - if ($this->isKeywordPlacedProperly($tokens, $staticIndex, $index)) { - $index = $staticIndex; + $swapIndex = $staticIndex ?? $readOnlyIndex; // "static" property cannot be "readonly", so there can always be at most one swap + + if (null !== $swapIndex) { + if ($this->isKeywordPlacedProperly($tokens, $swapIndex, $index)) { + $index = $swapIndex; } else { - $this->moveTokenAndEnsureSingleSpaceFollows($tokens, $staticIndex, $index); + $this->moveTokenAndEnsureSingleSpaceFollows($tokens, $swapIndex, $index); } } diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index 5d3f64f57fd..dc1c2827f6b 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -113,6 +113,10 @@ public function configure(array $configuration): void self::$tokenMap['match'] = T_MATCH; } + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + self::$tokenMap['readonly'] = T_READONLY; + } + $this->fixTokenMap = []; foreach ($this->configuration['constructs'] as $key) { diff --git a/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php b/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php index 5548e8032e0..e5e630c37d9 100644 --- a/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php +++ b/src/Fixer/Phpdoc/NoSuperfluousPhpdocTagsFixer.php @@ -183,6 +183,10 @@ private function findDocumentedElement(Tokens $tokens, int $docCommentIndex): ?i $kindsBeforeProperty = [T_STATIC, T_PRIVATE, T_PROTECTED, T_PUBLIC, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, T_STRING, T_NS_SEPARATOR]; + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $kindsBeforeProperty[] = T_READONLY; + } + $index = $tokens->getNextMeaningfulToken($docCommentIndex); if (!$tokens[$index]->isGivenKind($kindsBeforeProperty)) { @@ -247,6 +251,10 @@ private function fixPropertyDocComment(string $content, Tokens $tokens, int $ind { $propertyModifierKinds = [T_STATIC, T_PRIVATE, T_PROTECTED, T_PUBLIC]; + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $propertyModifierKinds[] = T_READONLY; + } + $docBlock = new DocBlock($content); do { diff --git a/src/Fixer/Phpdoc/PhpdocLineSpanFixer.php b/src/Fixer/Phpdoc/PhpdocLineSpanFixer.php index 9be0e621254..53963ec714d 100644 --- a/src/Fixer/Phpdoc/PhpdocLineSpanFixer.php +++ b/src/Fixer/Phpdoc/PhpdocLineSpanFixer.php @@ -138,6 +138,10 @@ private function getDocBlockIndex(Tokens $tokens, int $index): int CT::T_NULLABLE_TYPE, ]; + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $propertyPartKinds[] = T_READONLY; + } + do { $index = $tokens->getPrevNonWhitespace($index); } while ($tokens[$index]->isGivenKind($propertyPartKinds)); diff --git a/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php b/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php index ce533d8aead..7bfca416015 100644 --- a/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php +++ b/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php @@ -97,6 +97,10 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void // We want only doc blocks that are for properties and thus have specified access modifiers next $propertyModifierKinds = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_VAR]; + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $propertyModifierKinds[] = T_READONLY; + } + if (!$tokens[$nextIndex]->isGivenKind($propertyModifierKinds)) { continue; } diff --git a/src/Tokenizer/Analyzer/CommentsAnalyzer.php b/src/Tokenizer/Analyzer/CommentsAnalyzer.php index 47fbbdf0163..2726086f72b 100644 --- a/src/Tokenizer/Analyzer/CommentsAnalyzer.php +++ b/src/Tokenizer/Analyzer/CommentsAnalyzer.php @@ -156,22 +156,30 @@ public function getCommentBlockIndices(Tokens $tokens, int $index): ?array */ private function isStructuralElement(Token $token): bool { - static $skip = [ - T_PRIVATE, - T_PROTECTED, - T_PUBLIC, - T_VAR, - T_FUNCTION, - T_ABSTRACT, - T_CONST, - T_NAMESPACE, - T_REQUIRE, - T_REQUIRE_ONCE, - T_INCLUDE, - T_INCLUDE_ONCE, - T_FINAL, - T_STATIC, - ]; + static $skip; + + if (null === $skip) { + $skip = [ + T_PRIVATE, + T_PROTECTED, + T_PUBLIC, + T_VAR, + T_FUNCTION, + T_ABSTRACT, + T_CONST, + T_NAMESPACE, + T_REQUIRE, + T_REQUIRE_ONCE, + T_INCLUDE, + T_INCLUDE_ONCE, + T_FINAL, + T_STATIC, + ]; + + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $skip[] = T_READONLY; + } + } return $token->isClassy() || $token->isGivenKind($skip); } diff --git a/src/Tokenizer/Token.php b/src/Tokenizer/Token.php index 5ff6d2ee0ea..df6efdf6e8b 100644 --- a/src/Tokenizer/Token.php +++ b/src/Tokenizer/Token.php @@ -306,7 +306,7 @@ public static function getKeywords(): array 'T_INTERFACE', 'T_ISSET', 'T_LIST', 'T_LOGICAL_AND', 'T_LOGICAL_OR', 'T_LOGICAL_XOR', 'T_NAMESPACE', 'T_MATCH', 'T_NEW', 'T_PRINT', 'T_PRIVATE', 'T_PROTECTED', 'T_PUBLIC', 'T_REQUIRE', 'T_REQUIRE_ONCE', 'T_RETURN', 'T_STATIC', 'T_SWITCH', 'T_THROW', 'T_TRAIT', 'T_TRY', - 'T_UNSET', 'T_USE', 'T_VAR', 'T_WHILE', 'T_YIELD', 'T_YIELD_FROM', + 'T_UNSET', 'T_USE', 'T_VAR', 'T_WHILE', 'T_YIELD', 'T_YIELD_FROM', 'T_READONLY', ]) + [ CT::T_ARRAY_TYPEHINT => CT::T_ARRAY_TYPEHINT, CT::T_CLASS_CONSTANT => CT::T_CLASS_CONSTANT, diff --git a/src/Tokenizer/Transformer/NullableTypeTransformer.php b/src/Tokenizer/Transformer/NullableTypeTransformer.php index 0a7cc7ff90f..c8f17ecf72e 100644 --- a/src/Tokenizer/Transformer/NullableTypeTransformer.php +++ b/src/Tokenizer/Transformer/NullableTypeTransformer.php @@ -54,23 +54,32 @@ public function process(Tokens $tokens, Token $token, int $index): void return; } + static $types; + + if (null === $types) { + $types = [ + '(', + ',', + [CT::T_TYPE_COLON], + [CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC], + [CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED], + [CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE], + [CT::T_ATTRIBUTE_CLOSE], + [T_PRIVATE], + [T_PROTECTED], + [T_PUBLIC], + [T_VAR], + [T_STATIC], + ]; + + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $types[] = [T_READONLY]; + } + } + $prevIndex = $tokens->getPrevMeaningfulToken($index); - $prevToken = $tokens[$prevIndex]; - if ($prevToken->equalsAny([ - '(', - ',', - [CT::T_TYPE_COLON], - [CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC], - [CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED], - [CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE], - [CT::T_ATTRIBUTE_CLOSE], - [T_PRIVATE], - [T_PROTECTED], - [T_PUBLIC], - [T_VAR], - [T_STATIC], - ])) { + if ($tokens[$prevIndex]->equalsAny($types)) { $tokens[$index] = new Token([CT::T_NULLABLE_TYPE, '?']); } } diff --git a/src/Tokenizer/Transformer/TypeAlternationTransformer.php b/src/Tokenizer/Transformer/TypeAlternationTransformer.php index 22509f359cd..384960b70f1 100644 --- a/src/Tokenizer/Transformer/TypeAlternationTransformer.php +++ b/src/Tokenizer/Transformer/TypeAlternationTransformer.php @@ -71,6 +71,12 @@ public function process(Tokens $tokens, Token $token, int $index): void return; } + if (\defined('T_READONLY') && $prevToken->isGivenKind(T_READONLY)) { // @TODO: drop condition when PHP 8.1+ is required + $this->replaceToken($tokens, $index); + + return; + } + if (!$prevToken->equalsAny(['(', ','])) { return; } diff --git a/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php b/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php index a5ae2e37bbd..0dbec278bed 100644 --- a/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php +++ b/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php @@ -109,6 +109,54 @@ public function __construct( privatE float $z = 0.0, ) {} } +', + ]; + } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, string $input): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'readonly - cannot have default value, fixer should not crash' => [ + ' false], ]; } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public static function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public static function provideFix80Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public static function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected); + } + + public function provideFix81Cases(): \Generator + { + yield 'readonly properties are always typed, make sure the fixer does not crash' => [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'some readonly properties' => [ + 'fixer->configure($config); + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'readonly' => [ + ' 'single', + ], + ]; + } } diff --git a/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php b/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php index 4e9b9b0c187..ce34194bb89 100644 --- a/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php +++ b/tests/Fixer/Phpdoc/PhpdocVarWithoutNameFixerTest.php @@ -476,6 +476,64 @@ class A {} // for the candidate check list($bar) = a(); ', ], + 'const are not handled by this fixer' => [ + ' SKIPPED_TYPES + */ + private const SKIPPED_TYPES = ["a" => true]; +} +', + ], + ]; + } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'readonly' => [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'getNextTokenOfKind(0, [[T_COMMENT], [T_DOC_COMMENT]]); + $analyzer = new CommentsAnalyzer(); + + static::assertTrue($analyzer->isBeforeStructuralElement($tokens, $index)); + } + + public function providePhpdocCandidatePhp81Cases(): \Generator + { + yield 'public readonly' => [ + ' [ + ' [ + 'getClassyElements(); + + array_walk( + $expected, + static function (array &$element, $index) use ($tokens): void { + $element['token'] = $tokens[$index]; + ksort($element); + } + ); + + static::assertSame($expected, $elements); + } + + public function provideGetClassyElements81Cases(): \Generator + { + yield [ + [ + 11 => [ + 'classIndex' => 1, + 'type' => 'property', // $prop1 + ], + 20 => [ + 'classIndex' => 1, + 'type' => 'property', // $prop2 + ], + 29 => [ + 'classIndex' => 1, + 'type' => 'property', // $prop13 + ], + ], + 'doTest( + $source, + $expectedTokens, + [ + CT::T_TYPE_ALTERNATION, + ] + ); + } + + public function provideFix81Cases(): \Generator + { + yield 'readonly' => [ + [ + 14 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, + 23 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, + 36 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, + 52 => CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, + ], + 'doTest( $source, @@ -149,34 +149,71 @@ public function testProcess80(string $source, array $expectedTokens = []): void ); } - public function provideProcess80Cases(): array + public function provideProcess80Cases(): \Generator { - return [ + yield [ [ - ' CT::T_NULLABLE_TYPE, - 29 => CT::T_NULLABLE_TYPE, - 41 => CT::T_NULLABLE_TYPE, - ], + 17 => CT::T_NULLABLE_TYPE, + 29 => CT::T_NULLABLE_TYPE, + 41 => CT::T_NULLABLE_TYPE, ], + ' CT::T_NULLABLE_TYPE, - ], + 10 => CT::T_NULLABLE_TYPE, + ], + 'doTest( + $source, + $expectedTokens, + [ + CT::T_NULLABLE_TYPE, + ] + ); + } + + public function provideProcess81Cases(): \Generator + { + yield [ + [ + 19 => CT::T_NULLABLE_TYPE, + 33 => CT::T_NULLABLE_TYPE, + 47 => CT::T_NULLABLE_TYPE, ], + 'doTest( + $source, + $expectedTokens, + [ + CT::T_TYPE_ALTERNATION, + ] + ); + } + + public function provideFix81Cases(): \Generator + { + yield 'readonly' => [ + [ + 12 => CT::T_TYPE_ALTERNATION, + ], + ' [ + [ + 19 => CT::T_TYPE_ALTERNATION, + 30 => CT::T_TYPE_ALTERNATION, + 41 => CT::T_TYPE_ALTERNATION, + ], + ' Date: Tue, 7 Sep 2021 16:14:59 +0200 Subject: [PATCH 72/80] PHP8.1 - Enum (start) --- .composer-require-checker.json | 3 +- .../SingleSpaceAfterConstructFixer.php | 4 ++ src/Tokenizer/Token.php | 2 +- .../Casing/LowercaseKeywordsFixerTest.php | 13 ++++++ .../SingleSpaceAfterConstructFixerTest.php | 40 ++++++++++++++++--- tests/Fixtures/Integration/misc/PHP8_1.test | 14 ++++++- 6 files changed, 67 insertions(+), 9 deletions(-) diff --git a/.composer-require-checker.json b/.composer-require-checker.json index ccc607ed571..2f2afcdcd4d 100644 --- a/.composer-require-checker.json +++ b/.composer-require-checker.json @@ -15,7 +15,8 @@ "T_NAME_QUALIFIED", "T_NAME_RELATIVE", "T_NULLSAFE_OBJECT_OPERATOR", - "T_READONLY" + "T_READONLY", + "T_ENUM" ], "php-core-extensions" : [ "dom", "mbstring", "Phar", diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index dc1c2827f6b..f434b143901 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -117,6 +117,10 @@ public function configure(array $configuration): void self::$tokenMap['readonly'] = T_READONLY; } + if (\defined('T_ENUM')) { // @TODO: drop condition when PHP 8.1+ is required + self::$tokenMap['enum'] = T_ENUM; + } + $this->fixTokenMap = []; foreach ($this->configuration['constructs'] as $key) { diff --git a/src/Tokenizer/Token.php b/src/Tokenizer/Token.php index df6efdf6e8b..e1099825a9e 100644 --- a/src/Tokenizer/Token.php +++ b/src/Tokenizer/Token.php @@ -306,7 +306,7 @@ public static function getKeywords(): array 'T_INTERFACE', 'T_ISSET', 'T_LIST', 'T_LOGICAL_AND', 'T_LOGICAL_OR', 'T_LOGICAL_XOR', 'T_NAMESPACE', 'T_MATCH', 'T_NEW', 'T_PRINT', 'T_PRIVATE', 'T_PROTECTED', 'T_PUBLIC', 'T_REQUIRE', 'T_REQUIRE_ONCE', 'T_RETURN', 'T_STATIC', 'T_SWITCH', 'T_THROW', 'T_TRAIT', 'T_TRY', - 'T_UNSET', 'T_USE', 'T_VAR', 'T_WHILE', 'T_YIELD', 'T_YIELD_FROM', 'T_READONLY', + 'T_UNSET', 'T_USE', 'T_VAR', 'T_WHILE', 'T_YIELD', 'T_YIELD_FROM', 'T_READONLY', 'T_ENUM', ]) + [ CT::T_ARRAY_TYPEHINT => CT::T_ARRAY_TYPEHINT, CT::T_CLASS_CONSTANT => CT::T_CLASS_CONSTANT, diff --git a/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php b/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php index 0dbec278bed..78cf29a4e4a 100644 --- a/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php +++ b/tests/Fixer/Casing/LowercaseKeywordsFixerTest.php @@ -157,6 +157,19 @@ public function __construct( privatE READONLY float $z = 0.0, ) {} } +', + ]; + + yield 'enum full caps' => [ + ' [ ' [ + ' [ + ' Date: Fri, 3 Sep 2021 13:16:50 +0200 Subject: [PATCH 73/80] PHP8.1 - "final const" support --- php-cs-fixer | 20 +- .../Report/ListSetsReport/ReporterFactory.php | 5 +- src/DocBlock/Annotation.php | 4 +- .../NoUnneededFinalMethodFixer.php | 91 +++++---- .../ClassNotation/ProtectedToPrivateFixer.php | 81 ++++---- .../SingleSpaceAfterConstructFixer.php | 3 +- .../Console/Command/SelfUpdateCommandTest.php | 4 +- tests/Fixer/Casing/ConstantCaseFixerTest.php | 31 ++++ .../LowercaseStaticReferenceFixerTest.php | 16 ++ .../ClassAttributesSeparationFixerTest.php | 25 +++ .../NoUnneededFinalMethodFixerTest.php | 83 ++++++++- .../ProtectedToPrivateFixerTest.php | 17 +- ...ingleClassElementPerStatementFixerTest.php | 13 +- .../VisibilityRequiredFixerTest.php | 30 +++ .../Fixer/Import/NoUnusedImportsFixerTest.php | 36 +++- .../SingleSpaceAfterConstructFixerTest.php | 11 ++ .../ListNotation/ListSyntaxFixerTest.php | 4 +- .../PhpUnit/PhpUnitNamespacedFixerTest.php | 28 ++- .../Fixer/Phpdoc/PhpdocLineSpanFixerTest.php | 43 +++++ .../Phpdoc/PhpdocVarWithoutNameFixerTest.php | 12 ++ .../StringLineEndingFixerTest.php | 2 +- .../Whitespace/IndentationTypeFixerTest.php | 8 +- .../Fixer/Whitespace/LineEndingFixerTest.php | 14 +- .../NoTrailingWhitespaceFixerTest.php | 2 +- .../SingleBlankLineAtEofFixerTest.php | 21 +-- tests/Fixtures/Integration/misc/PHP8_1.test | 12 ++ .../Tokenizer/Analyzer/ClassyAnalyzerTest.php | 2 +- .../Analyzer/CommentsAnalyzerTest.php | 16 ++ tests/Tokenizer/TokensAnalyzerTest.php | 46 ++++- .../NameQualifiedTransformerTest.php | 175 +++++++++--------- 30 files changed, 636 insertions(+), 219 deletions(-) diff --git a/php-cs-fixer b/php-cs-fixer index fd9e6011c89..7d1749c8304 100755 --- a/php-cs-fixer +++ b/php-cs-fixer @@ -21,22 +21,22 @@ if (defined('HHVM_VERSION_ID')) { } else { exit(1); } +} elseif (!defined('PHP_VERSION_ID')) { // PHP_VERSION_ID is available as of PHP 5.2.7 + fwrite(STDERR, 'PHP version no supported, please update. Current PHP version: '.PHP_VERSION.".\n"); + + exit(1); +} elseif (\PHP_VERSION_ID === 80000) { + fwrite(STDERR, "PHP CS Fixer is not able run on PHP 8.0.0 due to bug in PHP tokenizer (https://bugs.php.net/bug.php?id=80462).\n"); + fwrite(STDERR, "Update PHP version to unblock execution.\n"); + + exit(1); } elseif ( - !defined('PHP_VERSION_ID') - || \PHP_VERSION_ID === 80000 - || \PHP_VERSION_ID < 70103 + \PHP_VERSION_ID < 70103 || \PHP_VERSION_ID >= 80100 ) { fwrite(STDERR, "PHP needs to be a minimum version of PHP 7.1.3 and maximum version of PHP 8.0.*.\n"); fwrite(STDERR, 'Current PHP version: '.PHP_VERSION.".\n"); - if (defined('PHP_VERSION_ID') && \PHP_VERSION_ID === 80000) { - fwrite(STDERR, "PHP CS Fixer is not able run on PHP 8.0.0 due to bug in PHP tokenizer (https://bugs.php.net/bug.php?id=80462).\n"); - fwrite(STDERR, "Update PHP version to unblock execution.\n"); - - exit(1); - } - if (getenv('PHP_CS_FIXER_IGNORE_ENV')) { fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n"); } else { diff --git a/src/Console/Report/ListSetsReport/ReporterFactory.php b/src/Console/Report/ListSetsReport/ReporterFactory.php index 96ce3d556ea..5e2f277515a 100644 --- a/src/Console/Report/ListSetsReport/ReporterFactory.php +++ b/src/Console/Report/ListSetsReport/ReporterFactory.php @@ -54,10 +54,7 @@ public function registerBuiltInReporters(): self return $this; } - /** - * @return $this - */ - public function registerReporter(ReporterInterface $reporter) + public function registerReporter(ReporterInterface $reporter): self { $format = $reporter->getFormat(); diff --git a/src/DocBlock/Annotation.php b/src/DocBlock/Annotation.php index f06b2e1b65c..5d4376427ef 100644 --- a/src/DocBlock/Annotation.php +++ b/src/DocBlock/Annotation.php @@ -163,11 +163,9 @@ public function getTag(): Tag } /** - * @return TypeExpression - * * @internal */ - public function getTypeExpression() + public function getTypeExpression(): TypeExpression { return new TypeExpression($this->getTypesContent(), $this->namespace, $this->namespaceUses); } diff --git a/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php b/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php index dadc06d1b8f..eec3ef50650 100644 --- a/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php +++ b/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php @@ -23,6 +23,7 @@ use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; +use PhpCsFixer\Tokenizer\TokensAnalyzer; /** * @author Filippo Tessarotto @@ -90,17 +91,20 @@ public function isRisky(): bool */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { - $tokensCount = \count($tokens); - for ($index = 0; $index < $tokensCount; ++$index) { - if (!$tokens[$index]->isGivenKind(T_CLASS)) { + foreach ($this->getClassMethods($tokens) as $element) { + $index = $element['method_final_index']; + + if ($element['class_is_final']) { + $this->clearFinal($tokens, $index); + continue; } - $classOpen = $tokens->getNextTokenOfKind($index, ['{']); - $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)]; - $classIsFinal = $prevToken->isGivenKind(T_FINAL); + if (!$element['method_is_private'] || false === $this->configuration['private_methods'] || $element['method_is_constructor']) { + continue; + } - $this->fixClass($tokens, $classOpen, $classIsFinal); + $this->clearFinal($tokens, $index); } } @@ -117,54 +121,67 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn ]); } - private function fixClass(Tokens $tokens, int $classOpenIndex, bool $classIsFinal): void + private function getClassMethods(Tokens $tokens): \Generator { - $tokensCount = \count($tokens); + $tokensAnalyzer = new TokensAnalyzer($tokens); + $modifierKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_STATIC]; - for ($index = $classOpenIndex + 1; $index < $tokensCount; ++$index) { - // Class end - if ($tokens[$index]->equals('}')) { - return; - } + $classesAreFinal = []; + $elements = $tokensAnalyzer->getClassyElements(); - // Skip method content - if ($tokens[$index]->equals('{')) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + for (end($elements);; prev($elements)) { + $index = key($elements); - continue; + if (null === $index) { + break; } - if (!$tokens[$index]->isGivenKind(T_FINAL)) { - continue; + $element = current($elements); + + if ('method' !== $element['type']) { + continue; // not a method } - if (!$classIsFinal && (!$this->isPrivateMethodOtherThanConstructor($tokens, $index, $classOpenIndex) || !$this->configuration['private_methods'])) { - continue; + $classIndex = $element['classIndex']; + + if (!\array_key_exists($classIndex, $classesAreFinal)) { + $prevToken = $tokens[$tokens->getPrevMeaningfulToken($classIndex)]; + $classesAreFinal[$classIndex] = $prevToken->isGivenKind(T_FINAL); } - $tokens->clearAt($index); + $element['class_is_final'] = $classesAreFinal[$classIndex]; + $element['method_is_constructor'] = '__construct' === strtolower($tokens[$tokens->getNextMeaningfulToken($index)]->getContent()); + $element['method_final_index'] = null; + $element['method_is_private'] = false; - ++$index; + $previous = $index; - if ($tokens[$index]->isWhitespace()) { - $tokens->clearAt($index); - } + do { + $previous = $tokens->getPrevMeaningfulToken($previous); + + if ($tokens[$previous]->isGivenKind(T_PRIVATE)) { + $element['method_is_private'] = true; + } elseif ($tokens[$previous]->isGivenKind(T_FINAL)) { + $element['method_final_index'] = $previous; + } + } while ($tokens[$previous]->isGivenKind($modifierKinds)); + + yield $element; } } - private function isPrivateMethodOtherThanConstructor(Tokens $tokens, int $index, int $classOpenIndex): bool + private function clearFinal(Tokens $tokens, ?int $index): void { - $index = max($classOpenIndex + 1, $tokens->getPrevTokenOfKind($index, [';', '{', '}'])); - $private = false; + if (null === $index) { + return; + } - while (!$tokens[$index]->isGivenKind(T_FUNCTION)) { - if ($tokens[$index]->isGivenKind(T_PRIVATE)) { - $private = true; - } + $tokens->clearAt($index); - $index = $tokens->getNextMeaningfulToken($index); - } + ++$index; - return $private && '__construct' !== strtolower($tokens[$tokens->getNextMeaningfulToken($index)]->getContent()); + if ($tokens[$index]->isWhitespace()) { + $tokens->clearAt($index); + } } } diff --git a/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php b/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php index aaabb095184..b04c5eacf67 100644 --- a/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php +++ b/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php @@ -21,6 +21,7 @@ use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; +use PhpCsFixer\Tokenizer\TokensAnalyzer; /** * @author Filippo Tessarotto @@ -75,58 +76,76 @@ public function isCandidate(Tokens $tokens): bool */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { - $end = \count($tokens) - 3; // min. number of tokens to form a class candidate to fix - for ($index = 0; $index < $end; ++$index) { - if (!$tokens[$index]->isGivenKind(T_CLASS)) { - continue; - } + $tokensAnalyzer = new TokensAnalyzer($tokens); + $modifierKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_NS_SEPARATOR, T_STRING, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, T_STATIC, CT::T_TYPE_ALTERNATION]; + + if (\defined('T_READONLY')) { // @TODO: drop condition when PHP 8.1+ is required + $modifierKinds[] = T_READONLY; + } + + $classesCandidate = []; - $classOpen = $tokens->getNextTokenOfKind($index, ['{']); - $classClose = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpen); + foreach ($tokensAnalyzer->getClassyElements() as $index => $element) { + $classIndex = $element['classIndex']; - if (!$this->skipClass($tokens, $index, $classOpen, $classClose)) { - $this->fixClass($tokens, $classOpen, $classClose); + if (!\array_key_exists($classIndex, $classesCandidate)) { + $classesCandidate[$classIndex] = $this->isClassCandidate($tokens, $classIndex); } - $index = $classClose; - } - } + if (false === $classesCandidate[$classIndex]) { + continue; // not "final" class, "extends", is "anonymous" or uses trait + } - private function fixClass(Tokens $tokens, int $classOpenIndex, int $classCloseIndex): void - { - for ($index = $classOpenIndex + 1; $index < $classCloseIndex; ++$index) { - if ($tokens[$index]->equals('{')) { - $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index); + $previous = $index; + $isProtected = false; + $isFinal = false; + + do { + $previous = $tokens->getPrevMeaningfulToken($previous); + if ($tokens[$previous]->isGivenKind(T_PROTECTED)) { + $isProtected = $previous; + } elseif ($tokens[$previous]->isGivenKind(T_FINAL)) { + $isFinal = $previous; + } + } while ($tokens[$previous]->isGivenKind($modifierKinds)); + + if (false === $isProtected) { continue; } - if (!$tokens[$index]->isGivenKind(T_PROTECTED)) { - continue; + if ($isFinal && 'const' === $element['type']) { + continue; // Final constants cannot be private } - $tokens[$index] = new Token([T_PRIVATE, 'private']); + $element['protected_index'] = $isProtected; + $tokens[$element['protected_index']] = new Token([T_PRIVATE, 'private']); } } - /** - * Decide whether to skip the fix for given class. - */ - private function skipClass(Tokens $tokens, int $classIndex, int $classOpenIndex, int $classCloseIndex): bool + private function isClassCandidate(Tokens $tokens, int $classIndex): bool { $prevToken = $tokens[$tokens->getPrevMeaningfulToken($classIndex)]; + if (!$prevToken->isGivenKind(T_FINAL)) { - return true; + return false; } - for ($index = $classIndex; $index < $classOpenIndex; ++$index) { - if ($tokens[$index]->isGivenKind(T_EXTENDS)) { - return true; - } + $classNameIndex = $tokens->getNextMeaningfulToken($classIndex); // move to class name as anonymous class is never "final" + $classExtendsIndex = $tokens->getNextMeaningfulToken($classNameIndex); // move to possible "extends" + + if ($tokens[$classExtendsIndex]->isGivenKind(T_EXTENDS)) { + return false; + } + + if (!$tokens->isTokenKindFound(CT::T_USE_TRAIT)) { + return true; // cheap test } - $useIndex = $tokens->getNextTokenOfKind($classIndex, [[CT::T_USE_TRAIT]]); + $classOpenIndex = $tokens->getNextTokenOfKind($classNameIndex, ['{']); + $classCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpenIndex); + $useIndex = $tokens->getNextTokenOfKind($classOpenIndex, [[CT::T_USE_TRAIT]]); - return $useIndex && $useIndex < $classCloseIndex; + return null === $useIndex || $useIndex > $classCloseIndex; } } diff --git a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php index f434b143901..6e25abcb4e8 100644 --- a/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php +++ b/src/Fixer/LanguageConstruct/SingleSpaceAfterConstructFixer.php @@ -108,8 +108,7 @@ public function configure(array $configuration): void { parent::configure($configuration); - // @TODO: drop condition when PHP 8.0+ is required - if (\defined('T_MATCH')) { + if (\defined('T_MATCH')) { // @TODO: drop condition when PHP 8.0+ is required self::$tokenMap['match'] = T_MATCH; } diff --git a/tests/Console/Command/SelfUpdateCommandTest.php b/tests/Console/Command/SelfUpdateCommandTest.php index 8b227a04bc6..fd47b4c5ba1 100644 --- a/tests/Console/Command/SelfUpdateCommandTest.php +++ b/tests/Console/Command/SelfUpdateCommandTest.php @@ -238,7 +238,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions( $versionChecker = $this->prophesize(\PhpCsFixer\Console\SelfUpdate\NewVersionCheckerInterface::class); $newMajorVersion = $this->getNewMajorReleaseVersion(); - $versionChecker->getLatestVersion()->will(function () use ($latestVersionSuccess, $newMajorVersion) { + $versionChecker->getLatestVersion()->will(function () use ($latestVersionSuccess, $newMajorVersion): string { if ($latestVersionSuccess) { return $newMajorVersion; } @@ -249,7 +249,7 @@ public function testExecuteWhenNotAbleToGetLatestVersions( $newMinorVersion = $this->getNewMinorReleaseVersion(); $versionChecker ->getLatestVersionOfMajor($this->getCurrentMajorVersion()) - ->will(function () use ($latestMinorVersionSuccess, $newMinorVersion) { + ->will(function () use ($latestMinorVersionSuccess, $newMinorVersion): string { if ($latestMinorVersionSuccess) { return $newMinorVersion; } diff --git a/tests/Fixer/Casing/ConstantCaseFixerTest.php b/tests/Fixer/Casing/ConstantCaseFixerTest.php index 21f028999a0..d18b411d478 100644 --- a/tests/Fixer/Casing/ConstantCaseFixerTest.php +++ b/tests/Fixer/Casing/ConstantCaseFixerTest.php @@ -203,4 +203,35 @@ public static function provideFix80Cases(): array ['False; } }'], ]; } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public static function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public static function provideFix81Cases(): \Generator + { + yield [ + ' [ ' [ @@ -289,6 +303,48 @@ final private function qux() } ', ], + 'final private static' => [ + 'bar3(); } + private function bar2(){ echo 1; } + + private function bar3(){ echo 2; } +}', + 'bar3(); } + private function bar2(){ echo 1; } + + private final function bar3(){ echo 2; } +}', + ], ]; } @@ -357,6 +413,29 @@ class Foo81 { public readonly string $prop1; readonly public string $prop2; readonly string $prop3; +} + ', + ]; + + yield [ + ' [ - " [ "doTest($expected, $input); } @@ -917,5 +917,16 @@ class Foo readonly float $z1, $z2, $z3; }', ]; + + yield [ + 'doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'simple' => [ @@ -1297,7 +1297,7 @@ public function testFix72(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFix72Cases() + public function provideFix72Cases(): array { return [ [ // TODO test shows lot of cases where imports are not removed while could be @@ -1370,7 +1370,7 @@ public function testFix80(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function providePhp80Cases() + public function providePhp80Cases(): \Generator { yield [ 'doTest($expected, $input); + } + + public function providePhp81Cases(): \Generator + { + yield 'final const' => [ + 'provideFixToShortSyntaxPhp72Cases()); } @@ -244,7 +244,7 @@ public function provideFixToShortSyntaxPhp73Cases(): \Generator ]; } - public function provideFixToLongSyntaxPhp73Cases() + public function provideFixToLongSyntaxPhp73Cases(): iterable { return TestCaseUtils::swapExpectedInputTestCases($this->provideFixToShortSyntaxPhp73Cases()); } diff --git a/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php index 2d02d477e15..e37ab08b49c 100644 --- a/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitNamespacedFixerTest.php @@ -271,11 +271,31 @@ public static function provideClassIsFixedCases(): \Generator { $classmap = require __DIR__.'/../../../vendor/composer/autoload_classmap.php'; - foreach (array_keys($classmap) as $class) { - if (!str_starts_with($class, 'PHPUnit_')) { - continue; + foreach ($classmap as $class => $file) { + if (str_starts_with($class, 'PHPUnit_')) { + yield $file => [$class]; } - yield [$class]; } } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + ' 'single', ], ]; + + yield [ + ' [ + ' SKIPPED_TYPES + */ + final public const SKIPPED_TYPES = ["a" => true]; +} +', + ]; } } diff --git a/tests/Fixer/StringNotation/StringLineEndingFixerTest.php b/tests/Fixer/StringNotation/StringLineEndingFixerTest.php index 019719e84c0..44480b99de6 100644 --- a/tests/Fixer/StringNotation/StringLineEndingFixerTest.php +++ b/tests/Fixer/StringNotation/StringLineEndingFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $heredocTemplate = "doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $cases = []; @@ -233,7 +233,7 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): array { $cases = []; @@ -307,7 +307,7 @@ public function testMessyWhitespacesReversed(string $expected, ?string $input = $this->doTest($input, $expected); } - public function provideMessyWhitespacesReversedCases() + public function provideMessyWhitespacesReversedCases(): array { return array_filter( $this->provideMessyWhitespacesCases(), @@ -328,7 +328,7 @@ public function testDoubleSpaceIndent(string $expected, ?string $input = null): $this->doTest($expected, $input); } - public function provideDoubleSpaceIndentCases() + public function provideDoubleSpaceIndentCases(): array { return [ ['doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { $cases = $this->provideCommonCases(); @@ -84,26 +84,24 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): \Generator { - $cases = array_map(static function (array $case): array { + yield from array_map(static function (array $case): array { return array_reverse($case); }, $this->provideCommonCases()); - $cases[] = [ + yield [ " [ diff --git a/tests/Fixer/Whitespace/NoTrailingWhitespaceFixerTest.php b/tests/Fixer/Whitespace/NoTrailingWhitespaceFixerTest.php index ac8763ce303..59c023eb294 100644 --- a/tests/Fixer/Whitespace/NoTrailingWhitespaceFixerTest.php +++ b/tests/Fixer/Whitespace/NoTrailingWhitespaceFixerTest.php @@ -33,7 +33,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): \Generator { yield from [ [ diff --git a/tests/Fixer/Whitespace/SingleBlankLineAtEofFixerTest.php b/tests/Fixer/Whitespace/SingleBlankLineAtEofFixerTest.php index 3cc74487cd9..164ec141da5 100644 --- a/tests/Fixer/Whitespace/SingleBlankLineAtEofFixerTest.php +++ b/tests/Fixer/Whitespace/SingleBlankLineAtEofFixerTest.php @@ -34,7 +34,7 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases() + public function provideFixCases(): array { return [ 'Not adding an empty line in empty file.' => [ @@ -156,17 +156,16 @@ public function testMessyWhitespaces(string $expected, ?string $input = null): v $this->doTest($expected, $input); } - public function provideMessyWhitespacesCases() + public function provideMessyWhitespacesCases(): \Generator { - return [ - [ - " false, 9 => true, 12 => false, 14 => true, 18 => true, 21 => true, 25 => true, 32 => true], ], - [ + 'with reference' => [ ' false, 5 => true, 10 => true, 17 => true, 23 => false, 25 => true], ], diff --git a/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php b/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php index d925dd968c8..4cd4a5770be 100644 --- a/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php +++ b/tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php @@ -377,5 +377,21 @@ public function providePhpdocCandidatePhp81Cases(): \Generator yield 'readonly union' => [ ' [ + ' [ + ' [ + [ + 11 => [ + 'classIndex' => 1, + 'type' => 'const', // A + ], + 24 => [ + 'classIndex' => 1, + 'type' => 'const', // B + ], + ], + ' true, 7 => true, 11 => true], ' [ [3 => true, 7 => true, 11 => true], ' [ [3 => true], 'doIsConstantInvocationTest($expected, $source); + } + + public function provideIsConstantInvocationPhp81Cases(): \Generator + { + yield [ + [5 => false, 15 => false], + 'expectException(\LogicException::class); diff --git a/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php b/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php index 25d55ae5221..3ab25725aec 100644 --- a/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php +++ b/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php @@ -22,6 +22,7 @@ /** * @internal + * @requires PHP 8.0 * * @covers \PhpCsFixer\Tokenizer\Transformer\NameQualifiedTransformer */ @@ -34,7 +35,6 @@ final class NameQualifiedTransformerTest extends AbstractTransformerTestCase * @param null|Token[] $input * * @dataProvider provideProcessCases - * @requires PHP 8.0 */ public function testProcess(array $expected, array $input = null): void { @@ -60,12 +60,8 @@ public function testProcess(array $expected, array $input = null): void } } - public function provideProcessCases() + public function provideProcessCases(): \Generator { - if (\PHP_VERSION_ID < 80000) { - return; - } - yield 'string' => [ [ new Token([T_OPEN_TAG, " Date: Wed, 8 Sep 2021 13:06:06 +0200 Subject: [PATCH 74/80] Fix test warning --- tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php b/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php index 3ab25725aec..536a3b73c25 100644 --- a/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php +++ b/tests/Tokenizer/Transformer/NameQualifiedTransformerTest.php @@ -62,6 +62,10 @@ public function testProcess(array $expected, array $input = null): void public function provideProcessCases(): \Generator { + if (\PHP_VERSION_ID < 80000) { + return; // PHPUnit still calls this for no reason on non PHP8.0 + } + yield 'string' => [ [ new Token([T_OPEN_TAG, " Date: Wed, 8 Sep 2021 18:33:47 +0200 Subject: [PATCH 75/80] RegularCallableCallFixer must run before NativeFunctionInvocationFixer --- .../NativeFunctionInvocationFixer.php | 2 +- .../FunctionNotation/RegularCallableCallFixer.php | 10 ++++++++++ tests/AutoReview/FixerFactoryTest.php | 1 + ...ar_callable_call,native_function_invocation.test | 13 +++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/Fixtures/Integration/priority/regular_callable_call,native_function_invocation.test diff --git a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php index 0ae435d4c97..5cbffc88dea 100644 --- a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php +++ b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php @@ -167,7 +167,7 @@ function baz($options) * {@inheritdoc} * * Must run before GlobalNamespaceImportFixer. - * Must run after BacktickToShellExecFixer, StrictParamFixer. + * Must run after BacktickToShellExecFixer, RegularCallableCallFixer, StrictParamFixer. */ public function getPriority(): int { diff --git a/src/Fixer/FunctionNotation/RegularCallableCallFixer.php b/src/Fixer/FunctionNotation/RegularCallableCallFixer.php index cea13b2a01d..1cd3f6ec330 100644 --- a/src/Fixer/FunctionNotation/RegularCallableCallFixer.php +++ b/src/Fixer/FunctionNotation/RegularCallableCallFixer.php @@ -58,6 +58,16 @@ public function getDefinition(): FixerDefinitionInterface ); } + /** + * {@inheritdoc} + * + * Must run before NativeFunctionInvocationFixer. + */ + public function getPriority(): int + { + return 2; + } + /** * {@inheritdoc} */ diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 3059547d88b..21084181940 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -264,6 +264,7 @@ public function provideFixersPriorityCases(): array [$fixers['pow_to_exponentiation'], $fixers['no_spaces_after_function_name']], [$fixers['pow_to_exponentiation'], $fixers['no_spaces_inside_parenthesis']], [$fixers['protected_to_private'], $fixers['ordered_class_elements']], + [$fixers['regular_callable_call'], $fixers['native_function_invocation']], [$fixers['return_assignment'], $fixers['blank_line_before_statement']], [$fixers['semicolon_after_instruction'], $fixers['simplified_if_return']], [$fixers['simplified_if_return'], $fixers['multiline_whitespace_before_semicolons']], diff --git a/tests/Fixtures/Integration/priority/regular_callable_call,native_function_invocation.test b/tests/Fixtures/Integration/priority/regular_callable_call,native_function_invocation.test new file mode 100644 index 00000000000..55ea1026ea7 --- /dev/null +++ b/tests/Fixtures/Integration/priority/regular_callable_call,native_function_invocation.test @@ -0,0 +1,13 @@ +--TEST-- +Integration of fixers: regular_callable_call,native_function_invocation. +--RULESET-- +{"regular_callable_call": true, "native_function_invocation": true} +--EXPECT-- + Date: Mon, 6 Sep 2021 11:54:59 +0200 Subject: [PATCH 76/80] PHP8.1 - FirstClassCallable --- .../PhpUnitMockShortWillReturnFixer.php | 5 + .../PhpUnitTestCaseStaticMethodCallsFixer.php | 5 + src/Tokenizer/Analyzer/FunctionsAnalyzer.php | 4 + src/Tokenizer/CT.php | 1 + .../FirstClassCallableTransformer.php | 58 +++++++++++ tests/Fixer/Alias/ArrayPushFixerTest.php | 23 +++++ tests/Fixer/Alias/EregToPregFixerTest.php | 16 ++++ .../Fixer/Alias/NoAliasFunctionsFixerTest.php | 16 ++++ .../Alias/RandomApiMigrationFixerTest.php | 16 ++++ .../Casing/MagicMethodCasingFixerTest.php | 22 +++++ .../ModernizeTypesCastingFixerTest.php | 16 ++++ .../ControlStructure/YodaStyleFixerTest.php | 20 ++++ .../CombineNestedDirnameFixerTest.php | 14 +++ .../MethodArgumentSpaceFixerTest.php | 22 +++++ .../NoSpacesAfterFunctionNameFixerTest.php | 17 ++++ ...reachableDefaultArgumentValueFixerTest.php | 16 ++++ .../RegularCallableCallFixerTest.php | 16 ++++ .../Fixer/Import/NoUnusedImportsFixerTest.php | 10 ++ .../ErrorSuppressionFixerTest.php | 16 ++++ .../FunctionToConstantFixerTest.php | 16 ++++ .../ListNotation/ListSyntaxFixerTest.php | 16 ++++ .../PhpUnit/PhpUnitConstructFixerTest.php | 16 ++++ .../PhpUnitDedicateAssertFixerTest.php | 16 ++++ .../PhpUnitMockShortWillReturnFixerTest.php | 15 +++ ...UnitTestCaseStaticMethodCallsFixerTest.php | 24 +++++ .../NoSpacesInsideParenthesisFixerTest.php | 17 ++++ .../Analyzer/FunctionsAnalyzerTest.php | 31 ++++++ .../FirstClassCallableTransformerTest.php | 96 +++++++++++++++++++ 28 files changed, 560 insertions(+) create mode 100644 src/Tokenizer/Transformer/FirstClassCallableTransformer.php create mode 100644 tests/Tokenizer/Transformer/FirstClassCallableTransformerTest.php diff --git a/src/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixer.php b/src/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixer.php index dab8655a581..4e3ea63733d 100644 --- a/src/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitMockShortWillReturnFixer.php @@ -19,6 +19,7 @@ use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer; +use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -111,6 +112,10 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en continue; } + if ($tokens[$tokens->getNextMeaningfulToken($openingBraceIndex)]->isGivenKind(CT::T_FIRST_CLASS_CALLABLE)) { + continue; + } + $closingBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openingBraceIndex); $tokens[$functionToReplaceIndex] = new Token([T_STRING, self::RETURN_METHODS_MAP[strtolower($tokens[$functionToRemoveIndex]->getContent())]]); diff --git a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php index d543a96dc97..d6493e5da64 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php @@ -23,6 +23,7 @@ use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer; +use PhpCsFixer\Tokenizer\CT; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; use PhpCsFixer\Tokenizer\TokensAnalyzer; @@ -438,6 +439,10 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en continue; } + if ($tokens[$tokens->getNextMeaningfulToken($nextIndex)]->isGivenKind(CT::T_FIRST_CLASS_CALLABLE)) { + continue; + } + $methodName = $tokens[$index]->getContent(); if (isset($this->configuration['methods'][$methodName])) { diff --git a/src/Tokenizer/Analyzer/FunctionsAnalyzer.php b/src/Tokenizer/Analyzer/FunctionsAnalyzer.php index 080ee79e4f7..5edfab27cd4 100644 --- a/src/Tokenizer/Analyzer/FunctionsAnalyzer.php +++ b/src/Tokenizer/Analyzer/FunctionsAnalyzer.php @@ -69,6 +69,10 @@ public function isGlobalFunctionCall(Tokens $tokens, int $index): bool return true; } + if ($tokens[$tokens->getNextMeaningfulToken($nextIndex)]->isGivenKind(CT::T_FIRST_CLASS_CALLABLE)) { + return false; + } + if ($tokens->isChanged() || $tokens->getCodeHash() !== $this->functionsAnalysis['tokens']) { $this->buildFunctionsAnalysis($tokens); } diff --git a/src/Tokenizer/CT.php b/src/Tokenizer/CT.php index 59fea01f542..c2879569322 100644 --- a/src/Tokenizer/CT.php +++ b/src/Tokenizer/CT.php @@ -52,6 +52,7 @@ final class CT public const T_ATTRIBUTE_CLOSE = 10031; public const T_NAMED_ARGUMENT_NAME = 10032; public const T_NAMED_ARGUMENT_COLON = 10033; + public const T_FIRST_CLASS_CALLABLE = 10034; private function __construct() { diff --git a/src/Tokenizer/Transformer/FirstClassCallableTransformer.php b/src/Tokenizer/Transformer/FirstClassCallableTransformer.php new file mode 100644 index 00000000000..f96a3e6111d --- /dev/null +++ b/src/Tokenizer/Transformer/FirstClassCallableTransformer.php @@ -0,0 +1,58 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tokenizer\Transformer; + +use PhpCsFixer\Tokenizer\AbstractTransformer; +use PhpCsFixer\Tokenizer\CT; +use PhpCsFixer\Tokenizer\Token; +use PhpCsFixer\Tokenizer\Tokens; + +/** + * @internal + */ +final class FirstClassCallableTransformer extends AbstractTransformer +{ + /** + * {@inheritdoc} + */ + public function getRequiredPhpVersionId(): int + { + return 80100; + } + + /** + * {@inheritdoc} + */ + public function process(Tokens $tokens, Token $token, int $index): void + { + if ( + $token->isGivenKind(T_ELLIPSIS) + && $tokens[$tokens->getPrevMeaningfulToken($index)]->equals('(') + && $tokens[$tokens->getNextMeaningfulToken($index)]->equals(')') + ) { + $tokens[$index] = new Token([CT::T_FIRST_CLASS_CALLABLE, '...']); + } + } + + /** + * {@inheritdoc} + */ + public function getCustomTokens(): array + { + return [ + CT::T_FIRST_CLASS_CALLABLE, + ]; + } +} diff --git a/tests/Fixer/Alias/ArrayPushFixerTest.php b/tests/Fixer/Alias/ArrayPushFixerTest.php index baa4ddaad94..979da5a36fe 100644 --- a/tests/Fixer/Alias/ArrayPushFixerTest.php +++ b/tests/Fixer/Alias/ArrayPushFixerTest.php @@ -278,4 +278,27 @@ public function provideFix80Cases(): \Generator 'c[2], $b19);', ]; } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, string $input): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'simple 8.1' => [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'simple 8.1' => [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'simple 8.1' => [ + '__INVOKE(1, );' ); } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'static call to "__set_state".' => [ + ' [ + '__isset(...);', + '__ISSET(...);', + ]; + } } diff --git a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php index 3647f2c85f1..bbf258663bd 100644 --- a/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php +++ b/tests/Fixer/CastNotation/ModernizeTypesCastingFixerTest.php @@ -243,4 +243,20 @@ public function testFixPrePHP80(): void ;#' ); } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + ' true, 'identical' => true], ]; } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'does not make a lot of sense but is valid syntax, do not break 1' => [ + ' [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield ['doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + '', + '', + ]; + } } diff --git a/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php b/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php index af463f98f67..96ae4796b3c 100644 --- a/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php +++ b/tests/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixerTest.php @@ -177,4 +177,21 @@ public function provideFixPre80Cases(): \Generator 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'do not crash' => [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + '', + ]; + } } diff --git a/tests/Fixer/Import/NoUnusedImportsFixerTest.php b/tests/Fixer/Import/NoUnusedImportsFixerTest.php index a50f6de07bd..124b098df67 100644 --- a/tests/Fixer/Import/NoUnusedImportsFixerTest.php +++ b/tests/Fixer/Import/NoUnusedImportsFixerTest.php @@ -1452,5 +1452,15 @@ class Foo } ', ]; + + yield 'first callable class' => [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'fixer->configure(['pi123']); } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'first callable class' => [ + 'provideFixToShortSyntaxPhp73Cases()); } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'simple 8.1' => [ + 'doTest(self::generateTest('$this->assertSame(null, $a);')); } + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + self::generateTest('$this->assertEquals(...);'), + ]; + } + private function generateCases(string $expectedTemplate, string $inputTemplate): array { $functionTypes = ['Same' => true, 'NotSame' => false, 'Equals' => true, 'NotEquals' => false]; diff --git a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php index c9dcc0cb2e2..9f76e93805c 100644 --- a/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php @@ -490,6 +490,22 @@ public function provideFix73Cases(): array ]; } + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + self::generateTest('$a = $this->assertTrue(...);'), + ]; + } + private static function generateTest(string $content): string { return "method("someMethod")?->will($this?->returnValue(10)); } +}' + ); + } + + /** + * @requires PHP 8.1 + */ + public function testFix81(): void + { + $this->doTest( + 'method("someMethod")->will($this?->returnValue(...)); + } }' ); } diff --git a/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php b/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php index a02a27386bd..46583e8fe51 100644 --- a/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php +++ b/tests/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixerTest.php @@ -536,4 +536,28 @@ public function assertSame($a, $b) }' ); } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'first callable class' => [ + ' [ + [], + 'method(...); +$obj->$methodStr(...); +($obj->property)(...); +Foo::method(...); +$classStr::$methodStr(...); +self::{$complex . $expression}(...); +\'strlen\'(...); +[$obj, \'method\'](...); +[Foo::class, \'method\'](...) ?>', + ]; + } + /** * @dataProvider provideFunctionsWithArgumentsCases */ diff --git a/tests/Tokenizer/Transformer/FirstClassCallableTransformerTest.php b/tests/Tokenizer/Transformer/FirstClassCallableTransformerTest.php new file mode 100644 index 00000000000..ff5e97decbc --- /dev/null +++ b/tests/Tokenizer/Transformer/FirstClassCallableTransformerTest.php @@ -0,0 +1,96 @@ + + * Dariusz RumiƄski + * + * This source file is subject to the MIT license that is bundled + * with this source code in the file LICENSE. + */ + +namespace PhpCsFixer\Tests\Tokenizer\Transformer; + +use PhpCsFixer\Tests\Test\AbstractTransformerTestCase; +use PhpCsFixer\Tokenizer\CT; + +/** + * @internal + * + * @covers \PhpCsFixer\Tokenizer\Transformer\FirstClassCallableTransformer + */ +final class FirstClassCallableTransformerTest extends AbstractTransformerTestCase +{ + /** + * @dataProvider provideProcessCases + * @requires PHP 8.1 + */ + public function testProcess(array $expectedTokens, string $source): void + { + $this->doTest($source, $expectedTokens, [CT::T_FIRST_CLASS_CALLABLE]); + } + + public function provideProcessCases(): \Generator + { + yield 'set' => [ + [ + 3 => CT::T_FIRST_CLASS_CALLABLE, + 9 => CT::T_FIRST_CLASS_CALLABLE, + 15 => CT::T_FIRST_CLASS_CALLABLE, + 23 => CT::T_FIRST_CLASS_CALLABLE, + 31 => CT::T_FIRST_CLASS_CALLABLE, + 41 => CT::T_FIRST_CLASS_CALLABLE, + 49 => CT::T_FIRST_CLASS_CALLABLE, + 57 => CT::T_FIRST_CLASS_CALLABLE, + 71 => CT::T_FIRST_CLASS_CALLABLE, + 77 => CT::T_FIRST_CLASS_CALLABLE, + 88 => CT::T_FIRST_CLASS_CALLABLE, + 101 => CT::T_FIRST_CLASS_CALLABLE, + ], + 'method(...); +$obj->$methodStr(...); +($obj->property)(...); +Foo::method(...); +$classStr::$methodStr(...); +self::{$complex . $expression}(...); +\'strlen\'(...); +[$obj, \'method\'](...); +[Foo::class, \'method\'](...) ?>', + ]; + + yield 'comments and spacing' => [ + [ + 4 => CT::T_FIRST_CLASS_CALLABLE, + 12 => CT::T_FIRST_CLASS_CALLABLE, + 18 => CT::T_FIRST_CLASS_CALLABLE, + 28 => CT::T_FIRST_CLASS_CALLABLE, + 40 => CT::T_FIRST_CLASS_CALLABLE, + ], + 'method( ... ); +$obj->$methodStr( /* */ ... /* */ ); + ', + ]; + + yield 'not cases' => [ + [], + ' Date: Wed, 8 Sep 2021 15:02:39 +0200 Subject: [PATCH 77/80] PHP8.1 - New in initializers (start) --- src/Fixer/Alias/EregToPregFixer.php | 2 +- src/Fixer/Basic/PsrAutoloadingFixer.php | 13 ++- .../ClassNotation/FinalInternalClassFixer.php | 7 +- .../ClassNotation/SelfStaticAccessorFixer.php | 6 +- .../ClassUsage/DateTimeImmutableFixer.php | 39 +++---- .../Comment/SingleLineCommentStyleFixer.php | 2 +- .../Import/SingleImportPerStatementFixer.php | 2 +- src/Fixer/Operator/ConcatSpaceFixer.php | 3 +- src/Fixer/Operator/NewWithBracesFixer.php | 4 +- .../PhpUnit/PhpUnitDedicateAssertFixer.php | 5 +- .../PhpUnit/PhpUnitTestAnnotationFixer.php | 4 +- src/Fixer/Strict/DeclareStrictTypesFixer.php | 2 +- .../FixerConfigurationResolver.php | 6 +- tests/Fixer/Basic/PsrAutoloadingFixerTest.php | 21 ++++ .../FinalInternalClassFixerTest.php | 32 +++++- .../Fixer/Import/NoUnusedImportsFixerTest.php | 34 ++++++ .../SingleSpaceAfterConstructFixerTest.php | 17 +++ .../Fixer/Operator/NewWithBracesFixerTest.php | 64 +++++++++++ .../Analyzer/FunctionsAnalyzerTest.php | 7 +- tests/Tokenizer/TokensAnalyzerTest.php | 12 ++ ...BraceClassInstantiationTransformerTest.php | 103 ++++++++++++++---- .../FirstClassCallableTransformerTest.php | 2 +- 22 files changed, 315 insertions(+), 72 deletions(-) diff --git a/src/Fixer/Alias/EregToPregFixer.php b/src/Fixer/Alias/EregToPregFixer.php index 80151cf7a31..8fc64c5f11f 100644 --- a/src/Fixer/Alias/EregToPregFixer.php +++ b/src/Fixer/Alias/EregToPregFixer.php @@ -161,7 +161,7 @@ private function checkPreg(string $pattern): bool */ private function getBestDelimiter(string $pattern): string { - // try do find something that's not used + // try to find something that's not used $delimiters = []; foreach (self::$delimiters as $k => $d) { if (!str_contains($pattern, $d)) { diff --git a/src/Fixer/Basic/PsrAutoloadingFixer.php b/src/Fixer/Basic/PsrAutoloadingFixer.php index 71dbe216a00..0b3ebeb3af1 100644 --- a/src/Fixer/Basic/PsrAutoloadingFixer.php +++ b/src/Fixer/Basic/PsrAutoloadingFixer.php @@ -26,6 +26,7 @@ use PhpCsFixer\StdinFileInfo; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; +use PhpCsFixer\Tokenizer\TokensAnalyzer; /** * @author Jordi Boggiano @@ -153,6 +154,8 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { + $tokenAnalyzer = new TokensAnalyzer($tokens); + if (null !== $this->configuration['dir'] && !str_starts_with($file->getRealPath(), $this->configuration['dir'])) { return; } @@ -172,10 +175,9 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $namespaceStartIndex = $tokens->getNextMeaningfulToken($index); $namespaceEndIndex = $tokens->getNextTokenOfKind($namespaceStartIndex, [';']); - $namespace = trim($tokens->generatePartialCode($namespaceStartIndex, $namespaceEndIndex - 1)); } elseif ($token->isClassy()) { - if ($tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(T_NEW)) { + if ($tokenAnalyzer->isAnonymousClass($index)) { continue; } @@ -208,6 +210,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $configuredDir = realpath($this->configuration['dir']); $fileDir = \dirname($file->getRealPath()); + if (\strlen($configuredDir) >= \strlen($fileDir)) { return; } @@ -230,7 +233,6 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void private function calculateClassyName(\SplFileInfo $file, ?string $namespace, string $currentName): string { $name = $file->getBasename('.php'); - $maxNamespace = $this->calculateMaxNamespace($file, $namespace); if (null !== $this->configuration['dir']) { @@ -241,9 +243,11 @@ private function calculateClassyName(\SplFileInfo $file, ?string $namespace, str foreach ($namespaceParts as $namespacePart) { $nameCandidate = sprintf('%s_%s', $namespacePart, $name); + if (strtolower($nameCandidate) !== strtolower(substr($currentName, -\strlen($nameCandidate)))) { break; } + $name = $nameCandidate; } @@ -254,6 +258,7 @@ private function calculateMaxNamespace(\SplFileInfo $file, ?string $namespace): { if (null === $this->configuration['dir']) { $root = \dirname($file->getRealPath()); + while ($root !== \dirname($root)) { $root = \dirname($root); } @@ -274,9 +279,11 @@ private function calculateMaxNamespace(\SplFileInfo $file, ?string $namespace): if (!isset($namespaceAccordingToFileLocationPartsReversed[$key])) { break; } + if (strtolower($namespaceParte) !== strtolower($namespaceAccordingToFileLocationPartsReversed[$key])) { break; } + unset($namespaceAccordingToFileLocationPartsReversed[$key]); } diff --git a/src/Fixer/ClassNotation/FinalInternalClassFixer.php b/src/Fixer/ClassNotation/FinalInternalClassFixer.php index f49b970576c..dfe3941ae89 100644 --- a/src/Fixer/ClassNotation/FinalInternalClassFixer.php +++ b/src/Fixer/ClassNotation/FinalInternalClassFixer.php @@ -27,6 +27,7 @@ use PhpCsFixer\Preg; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; +use PhpCsFixer\Tokenizer\TokensAnalyzer; use Symfony\Component\OptionsResolver\Options; /** @@ -105,8 +106,10 @@ public function isRisky(): bool */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { + $tokensAnalyzer = new TokensAnalyzer($tokens); + for ($index = $tokens->count() - 1; 0 <= $index; --$index) { - if (!$tokens[$index]->isGivenKind(T_CLASS) || !$this->isClassCandidate($tokens, $index)) { + if (!$tokens[$index]->isGivenKind(T_CLASS) || $tokensAnalyzer->isAnonymousClass($index) || !$this->isClassCandidate($tokens, $index)) { continue; } @@ -182,7 +185,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn */ private function isClassCandidate(Tokens $tokens, int $index): bool { - if ($tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind([T_ABSTRACT, T_FINAL, T_NEW])) { + if ($tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind([T_ABSTRACT, T_FINAL])) { return false; // ignore class; it is abstract or already final } diff --git a/src/Fixer/ClassNotation/SelfStaticAccessorFixer.php b/src/Fixer/ClassNotation/SelfStaticAccessorFixer.php index 0539753bc0e..0c66ca6d6c3 100644 --- a/src/Fixer/ClassNotation/SelfStaticAccessorFixer.php +++ b/src/Fixer/ClassNotation/SelfStaticAccessorFixer.php @@ -114,14 +114,14 @@ public function getPriority(): int */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { - $this->tokensAnalyzer = $tokensAnalyzer = new TokensAnalyzer($tokens); + $this->tokensAnalyzer = new TokensAnalyzer($tokens); $classIndex = $tokens->getNextTokenOfKind(0, [[T_CLASS]]); while (null !== $classIndex) { if ( - $tokens[$tokens->getPrevMeaningfulToken($classIndex)]->isGivenKind(T_FINAL) - || $tokensAnalyzer->isAnonymousClass($classIndex) + $this->tokensAnalyzer->isAnonymousClass($classIndex) + || $tokens[$tokens->getPrevMeaningfulToken($classIndex)]->isGivenKind(T_FINAL) ) { $classIndex = $this->fixClass($tokens, $classIndex); } diff --git a/src/Fixer/ClassUsage/DateTimeImmutableFixer.php b/src/Fixer/ClassUsage/DateTimeImmutableFixer.php index fc611a09275..1d0610ea2fc 100644 --- a/src/Fixer/ClassUsage/DateTimeImmutableFixer.php +++ b/src/Fixer/ClassUsage/DateTimeImmutableFixer.php @@ -18,6 +18,7 @@ use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; +use PhpCsFixer\Tokenizer\Analyzer\FunctionsAnalyzer; use PhpCsFixer\Tokenizer\Token; use PhpCsFixer\Tokenizer\Tokens; @@ -60,6 +61,12 @@ public function isRisky(): bool */ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { + $functionsAnalyzer = new FunctionsAnalyzer(); + $functionMap = [ + 'date_create' => 'date_create_immutable', + 'date_create_from_format' => 'date_create_immutable_from_format', + ]; + $isInNamespace = false; $isImported = false; // e.g. use DateTime; @@ -72,12 +79,15 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void continue; } - if ($token->isGivenKind(T_USE) && $isInNamespace) { + if ($isInNamespace && $token->isGivenKind(T_USE)) { $nextIndex = $tokens->getNextMeaningfulToken($index); + if ('datetime' !== strtolower($tokens[$nextIndex]->getContent())) { continue; } + $nextNextIndex = $tokens->getNextMeaningfulToken($nextIndex); + if ($tokens[$nextNextIndex]->equals(';')) { $isImported = true; } @@ -92,6 +102,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } $prevIndex = $tokens->getPrevMeaningfulToken($index); + if ($tokens[$prevIndex]->isGivenKind(T_FUNCTION)) { continue; } @@ -101,10 +112,12 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ('datetime' === $lowercaseContent) { $this->fixClassUsage($tokens, $index, $isInNamespace, $isImported); $limit = $tokens->count(); // update limit, as fixing class usage may insert new token - } elseif ('date_create' === $lowercaseContent) { - $this->fixFunctionUsage($tokens, $index, 'date_create_immutable'); - } elseif ('date_create_from_format' === $lowercaseContent) { - $this->fixFunctionUsage($tokens, $index, 'date_create_immutable_from_format'); + + continue; + } + + if (isset($functionMap[$lowercaseContent]) && $functionsAnalyzer->isGlobalFunctionCall($tokens, $index)) { + $tokens[$index] = new Token([T_STRING, $functionMap[$lowercaseContent]]); } } } @@ -142,20 +155,4 @@ private function fixClassUsage(Tokens $tokens, int $index, bool $isInNamespace, } } } - - private function fixFunctionUsage(Tokens $tokens, int $index, string $replacement): void - { - $prevIndex = $tokens->getPrevMeaningfulToken($index); - if ($tokens[$prevIndex]->isGivenKind([T_DOUBLE_COLON, T_NEW]) || $tokens[$prevIndex]->isObjectOperator()) { - return; - } - if ($tokens[$prevIndex]->isGivenKind(T_NS_SEPARATOR)) { - $prevPrevIndex = $tokens->getPrevMeaningfulToken($prevIndex); - if ($tokens[$prevPrevIndex]->isGivenKind([T_NEW, T_STRING])) { - return; - } - } - - $tokens[$index] = new Token([T_STRING, $replacement]); - } } diff --git a/src/Fixer/Comment/SingleLineCommentStyleFixer.php b/src/Fixer/Comment/SingleLineCommentStyleFixer.php index 09fabc7b1c2..1991abb549f 100644 --- a/src/Fixer/Comment/SingleLineCommentStyleFixer.php +++ b/src/Fixer/Comment/SingleLineCommentStyleFixer.php @@ -135,7 +135,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if ($this->hashEnabled && '#' === $content[0]) { if (isset($content[1]) && '[' === $content[1]) { - continue; // This might be attribute on PHP8, do not change + continue; // This might be an attribute on PHP8, do not change } $tokens[$index] = new Token([$token->getId(), '//'.substr($content, 1)]); diff --git a/src/Fixer/Import/SingleImportPerStatementFixer.php b/src/Fixer/Import/SingleImportPerStatementFixer.php index 0c36a402fff..0a48baacad6 100644 --- a/src/Fixer/Import/SingleImportPerStatementFixer.php +++ b/src/Fixer/Import/SingleImportPerStatementFixer.php @@ -155,7 +155,7 @@ private function getGroupStatements(Tokens $tokens, string $groupPrefix, int $gr $i += 2; } - if ($token->isWhitespace(" \t") || '//' !== substr($tokens[$i - 1]->getContent(), 0, 2)) { + if ($token->isWhitespace(" \t") || !str_starts_with($tokens[$i - 1]->getContent(), '//')) { continue; } } diff --git a/src/Fixer/Operator/ConcatSpaceFixer.php b/src/Fixer/Operator/ConcatSpaceFixer.php index 91ecc8b4140..c0b87eb4366 100644 --- a/src/Fixer/Operator/ConcatSpaceFixer.php +++ b/src/Fixer/Operator/ConcatSpaceFixer.php @@ -122,7 +122,8 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn private function fixConcatenationToNoSpace(Tokens $tokens, int $index): void { $prevNonWhitespaceToken = $tokens[$tokens->getPrevNonWhitespace($index)]; - if (!$prevNonWhitespaceToken->isGivenKind([T_LNUMBER, T_COMMENT, T_DOC_COMMENT]) || '/*' === substr($prevNonWhitespaceToken->getContent(), 0, 2)) { + + if (!$prevNonWhitespaceToken->isGivenKind([T_LNUMBER, T_COMMENT, T_DOC_COMMENT]) || str_starts_with($prevNonWhitespaceToken->getContent(), '/*')) { $tokens->removeLeadingWhitespace($index, " \t"); } diff --git a/src/Fixer/Operator/NewWithBracesFixer.php b/src/Fixer/Operator/NewWithBracesFixer.php index c361c2c134e..7b31a752f8f 100644 --- a/src/Fixer/Operator/NewWithBracesFixer.php +++ b/src/Fixer/Operator/NewWithBracesFixer.php @@ -101,9 +101,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void } for ($index = $tokens->count() - 3; $index > 0; --$index) { - $token = $tokens[$index]; - - if (!$token->isGivenKind(T_NEW)) { + if (!$tokens[$index]->isGivenKind(T_NEW)) { continue; } diff --git a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php index 738c0e6d2ec..5c4656f3710 100644 --- a/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php @@ -355,18 +355,21 @@ private function getPreviousAssertCall(Tokens $tokens, int $startIndex, int $end for ($index = $endIndex; $index > $startIndex; --$index) { $index = $tokens->getPrevTokenOfKind($index, [[T_STRING]]); + if (null === $index) { return; } // test if "assert" something call $loweredContent = strtolower($tokens[$index]->getContent()); - if ('assert' !== substr($loweredContent, 0, 6)) { + + if (!str_starts_with($loweredContent, 'assert')) { continue; } // test candidate for simple calls like: ([\]+'some fixable call'(...)) $openBraceIndex = $tokens->getNextMeaningfulToken($index); + if (!$tokens[$openBraceIndex]->equals('(')) { continue; } diff --git a/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php b/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php index 0cae5b03bb8..4e059d0fc0d 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php @@ -172,7 +172,7 @@ private function isTestMethod(Tokens $tokens, int $index): bool return false; } - // if the function name starts with test its a test + // if the function name starts with test it is a test $functionNameIndex = $tokens->getNextMeaningfulToken($index); $functionName = $tokens[$functionNameIndex]->getContent(); @@ -182,7 +182,7 @@ private function isTestMethod(Tokens $tokens, int $index): bool $docBlockIndex = $this->getDocBlockIndex($tokens, $index); - // If the function doesn't have test in its name, and no doc block, its not a test + // If the function doesn't have test in its name, and no doc block, it is not a test return $this->isPHPDoc($tokens, $docBlockIndex) && str_contains($tokens[$docBlockIndex]->getContent(), '@test') diff --git a/src/Fixer/Strict/DeclareStrictTypesFixer.php b/src/Fixer/Strict/DeclareStrictTypesFixer.php index cbb7388a162..76e26b47387 100644 --- a/src/Fixer/Strict/DeclareStrictTypesFixer.php +++ b/src/Fixer/Strict/DeclareStrictTypesFixer.php @@ -136,7 +136,7 @@ private function insertSequence(Tokens $tokens): void } if ($endIndex === \count($tokens) - 1) { - return; // no more tokens afters sequence, single_blank_line_at_eof might add a line + return; // no more tokens after sequence, single_blank_line_at_eof might add a line } $lineEnding = $this->whitespacesConfig->getLineEnding(); diff --git a/src/FixerConfiguration/FixerConfigurationResolver.php b/src/FixerConfiguration/FixerConfigurationResolver.php index ca862772ae1..6c79e4495dc 100644 --- a/src/FixerConfiguration/FixerConfigurationResolver.php +++ b/src/FixerConfiguration/FixerConfigurationResolver.php @@ -116,10 +116,8 @@ public function resolve(array $options): array /** * @throws \LogicException when the option is already defined - * - * @return $this */ - private function addOption(FixerOptionInterface $option): self + private function addOption(FixerOptionInterface $option): void { $name = $option->getName(); @@ -129,7 +127,5 @@ private function addOption(FixerOptionInterface $option): self $this->options[] = $option; $this->registeredNames[] = $name; - - return $this; } } diff --git a/tests/Fixer/Basic/PsrAutoloadingFixerTest.php b/tests/Fixer/Basic/PsrAutoloadingFixerTest.php index ad531cf85a1..d7586320e05 100644 --- a/tests/Fixer/Basic/PsrAutoloadingFixerTest.php +++ b/tests/Fixer/Basic/PsrAutoloadingFixerTest.php @@ -441,6 +441,27 @@ public function foo() { class ClassOne {}; new class extends stdClass {}; class ClassTwo {}; +', + ]; + } + + /** + * @requires PHP 8.0 + * @dataProvider providePhp80Cases + */ + public function testFix80(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function providePhp80Cases(): \Generator + { + yield 'anonymous + annotation' => [ + 'doTest($expected, $input); } - public function provideAnonymousClassesCases(): array + public function provideAnonymousClassesCases(): \Generator { - return [ - [ - ' ['@internal123', 'b'], ]); } + + /** + * @dataProvider provideFix80Cases + * @requires PHP 8.0 + */ + public function testFix80(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix80Cases(): \Generator + { + yield [ + ' [ + 'bar(); ', ]; + + yield [ + 'doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield [ + '', +[Foo::class, \'method\'](...); +$c = new class{}; +$b = new class(){}; +$a = new #[foo] +class(){}; +', ]; } diff --git a/tests/Tokenizer/TokensAnalyzerTest.php b/tests/Tokenizer/TokensAnalyzerTest.php index 27db1fd41e6..6fbf283da00 100644 --- a/tests/Tokenizer/TokensAnalyzerTest.php +++ b/tests/Tokenizer/TokensAnalyzerTest.php @@ -1117,6 +1117,18 @@ abstract class Baz { final public const Y = "i"; } +', + ]; + + yield [ + [4 => false, 12 => false, 23 => false], + 'doTest( $source, @@ -401,26 +399,91 @@ public function testProcessPhp80(string $source, array $expectedTokens, array $o ); } - public function provideProcessPhp80Cases(): array + public function provideProcessPhp80Cases(): \Generator { - return [ + yield [ [ - ' CT::T_BRACE_CLASS_INSTANTIATION_OPEN, - 8 => '(', - 10 => '(', - 11 => ')', - 12 => ')', - 13 => CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, - ], - [ - '(', - ')', - CT::T_BRACE_CLASS_INSTANTIATION_OPEN, - CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, - ], + 5 => CT::T_BRACE_CLASS_INSTANTIATION_OPEN, + 8 => '(', + 10 => '(', + 11 => ')', + 12 => ')', + 13 => CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, + ], + [ + '(', + ')', + CT::T_BRACE_CLASS_INSTANTIATION_OPEN, + CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, + ], + ' CT::T_BRACE_CLASS_INSTANTIATION_OPEN, + 15 => CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, + ], + [ + CT::T_BRACE_CLASS_INSTANTIATION_OPEN, + CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, + ], + '', + ]; + } + + /** + * @param array $expectedTokens + * + * @dataProvider provideProcessPhp81Cases + * @requires PHP 8.1 + */ + public function testProcessPhp81(array $expectedTokens, array $observedKinds, string $source): void + { + $this->doTest( + $source, + $expectedTokens, + $observedKinds + ); + } + + public function provideProcessPhp81Cases(): \Generator + { + yield [ + [ + 20 => CT::T_BRACE_CLASS_INSTANTIATION_OPEN, + 24 => CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, + 43 => CT::T_BRACE_CLASS_INSTANTIATION_OPEN, + 47 => CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, + 54 => CT::T_BRACE_CLASS_INSTANTIATION_OPEN, + 64 => CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, + 107 => CT::T_BRACE_CLASS_INSTANTIATION_OPEN, + 111 => CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, + ], + [ + CT::T_BRACE_CLASS_INSTANTIATION_OPEN, + CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, ], + ' Date: Wed, 8 Sep 2021 21:57:12 +0200 Subject: [PATCH 78/80] PHP8.1 - Enum (start) --- .../no_unneeded_control_parentheses.rst | 2 +- .../ControlStructure/NoBreakCommentFixer.php | 14 ++++----- .../NoUnneededControlParenthesesFixer.php | 13 +++----- .../NoBreakCommentFixerTest.php | 30 ++++++++++++++++++ .../NoUnneededControlParenthesesFixerTest.php | 31 +++++++++++++++++++ .../SingleSpaceAfterConstructFixerTest.php | 2 +- 6 files changed, 74 insertions(+), 18 deletions(-) diff --git a/doc/rules/control_structure/no_unneeded_control_parentheses.rst b/doc/rules/control_structure/no_unneeded_control_parentheses.rst index e7c9a7e4117..e8cb6e32849 100644 --- a/doc/rules/control_structure/no_unneeded_control_parentheses.rst +++ b/doc/rules/control_structure/no_unneeded_control_parentheses.rst @@ -12,7 +12,7 @@ Configuration List of control statements to fix. -Allowed types: ``array`` +Allowed values: a subset of ``['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield', 'yield_from']`` Default value: ``['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield']`` diff --git a/src/Fixer/ControlStructure/NoBreakCommentFixer.php b/src/Fixer/ControlStructure/NoBreakCommentFixer.php index f89c1abbe12..55336176605 100644 --- a/src/Fixer/ControlStructure/NoBreakCommentFixer.php +++ b/src/Fixer/ControlStructure/NoBreakCommentFixer.php @@ -122,17 +122,15 @@ static function (string $value): bool { protected function applyFix(\SplFileInfo $file, Tokens $tokens): void { for ($index = \count($tokens) - 1; $index >= 0; --$index) { - if (!$tokens[$index]->isGivenKind([T_CASE, T_DEFAULT])) { + if ($tokens[$index]->isGivenKind(T_DEFAULT)) { + if ($tokens[$tokens->getNextMeaningfulToken($index)]->isGivenKind(T_DOUBLE_ARROW)) { + continue; // this is "default" from "match" + } + } elseif (!$tokens[$index]->isGivenKind(T_CASE)) { continue; } - $caseColonIndex = $tokens->getNextTokenOfKind($index, [':', ';', [T_DOUBLE_ARROW]]); - - if ($tokens[$caseColonIndex]->isGivenKind(T_DOUBLE_ARROW)) { - continue; // this is "default" from "match" - } - - $this->fixCase($tokens, $caseColonIndex); + $this->fixCase($tokens, $tokens->getNextTokenOfKind($index, [':', ';'])); } } diff --git a/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php b/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php index 69085b9fb83..d6226da70a7 100644 --- a/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php +++ b/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php @@ -16,6 +16,7 @@ use PhpCsFixer\AbstractFixer; use PhpCsFixer\Fixer\ConfigurableFixerInterface; +use PhpCsFixer\FixerConfiguration\AllowedValueSubset; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; @@ -44,14 +45,6 @@ final class NoUnneededControlParenthesesFixer extends AbstractFixer implements C 'yield_from' => ['lookupTokens' => T_YIELD_FROM, 'neededSuccessors' => [';', ')']], ]; - /** - * Dynamic option set on constructor. - */ - public function __construct() - { - parent::__construct(); - } - /** * {@inheritdoc} */ @@ -62,6 +55,7 @@ public function isCandidate(Tokens $tokens): bool foreach (self::$loops as $loop) { $types[] = (array) $loop['lookupTokens']; } + $types = array_merge(...$types); return $tokens->isAnyTokenKindsFound($types); @@ -140,6 +134,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void $token->equals('(') ? Tokens::BLOCK_TYPE_PARENTHESIS_BRACE : Tokens::BLOCK_TYPE_BRACE_CLASS_INSTANTIATION, $blockStartIndex ); + $blockEndNextIndex = $tokens->getNextMeaningfulToken($blockEndIndex); if (!$tokens[$blockEndNextIndex]->equalsAny($loop['neededSuccessors'])) { @@ -148,6 +143,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void if (\array_key_exists('forbiddenContents', $loop)) { $forbiddenTokenIndex = $tokens->getNextTokenOfKind($blockStartIndex, $loop['forbiddenContents']); + // A forbidden token is found and is inside the parenthesis. if (null !== $forbiddenTokenIndex && $forbiddenTokenIndex < $blockEndIndex) { continue; @@ -174,6 +170,7 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn return new FixerConfigurationResolver([ (new FixerOptionBuilder('statements', 'List of control statements to fix.')) ->setAllowedTypes(['array']) + ->setAllowedValues([new AllowedValueSubset(array_keys(self::$loops))]) ->setDefault([ 'break', 'clone', diff --git a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php index e7cd8e1de77..0c5d1337f5f 100644 --- a/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php +++ b/tests/Fixer/ControlStructure/NoBreakCommentFixerTest.php @@ -1215,4 +1215,34 @@ public function provideFix80Cases(): \Generator ', ]; } + + /** + * @dataProvider provideFix81Cases + * @requires PHP 8.1 + */ + public function testFix81(string $expected, ?string $input = null): void + { + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'enums' => [ + 'fixer->configure(['statements' => ['switch_case']]); + $this->doTest($expected, $input); + } + + public function provideFix81Cases(): \Generator + { + yield 'enums' => [ + ' Date: Wed, 8 Sep 2021 22:32:22 +0200 Subject: [PATCH 79/80] CurlyBraceTransformer - count T_CURLY_OPEN itself as level as well --- .../Transformer/CurlyBraceTransformer.php | 19 ++++++------------- .../Transformer/CurlyBraceTransformerTest.php | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Tokenizer/Transformer/CurlyBraceTransformer.php b/src/Tokenizer/Transformer/CurlyBraceTransformer.php index 1d53a533e24..14333dc0af0 100644 --- a/src/Tokenizer/Transformer/CurlyBraceTransformer.php +++ b/src/Tokenizer/Transformer/CurlyBraceTransformer.php @@ -88,25 +88,18 @@ private function transformIntoCurlyCloseBrace(Tokens $tokens, Token $token, int } $level = 1; - $nestIndex = $index; - while (0 < $level) { - ++$nestIndex; + do { + ++$index; - // we count all kind of { - if ($tokens[$nestIndex]->equals('{')) { + if ($tokens[$index]->equals('{') || $tokens[$index]->isGivenKind(T_CURLY_OPEN)) { // we count all kind of { ++$level; - - continue; - } - - // we count all kind of } - if ($tokens[$nestIndex]->equals('}')) { + } elseif ($tokens[$index]->equals('}')) { // we count all kind of } --$level; } - } + } while (0 < $level); - $tokens[$nestIndex] = new Token([CT::T_CURLY_CLOSE, '}']); + $tokens[$index] = new Token([CT::T_CURLY_CLOSE, '}']); } private function transformIntoDollarCloseBrace(Tokens $tokens, Token $token, int $index): void diff --git a/tests/Tokenizer/Transformer/CurlyBraceTransformerTest.php b/tests/Tokenizer/Transformer/CurlyBraceTransformerTest.php index b223f3ab775..69717cc6ab6 100644 --- a/tests/Tokenizer/Transformer/CurlyBraceTransformerTest.php +++ b/tests/Tokenizer/Transformer/CurlyBraceTransformerTest.php @@ -170,7 +170,9 @@ public function provideProcessCases(): array 39 => CT::T_CURLY_CLOSE, ], ], - 'do not touch' => [' [ + ' [ '{"set_{$name}"}(42);', [ @@ -180,13 +182,24 @@ public function provideProcessCases(): array 10 => CT::T_DYNAMIC_PROP_BRACE_CLOSE, ], ], - [ + 'group import' => [ ' CT::T_GROUP_IMPORT_BRACE_OPEN, 19 => CT::T_GROUP_IMPORT_BRACE_CLOSE, ], ], + 'nested curly open + close' => [ + '{"{$bar}"}}";', + [ + 4 => T_CURLY_OPEN, + 7 => CT::T_DYNAMIC_PROP_BRACE_OPEN, + 9 => T_CURLY_OPEN, + 11 => CT::T_CURLY_CLOSE, + 13 => CT::T_DYNAMIC_PROP_BRACE_CLOSE, + 14 => CT::T_CURLY_CLOSE, + ], + ], ]; } From 0e9d477af64dbdb7362e4cdb765f7c48300be936 Mon Sep 17 00:00:00 2001 From: Wes Hooper Date: Thu, 9 Sep 2021 09:03:08 +0200 Subject: [PATCH 80/80] Correct mapping in NoAliasFunctionsFixer These were added recently, but are incorrectly mapping the function to the alias. --- src/Fixer/Alias/NoAliasFunctionsFixer.php | 18 +- .../Fixer/Alias/NoAliasFunctionsFixerTest.php | 263 +++++++++--------- 2 files changed, 145 insertions(+), 136 deletions(-) diff --git a/src/Fixer/Alias/NoAliasFunctionsFixer.php b/src/Fixer/Alias/NoAliasFunctionsFixer.php index 3a18ee63962..d67e7786725 100644 --- a/src/Fixer/Alias/NoAliasFunctionsFixer.php +++ b/src/Fixer/Alias/NoAliasFunctionsFixer.php @@ -38,8 +38,8 @@ final class NoAliasFunctionsFixer extends AbstractFixer implements ConfigurableF '@internal' => [ 'diskfreespace' => 'disk_free_space', - 'checkdnsrr' => 'dns_check_record', - 'getmxrr' => 'dns_get_mx', + 'dns_check_record' => 'checkdnsrr', + 'dns_get_mx' => 'getmxrr', 'session_commit' => 'session_write_close', @@ -83,14 +83,8 @@ final class NoAliasFunctionsFixer extends AbstractFixer implements ConfigurableF 'imap_scanmailbox' => 'imap_listscan', ], - '@snmp' => [ - 'snmpwalkoid' => 'snmprealwalk', - 'snmp_set_oid_numeric_print' => 'snmp_set_oid_output_format', - ], - '@ldap' => [ 'ldap_close' => 'ldap_unbind', - 'ldap_get_values' => 'ldap_get_values_len', 'ldap_modify' => 'ldap_mod_replace', ], @@ -169,6 +163,7 @@ public function configure(array $configuration): void parent::configure($configuration); $this->aliases = []; + foreach ($this->configuration['sets'] as $set) { if ('@all' === $set) { $this->aliases = array_merge(...array_values(self::SETS)); @@ -264,6 +259,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void foreach ($tokens->findGivenKind(T_STRING) as $index => $token) { // check mapping hit $tokenContent = strtolower($token->getContent()); + if (!isset($this->aliases[$tokenContent])) { continue; } @@ -315,16 +311,16 @@ protected function createConfigurationDefinition(): FixerConfigurationResolverIn '@pcntl' => 'PCNTL functions', '@pg' => 'pg functions', '@posix' => 'POSIX functions', - '@snmp' => 'SNMP functions', + '@snmp' => 'SNMP functions', // @TODO Remove on next major 4.0 as this set is now empty '@sodium' => 'libsodium functions', '@time' => 'time functions', ]; - $list = ''; + $list = "List of sets to fix. Defined sets are:\n\n"; + foreach ($sets as $set => $description) { $list .= sprintf("* `%s` (%s)\n", $set, $description); } - $list = sprintf("List of sets to fix. Defined sets are:\n\n%s", $list); return new FixerConfigurationResolver([ (new FixerOptionBuilder('sets', $list)) diff --git a/tests/Fixer/Alias/NoAliasFunctionsFixerTest.php b/tests/Fixer/Alias/NoAliasFunctionsFixerTest.php index f7e1ee56b28..a22023da46a 100644 --- a/tests/Fixer/Alias/NoAliasFunctionsFixerTest.php +++ b/tests/Fixer/Alias/NoAliasFunctionsFixerTest.php @@ -34,36 +34,46 @@ public function testFix(string $expected, ?string $input = null): void $this->doTest($expected, $input); } - public function provideFixCases(): array + public function provideFixCases(): \Generator { - $finalCases = []; $defaultSets = [ '@internal', '@IMAP', '@pg', ]; + foreach ($this->provideAllCases() as $set => $cases) { if (\in_array($set, $defaultSets, true)) { - $finalCases = array_merge($finalCases, $cases); + yield from $cases; } else { foreach ($cases as $case) { - $finalCases[] = [$case[0]]; + yield [$case[0]]; } } } // static case to fix - in case previous generation is broken - $finalCases[] = [ + yield [ ' mxrr' => [ + 'doTest($expected, $input); } - public function provideFixWithConfigurationCases(): array + public function provideFixWithConfigurationCases(): \Generator { - $finalCases = [ - '@internal' => [ - ' ['@internal']], - ], - '@IMAP' => [ - ' ['@IMAP']], - ], - '@mbreg' => [ - ' ['@mbreg']], - ], - '@all' => [ - ' ['@all']], - ], - '@IMAP, @mbreg' => [ - ' ['@IMAP', '@mbreg']], - ], - '@time' => [ - ' ['@time']], - ], - '@exif' => [ - ' ['@exif']], - ], + yield '@internal' => [ + ' ['@internal']], + ]; + + yield '@IMAP' => [ + ' ['@IMAP']], + ]; + + yield '@mbreg' => [ + ' ['@mbreg']], + ]; + + yield '@all' => [ + ' ['@all']], + ]; + + yield '@IMAP, @mbreg' => [ + ' ['@IMAP', '@mbreg']], + ]; + + yield '@time' => [ + ' ['@time']], + ]; + + yield '@exif' => [ + ' ['@exif']], ]; foreach ($this->provideAllCases() as $set => $cases) { foreach ($cases as $case) { - $finalCases[] = [ + yield [ $case[0], $case[1] ?? null, ['sets' => [$set]], ]; } } - - return $finalCases; } /** @@ -242,20 +252,20 @@ public function provideFix81Cases(): \Generator ]; } - private function provideAllCases(): array + private function provideAllCases(): \Generator { $reflectionConstant = new \ReflectionClassConstant(\PhpCsFixer\Fixer\Alias\NoAliasFunctionsFixer::class, 'SETS'); /** @var array $allAliases */ $allAliases = $reflectionConstant->getValue(); - $finalCases = []; $sets = $allAliases; unset($sets['@time']); // Tested manually $sets = array_keys($sets); + foreach ($sets as $set) { $aliases = $allAliases[$set]; - $cases = []; + foreach ($aliases as $alias => $master) { // valid cases $cases[] = ["{$alias}(\$a);"]; @@ -298,33 +308,36 @@ class '.$alias.' extends '.ucfirst($alias).'ing{ " $cases; } - - return $finalCases; } }