diff --git a/.github/workflows/build_php71.yaml b/.github/workflows/build_php71.yaml index 25bcb282be3..5c5c552d7e3 100644 --- a/.github/workflows/build_php71.yaml +++ b/.github/workflows/build_php71.yaml @@ -22,7 +22,7 @@ jobs: - run: composer require symfony/polyfill-php72 symfony/polyfill-php73 symfony/polyfill-php74 symfony/polyfill-php80 --no-install --no-update # Execute the downgrade script - - run: ./.github/workflows/scripts/downgrade_packages.sh 7.1 + - run: ./build/downgrade/downgrade_packages.sh 7.1 # Upload the artifact so we can download and review the downgraded code - run: mkdir build diff --git a/.github/workflows/scripts/downgrade_packages.sh b/build/downgrade/downgrade_packages.sh similarity index 98% rename from .github/workflows/scripts/downgrade_packages.sh rename to build/downgrade/downgrade_packages.sh index 008877585bd..c48061c1e4f 100755 --- a/.github/workflows/scripts/downgrade_packages.sh +++ b/build/downgrade/downgrade_packages.sh @@ -3,7 +3,7 @@ # This bash script downgrades the code to the selected PHP version # # Usage from within a GitHub workflow: -# .github/workflows/scripts/downgrade_packages.sh $target_php_version +# build/downgrade/downgrade_packages.sh $target_php_version # where $target_php_version is one of the following values: # - 7.0 # - 7.1 @@ -15,7 +15,7 @@ # - 8.0 # # Eg: To downgrade to PHP 7.1, execute: -# .github/workflows/scripts/downgrade_packages.sh 7.1 +# build/downgrade/downgrade_packages.sh 7.1 ######################################################################## # show errors @@ -204,7 +204,7 @@ then config=ci/downgrade/rector-downgrade-rector config="${config}-${rector_config}.php" note "Running rector_config ${rector_config} for main package ${rootPackage} on path(s) ${path_to_downgrade}" - bin/rector process $path_to_downgrade --config=$config --ansi --no-diffs + bin/rector process $path_to_downgrade --config=$config --ansi --no-diffs --debug #Downgrade all the dependencies then packages_to_downgrade=$(join_by " " ${dependency_packages[@]}) @@ -212,7 +212,7 @@ then config=ci/downgrade/rector-downgrade-dependency config="${config}-${rector_config}.php" note "Running rector_config ${rector_config} for dependency packages ${packages_to_downgrade} on paths ${paths_to_downgrade}" - bin/rector process $paths_to_downgrade --config=$config --ansi --no-diffs + bin/rector process $paths_to_downgrade --config=$config --ansi --no-diffs --debug # Success exit 0 @@ -316,7 +316,7 @@ do note "Running rector_config ${rector_config} for package ${package_to_downgrade} on path(s) ${path_to_downgrade}" # Execute the downgrade - bin/rector process $path_to_downgrade --config=$config --ansi + bin/rector process $path_to_downgrade --config=$config --ansi --debug # If Rector fails, already exit if [ "$?" -gt 0 ]; then @@ -355,7 +355,7 @@ do paths_to_downgrade=$(join_by " " ${circular_paths_to_downgrade_for_rectorconfig[@]}) note "Running rector_config ${rector_config} for packages ${circular_packages_to_downgrade_for_rectorconfig[@]}" config="ci/downgrade/rector-downgrade-dependency-${rector_config}.php" - bin/rector process $paths_to_downgrade --config=$config --ansi + bin/rector process $paths_to_downgrade --config=$config --ansi --debug # If Rector fails, already exit if [ "$?" -gt 0 ]; then diff --git a/rules/carbon/src/Rector/MethodCall/ChangeCarbonSingularMethodCallToPluralRector.php b/rules/carbon/src/Rector/MethodCall/ChangeCarbonSingularMethodCallToPluralRector.php index 336d92a1f02..4477495a29e 100644 --- a/rules/carbon/src/Rector/MethodCall/ChangeCarbonSingularMethodCallToPluralRector.php +++ b/rules/carbon/src/Rector/MethodCall/ChangeCarbonSingularMethodCallToPluralRector.php @@ -69,8 +69,7 @@ final class SomeClass } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/carbon/src/Rector/MethodCall/ChangeDiffForHumansArgsRector.php b/rules/carbon/src/Rector/MethodCall/ChangeDiffForHumansArgsRector.php index a5ab720c177..55b1370e198 100644 --- a/rules/carbon/src/Rector/MethodCall/ChangeDiffForHumansArgsRector.php +++ b/rules/carbon/src/Rector/MethodCall/ChangeDiffForHumansArgsRector.php @@ -53,8 +53,7 @@ final class SomeClass } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality-strict/src/Rector/Stmt/VarInlineAnnotationToAssertRector.php b/rules/code-quality-strict/src/Rector/Stmt/VarInlineAnnotationToAssertRector.php index 64c1f884734..e96aed00a4a 100644 --- a/rules/code-quality-strict/src/Rector/Stmt/VarInlineAnnotationToAssertRector.php +++ b/rules/code-quality-strict/src/Rector/Stmt/VarInlineAnnotationToAssertRector.php @@ -65,8 +65,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality-strict/src/Rector/Variable/MoveVariableDeclarationNearReferenceRector.php b/rules/code-quality-strict/src/Rector/Variable/MoveVariableDeclarationNearReferenceRector.php index 6d548826b34..78a43dd83b6 100644 --- a/rules/code-quality-strict/src/Rector/Variable/MoveVariableDeclarationNearReferenceRector.php +++ b/rules/code-quality-strict/src/Rector/Variable/MoveVariableDeclarationNearReferenceRector.php @@ -65,8 +65,7 @@ if ($condition === null) { return $var; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Array_/ArrayThisCallToThisMethodCallRector.php b/rules/code-quality/src/Rector/Array_/ArrayThisCallToThisMethodCallRector.php index c50ad4bb671..c30c5d695b9 100644 --- a/rules/code-quality/src/Rector/Array_/ArrayThisCallToThisMethodCallRector.php +++ b/rules/code-quality/src/Rector/Array_/ArrayThisCallToThisMethodCallRector.php @@ -81,8 +81,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php b/rules/code-quality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php index 525ac7bd52e..f60a50f87fd 100644 --- a/rules/code-quality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php +++ b/rules/code-quality/src/Rector/Array_/CallableThisArrayToAnonymousFunctionRector.php @@ -90,8 +90,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Assign/SplitListAssignToSeparateLineRector.php b/rules/code-quality/src/Rector/Assign/SplitListAssignToSeparateLineRector.php index 6130dcb5fb8..fcdc37a610f 100644 --- a/rules/code-quality/src/Rector/Assign/SplitListAssignToSeparateLineRector.php +++ b/rules/code-quality/src/Rector/Assign/SplitListAssignToSeparateLineRector.php @@ -47,8 +47,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/BooleanNot/SimplifyDeMorganBinaryRector.php b/rules/code-quality/src/Rector/BooleanNot/SimplifyDeMorganBinaryRector.php index 5d990a460cb..934b5d3a6df 100644 --- a/rules/code-quality/src/Rector/BooleanNot/SimplifyDeMorganBinaryRector.php +++ b/rules/code-quality/src/Rector/BooleanNot/SimplifyDeMorganBinaryRector.php @@ -46,8 +46,7 @@ $a = 5; $b = 10; $result = $a <= 20 && $b > 50; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Concat/JoinStringConcatRector.php b/rules/code-quality/src/Rector/Concat/JoinStringConcatRector.php index 270f11308f8..af581471ae8 100644 --- a/rules/code-quality/src/Rector/Concat/JoinStringConcatRector.php +++ b/rules/code-quality/src/Rector/Concat/JoinStringConcatRector.php @@ -53,8 +53,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php b/rules/code-quality/src/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php index e84f833a780..2eace054888 100644 --- a/rules/code-quality/src/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php +++ b/rules/code-quality/src/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php @@ -47,8 +47,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/For_/ForRepeatedCountToOwnVariableRector.php b/rules/code-quality/src/Rector/For_/ForRepeatedCountToOwnVariableRector.php index 6a9eb6e0f91..05130142990 100644 --- a/rules/code-quality/src/Rector/For_/ForRepeatedCountToOwnVariableRector.php +++ b/rules/code-quality/src/Rector/For_/ForRepeatedCountToOwnVariableRector.php @@ -60,8 +60,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php b/rules/code-quality/src/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php index a45eab3c1b4..161f5771751 100644 --- a/rules/code-quality/src/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php +++ b/rules/code-quality/src/Rector/Foreach_/ForeachItemsAssignToEmptyArrayToAssignRector.php @@ -67,8 +67,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Foreach_/SimplifyForeachToArrayFilterRector.php b/rules/code-quality/src/Rector/Foreach_/SimplifyForeachToArrayFilterRector.php index 6c0d3381d3a..00a479ad382 100644 --- a/rules/code-quality/src/Rector/Foreach_/SimplifyForeachToArrayFilterRector.php +++ b/rules/code-quality/src/Rector/Foreach_/SimplifyForeachToArrayFilterRector.php @@ -43,8 +43,7 @@ CODE_SAMPLE $possibleDirectories = []; $directories = array_filter($possibleDirectories, 'file_exists'); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Foreach_/SimplifyForeachToCoalescingRector.php b/rules/code-quality/src/Rector/Foreach_/SimplifyForeachToCoalescingRector.php index 4c1cae49fb5..1b87426411e 100644 --- a/rules/code-quality/src/Rector/Foreach_/SimplifyForeachToCoalescingRector.php +++ b/rules/code-quality/src/Rector/Foreach_/SimplifyForeachToCoalescingRector.php @@ -62,8 +62,7 @@ CODE_SAMPLE <<<'CODE_SAMPLE' return $this->oldToNewFunctions[$currentFunction] ?? null; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Foreach_/UnusedForeachValueToArrayKeysRector.php b/rules/code-quality/src/Rector/Foreach_/UnusedForeachValueToArrayKeysRector.php index 2b68541f993..82a3864cec2 100644 --- a/rules/code-quality/src/Rector/Foreach_/UnusedForeachValueToArrayKeysRector.php +++ b/rules/code-quality/src/Rector/Foreach_/UnusedForeachValueToArrayKeysRector.php @@ -50,8 +50,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php b/rules/code-quality/src/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php index b11395e2aca..85c38c38f29 100644 --- a/rules/code-quality/src/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php +++ b/rules/code-quality/src/Rector/FuncCall/ArrayKeysAndInArrayToArrayKeyExistsRector.php @@ -44,8 +44,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/FuncCall/ArrayMergeOfNonArraysToSimpleArrayRector.php b/rules/code-quality/src/Rector/FuncCall/ArrayMergeOfNonArraysToSimpleArrayRector.php index e961d3720b2..3508a557e78 100644 --- a/rules/code-quality/src/Rector/FuncCall/ArrayMergeOfNonArraysToSimpleArrayRector.php +++ b/rules/code-quality/src/Rector/FuncCall/ArrayMergeOfNonArraysToSimpleArrayRector.php @@ -52,8 +52,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/FuncCall/ChangeArrayPushToArrayAssignRector.php b/rules/code-quality/src/Rector/FuncCall/ChangeArrayPushToArrayAssignRector.php index 6624d552058..c55fd1d6b13 100644 --- a/rules/code-quality/src/Rector/FuncCall/ChangeArrayPushToArrayAssignRector.php +++ b/rules/code-quality/src/Rector/FuncCall/ChangeArrayPushToArrayAssignRector.php @@ -48,8 +48,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/FuncCall/IntvalToTypeCastRector.php b/rules/code-quality/src/Rector/FuncCall/IntvalToTypeCastRector.php index b55dde4de81..2a05e4e347b 100644 --- a/rules/code-quality/src/Rector/FuncCall/IntvalToTypeCastRector.php +++ b/rules/code-quality/src/Rector/FuncCall/IntvalToTypeCastRector.php @@ -44,8 +44,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/FuncCall/IsAWithStringWithThirdArgumentRector.php b/rules/code-quality/src/Rector/FuncCall/IsAWithStringWithThirdArgumentRector.php index 97327adf029..de266c84921 100644 --- a/rules/code-quality/src/Rector/FuncCall/IsAWithStringWithThirdArgumentRector.php +++ b/rules/code-quality/src/Rector/FuncCall/IsAWithStringWithThirdArgumentRector.php @@ -42,8 +42,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/FuncCall/SingleInArrayToCompareRector.php b/rules/code-quality/src/Rector/FuncCall/SingleInArrayToCompareRector.php index 3261ee5d70d..7fb788ce476 100644 --- a/rules/code-quality/src/Rector/FuncCall/SingleInArrayToCompareRector.php +++ b/rules/code-quality/src/Rector/FuncCall/SingleInArrayToCompareRector.php @@ -48,8 +48,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/FunctionLike/RemoveAlwaysTrueConditionSetInConstructorRector.php b/rules/code-quality/src/Rector/FunctionLike/RemoveAlwaysTrueConditionSetInConstructorRector.php index 39bd0380b49..7cad55107ad 100644 --- a/rules/code-quality/src/Rector/FunctionLike/RemoveAlwaysTrueConditionSetInConstructorRector.php +++ b/rules/code-quality/src/Rector/FunctionLike/RemoveAlwaysTrueConditionSetInConstructorRector.php @@ -90,8 +90,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php b/rules/code-quality/src/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php index 5db7f089c4c..84c995315a7 100644 --- a/rules/code-quality/src/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php +++ b/rules/code-quality/src/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php @@ -72,8 +72,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Identical/SimplifyBoolIdenticalTrueRector.php b/rules/code-quality/src/Rector/Identical/SimplifyBoolIdenticalTrueRector.php index 4742360e9e9..5e3278339ba 100644 --- a/rules/code-quality/src/Rector/Identical/SimplifyBoolIdenticalTrueRector.php +++ b/rules/code-quality/src/Rector/Identical/SimplifyBoolIdenticalTrueRector.php @@ -46,8 +46,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Identical/StrlenZeroToIdenticalEmptyStringRector.php b/rules/code-quality/src/Rector/Identical/StrlenZeroToIdenticalEmptyStringRector.php index d60f6c05e90..52589d82c4c 100644 --- a/rules/code-quality/src/Rector/Identical/StrlenZeroToIdenticalEmptyStringRector.php +++ b/rules/code-quality/src/Rector/Identical/StrlenZeroToIdenticalEmptyStringRector.php @@ -43,8 +43,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/If_/SimplifyIfElseToTernaryRector.php b/rules/code-quality/src/Rector/If_/SimplifyIfElseToTernaryRector.php index 940603cf30b..f427577936f 100644 --- a/rules/code-quality/src/Rector/If_/SimplifyIfElseToTernaryRector.php +++ b/rules/code-quality/src/Rector/If_/SimplifyIfElseToTernaryRector.php @@ -54,8 +54,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/If_/SimplifyIfNotNullReturnRector.php b/rules/code-quality/src/Rector/If_/SimplifyIfNotNullReturnRector.php index e2a00901e37..e3dfffe2806 100644 --- a/rules/code-quality/src/Rector/If_/SimplifyIfNotNullReturnRector.php +++ b/rules/code-quality/src/Rector/If_/SimplifyIfNotNullReturnRector.php @@ -47,8 +47,7 @@ CODE_SAMPLE $newNode = 'something ; return $newNode; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/If_/SimplifyIfReturnBoolRector.php b/rules/code-quality/src/Rector/If_/SimplifyIfReturnBoolRector.php index a2773062982..a7f6bf2d00e 100644 --- a/rules/code-quality/src/Rector/If_/SimplifyIfReturnBoolRector.php +++ b/rules/code-quality/src/Rector/If_/SimplifyIfReturnBoolRector.php @@ -55,8 +55,7 @@ return false; CODE_SAMPLE , 'return strpos($docToken->getContent(), "\n") === false;' - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/LogicalAnd/LogicalToBooleanRector.php b/rules/code-quality/src/Rector/LogicalAnd/LogicalToBooleanRector.php index be897a5eada..9c85f6345a7 100644 --- a/rules/code-quality/src/Rector/LogicalAnd/LogicalToBooleanRector.php +++ b/rules/code-quality/src/Rector/LogicalAnd/LogicalToBooleanRector.php @@ -37,8 +37,7 @@ if (($f = false) || true) { return $f; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Name/FixClassCaseSensitivityNameRector.php b/rules/code-quality/src/Rector/Name/FixClassCaseSensitivityNameRector.php index ec64895a0d5..596564d9198 100644 --- a/rules/code-quality/src/Rector/Name/FixClassCaseSensitivityNameRector.php +++ b/rules/code-quality/src/Rector/Name/FixClassCaseSensitivityNameRector.php @@ -67,8 +67,7 @@ final class AnotherClass { } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/NotEqual/CommonNotEqualRector.php b/rules/code-quality/src/Rector/NotEqual/CommonNotEqualRector.php index 5f96d42c68c..202ca61cfd7 100644 --- a/rules/code-quality/src/Rector/NotEqual/CommonNotEqualRector.php +++ b/rules/code-quality/src/Rector/NotEqual/CommonNotEqualRector.php @@ -42,8 +42,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Ternary/ArrayKeyExistsTernaryThenValueToCoalescingRector.php b/rules/code-quality/src/Rector/Ternary/ArrayKeyExistsTernaryThenValueToCoalescingRector.php index 6768ed27547..5d47f85de9a 100644 --- a/rules/code-quality/src/Rector/Ternary/ArrayKeyExistsTernaryThenValueToCoalescingRector.php +++ b/rules/code-quality/src/Rector/Ternary/ArrayKeyExistsTernaryThenValueToCoalescingRector.php @@ -45,8 +45,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Ternary/SimplifyDuplicatedTernaryRector.php b/rules/code-quality/src/Rector/Ternary/SimplifyDuplicatedTernaryRector.php index bbaa045b8b7..6994054df1a 100644 --- a/rules/code-quality/src/Rector/Ternary/SimplifyDuplicatedTernaryRector.php +++ b/rules/code-quality/src/Rector/Ternary/SimplifyDuplicatedTernaryRector.php @@ -43,8 +43,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/code-quality/src/Rector/Ternary/SwitchNegatedTernaryRector.php b/rules/code-quality/src/Rector/Ternary/SwitchNegatedTernaryRector.php index b93f74361be..7c05b2411e4 100644 --- a/rules/code-quality/src/Rector/Ternary/SwitchNegatedTernaryRector.php +++ b/rules/code-quality/src/Rector/Ternary/SwitchNegatedTernaryRector.php @@ -45,8 +45,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/Assign/PHPStormVarAnnotationRector.php b/rules/coding-style/src/Rector/Assign/PHPStormVarAnnotationRector.php index c53ee113f79..e0666c73cc9 100644 --- a/rules/coding-style/src/Rector/Assign/PHPStormVarAnnotationRector.php +++ b/rules/coding-style/src/Rector/Assign/PHPStormVarAnnotationRector.php @@ -55,8 +55,7 @@ CODE_SAMPLE /** @var \Shopsys\FrameworkBundle\Model\Product\Filter\ProductFilterConfig $config */ $config = 5; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php b/rules/coding-style/src/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php index e678654db1f..457e4185011 100644 --- a/rules/coding-style/src/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php +++ b/rules/coding-style/src/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php @@ -56,8 +56,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/ClassConst/SplitGroupedConstantsAndPropertiesRector.php b/rules/coding-style/src/Rector/ClassConst/SplitGroupedConstantsAndPropertiesRector.php index e62b0357444..57e246edbf5 100644 --- a/rules/coding-style/src/Rector/ClassConst/SplitGroupedConstantsAndPropertiesRector.php +++ b/rules/coding-style/src/Rector/ClassConst/SplitGroupedConstantsAndPropertiesRector.php @@ -53,8 +53,7 @@ class SomeClass public $isIsThough; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/ClassConst/VarConstantCommentRector.php b/rules/coding-style/src/Rector/ClassConst/VarConstantCommentRector.php index c3b0d3c5308..897db0f41dd 100644 --- a/rules/coding-style/src/Rector/ClassConst/VarConstantCommentRector.php +++ b/rules/coding-style/src/Rector/ClassConst/VarConstantCommentRector.php @@ -61,8 +61,7 @@ class SomeClass const HI = 'hi'; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/ClassMethod/RemoveDoubleUnderscoreInMethodNameRector.php b/rules/coding-style/src/Rector/ClassMethod/RemoveDoubleUnderscoreInMethodNameRector.php index cf29c90a3c9..0429014a815 100644 --- a/rules/coding-style/src/Rector/ClassMethod/RemoveDoubleUnderscoreInMethodNameRector.php +++ b/rules/coding-style/src/Rector/ClassMethod/RemoveDoubleUnderscoreInMethodNameRector.php @@ -53,8 +53,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php b/rules/coding-style/src/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php index 28176f75b5b..2a793af16aa 100644 --- a/rules/coding-style/src/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php +++ b/rules/coding-style/src/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php @@ -84,8 +84,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/Encapsed/EncapsedStringsToSprintfRector.php b/rules/coding-style/src/Rector/Encapsed/EncapsedStringsToSprintfRector.php index 3b7ba1244f2..2c830debd19 100644 --- a/rules/coding-style/src/Rector/Encapsed/EncapsedStringsToSprintfRector.php +++ b/rules/coding-style/src/Rector/Encapsed/EncapsedStringsToSprintfRector.php @@ -62,8 +62,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/FuncCall/ConsistentImplodeRector.php b/rules/coding-style/src/Rector/FuncCall/ConsistentImplodeRector.php index 6dca84a72ca..5d8684f93f1 100644 --- a/rules/coding-style/src/Rector/FuncCall/ConsistentImplodeRector.php +++ b/rules/coding-style/src/Rector/FuncCall/ConsistentImplodeRector.php @@ -61,8 +61,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php b/rules/coding-style/src/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php index f948dbe907b..8893b27b212 100644 --- a/rules/coding-style/src/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php +++ b/rules/coding-style/src/Rector/FuncCall/CountArrayToEmptyArrayComparisonRector.php @@ -45,8 +45,7 @@ $array === []; $array !== []; $array === []; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/FuncCall/PreslashSimpleFunctionRector.php b/rules/coding-style/src/Rector/FuncCall/PreslashSimpleFunctionRector.php index 7fc5a940b4d..e8dba3a0001 100644 --- a/rules/coding-style/src/Rector/FuncCall/PreslashSimpleFunctionRector.php +++ b/rules/coding-style/src/Rector/FuncCall/PreslashSimpleFunctionRector.php @@ -44,8 +44,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php b/rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php index 44dd6dc8def..79c650e556c 100644 --- a/rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php +++ b/rules/coding-style/src/Rector/FuncCall/VersionCompareFuncCallToConstantRector.php @@ -80,8 +80,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/Function_/CamelCaseFunctionNamingToUnderscoreRector.php b/rules/coding-style/src/Rector/Function_/CamelCaseFunctionNamingToUnderscoreRector.php index 2bf578630e6..d38427b6a4b 100644 --- a/rules/coding-style/src/Rector/Function_/CamelCaseFunctionNamingToUnderscoreRector.php +++ b/rules/coding-style/src/Rector/Function_/CamelCaseFunctionNamingToUnderscoreRector.php @@ -41,8 +41,7 @@ function some_camel_case_function() some_camel_case_function(); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/Include_/FollowRequireByDirRector.php b/rules/coding-style/src/Rector/Include_/FollowRequireByDirRector.php index b16a5b69c86..fc759f54291 100644 --- a/rules/coding-style/src/Rector/Include_/FollowRequireByDirRector.php +++ b/rules/coding-style/src/Rector/Include_/FollowRequireByDirRector.php @@ -44,8 +44,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/Property/AddFalseDefaultToBoolPropertyRector.php b/rules/coding-style/src/Rector/Property/AddFalseDefaultToBoolPropertyRector.php index b800f3b5fa9..58796de9d4e 100644 --- a/rules/coding-style/src/Rector/Property/AddFalseDefaultToBoolPropertyRector.php +++ b/rules/coding-style/src/Rector/Property/AddFalseDefaultToBoolPropertyRector.php @@ -41,8 +41,7 @@ class SomeClass private $isDisabled = false; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/String_/SplitStringClassConstantToClassConstFetchRector.php b/rules/coding-style/src/Rector/String_/SplitStringClassConstantToClassConstFetchRector.php index 1d418f6093b..7d74782e55a 100644 --- a/rules/coding-style/src/Rector/String_/SplitStringClassConstantToClassConstFetchRector.php +++ b/rules/coding-style/src/Rector/String_/SplitStringClassConstantToClassConstFetchRector.php @@ -64,8 +64,7 @@ class AnotherClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/String_/SymplifyQuoteEscapeRector.php b/rules/coding-style/src/Rector/String_/SymplifyQuoteEscapeRector.php index d488bcae750..8a224ccd142 100644 --- a/rules/coding-style/src/Rector/String_/SymplifyQuoteEscapeRector.php +++ b/rules/coding-style/src/Rector/String_/SymplifyQuoteEscapeRector.php @@ -50,8 +50,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/Ternary/TernaryConditionVariableAssignmentRector.php b/rules/coding-style/src/Rector/Ternary/TernaryConditionVariableAssignmentRector.php index 56421432521..039485ebb27 100644 --- a/rules/coding-style/src/Rector/Ternary/TernaryConditionVariableAssignmentRector.php +++ b/rules/coding-style/src/Rector/Ternary/TernaryConditionVariableAssignmentRector.php @@ -37,8 +37,7 @@ function ternary($value) $a = $value ? 1 : 0; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/coding-style/src/Rector/Use_/SplitGroupedUseImportsRector.php b/rules/coding-style/src/Rector/Use_/SplitGroupedUseImportsRector.php index 125ac6992af..e5afbc82878 100644 --- a/rules/coding-style/src/Rector/Use_/SplitGroupedUseImportsRector.php +++ b/rules/coding-style/src/Rector/Use_/SplitGroupedUseImportsRector.php @@ -43,8 +43,7 @@ class SomeClass use AnotherTrait; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/Assign/RemoveAssignOfVoidReturnFunctionRector.php b/rules/dead-code/src/Rector/Assign/RemoveAssignOfVoidReturnFunctionRector.php index f749fd037a8..b2650c04da8 100644 --- a/rules/dead-code/src/Rector/Assign/RemoveAssignOfVoidReturnFunctionRector.php +++ b/rules/dead-code/src/Rector/Assign/RemoveAssignOfVoidReturnFunctionRector.php @@ -52,8 +52,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/ClassMethod/RemoveDeadRecursiveClassMethodRector.php b/rules/dead-code/src/Rector/ClassMethod/RemoveDeadRecursiveClassMethodRector.php index 1983e37bc33..eca4a9fa665 100644 --- a/rules/dead-code/src/Rector/ClassMethod/RemoveDeadRecursiveClassMethodRector.php +++ b/rules/dead-code/src/Rector/ClassMethod/RemoveDeadRecursiveClassMethodRector.php @@ -62,8 +62,7 @@ class SomeClass { } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php b/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php index c76a703cfe1..0e6a6036237 100644 --- a/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php +++ b/rules/dead-code/src/Rector/ClassMethod/RemoveDelegatingParentCallRector.php @@ -54,8 +54,7 @@ class SomeClass { } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/ClassMethod/RemoveEmptyClassMethodRector.php b/rules/dead-code/src/Rector/ClassMethod/RemoveEmptyClassMethodRector.php index 40892077965..0c9a255886b 100644 --- a/rules/dead-code/src/Rector/ClassMethod/RemoveEmptyClassMethodRector.php +++ b/rules/dead-code/src/Rector/ClassMethod/RemoveEmptyClassMethodRector.php @@ -57,8 +57,7 @@ class OrphanClass { } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/ClassMethod/RemoveUnusedParameterRector.php b/rules/dead-code/src/Rector/ClassMethod/RemoveUnusedParameterRector.php index 7818b5f3194..bed0a86d2ba 100644 --- a/rules/dead-code/src/Rector/ClassMethod/RemoveUnusedParameterRector.php +++ b/rules/dead-code/src/Rector/ClassMethod/RemoveUnusedParameterRector.php @@ -93,8 +93,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/Class_/RemoveEmptyAbstractClassRector.php b/rules/dead-code/src/Rector/Class_/RemoveEmptyAbstractClassRector.php index 892ffc16b0a..ce0562a2fb2 100644 --- a/rules/dead-code/src/Rector/Class_/RemoveEmptyAbstractClassRector.php +++ b/rules/dead-code/src/Rector/Class_/RemoveEmptyAbstractClassRector.php @@ -75,8 +75,7 @@ abstracst clas AnotherAbstractClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/Class_/RemoveUnusedDoctrineEntityMethodAndPropertyRector.php b/rules/dead-code/src/Rector/Class_/RemoveUnusedDoctrineEntityMethodAndPropertyRector.php index fae0cf38254..1360f9a6e44 100644 --- a/rules/dead-code/src/Rector/Class_/RemoveUnusedDoctrineEntityMethodAndPropertyRector.php +++ b/rules/dead-code/src/Rector/Class_/RemoveUnusedDoctrineEntityMethodAndPropertyRector.php @@ -100,8 +100,7 @@ class UserEntity { } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/Concat/RemoveConcatAutocastRector.php b/rules/dead-code/src/Rector/Concat/RemoveConcatAutocastRector.php index f01a5c9968f..138bd698c02 100644 --- a/rules/dead-code/src/Rector/Concat/RemoveConcatAutocastRector.php +++ b/rules/dead-code/src/Rector/Concat/RemoveConcatAutocastRector.php @@ -42,8 +42,7 @@ class SomeConcatingClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/For_/RemoveDeadIfForeachForRector.php b/rules/dead-code/src/Rector/For_/RemoveDeadIfForeachForRector.php index f86306ebcdf..49af480fa02 100644 --- a/rules/dead-code/src/Rector/For_/RemoveDeadIfForeachForRector.php +++ b/rules/dead-code/src/Rector/For_/RemoveDeadIfForeachForRector.php @@ -59,8 +59,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/For_/RemoveDeadLoopRector.php b/rules/dead-code/src/Rector/For_/RemoveDeadLoopRector.php index 40f775c8490..31d59106a99 100644 --- a/rules/dead-code/src/Rector/For_/RemoveDeadLoopRector.php +++ b/rules/dead-code/src/Rector/For_/RemoveDeadLoopRector.php @@ -43,8 +43,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/FunctionLike/RemoveDeadReturnRector.php b/rules/dead-code/src/Rector/FunctionLike/RemoveDeadReturnRector.php index d439ab1cf9f..8b426734c70 100644 --- a/rules/dead-code/src/Rector/FunctionLike/RemoveDeadReturnRector.php +++ b/rules/dead-code/src/Rector/FunctionLike/RemoveDeadReturnRector.php @@ -53,8 +53,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php b/rules/dead-code/src/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php index 63c37cc50a8..5c9ade98a6e 100644 --- a/rules/dead-code/src/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php +++ b/rules/dead-code/src/Rector/FunctionLike/RemoveDuplicatedIfReturnRector.php @@ -82,8 +82,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/FunctionLike/RemoveOverriddenValuesRector.php b/rules/dead-code/src/Rector/FunctionLike/RemoveOverriddenValuesRector.php index 9f3491d5008..1705ffa2580 100644 --- a/rules/dead-code/src/Rector/FunctionLike/RemoveOverriddenValuesRector.php +++ b/rules/dead-code/src/Rector/FunctionLike/RemoveOverriddenValuesRector.php @@ -75,8 +75,7 @@ final class SomeController } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php b/rules/dead-code/src/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php index d993fac1ae7..f8e5de06066 100644 --- a/rules/dead-code/src/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php +++ b/rules/dead-code/src/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php @@ -77,8 +77,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/If_/UnwrapFutureCompatibleIfFunctionExistsRector.php b/rules/dead-code/src/Rector/If_/UnwrapFutureCompatibleIfFunctionExistsRector.php index bea81f5ee80..1f54f58a1cb 100644 --- a/rules/dead-code/src/Rector/If_/UnwrapFutureCompatibleIfFunctionExistsRector.php +++ b/rules/dead-code/src/Rector/If_/UnwrapFutureCompatibleIfFunctionExistsRector.php @@ -68,8 +68,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php b/rules/dead-code/src/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php index 53e218949ac..0d2324a1705 100644 --- a/rules/dead-code/src/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php +++ b/rules/dead-code/src/Rector/If_/UnwrapFutureCompatibleIfPhpVersionRector.php @@ -55,8 +55,7 @@ CODE_SAMPLE // current PHP: 7.2 return 'is PHP 7.2+'; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php b/rules/dead-code/src/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php index 09e21f85876..a9a43870017 100644 --- a/rules/dead-code/src/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php +++ b/rules/dead-code/src/Rector/Plus/RemoveDeadZeroAndOneOperationRector.php @@ -56,8 +56,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/Property/RemoveSetterOnlyPropertyAndMethodCallRector.php b/rules/dead-code/src/Rector/Property/RemoveSetterOnlyPropertyAndMethodCallRector.php index b1f9967a281..c016c20f026 100644 --- a/rules/dead-code/src/Rector/Property/RemoveSetterOnlyPropertyAndMethodCallRector.php +++ b/rules/dead-code/src/Rector/Property/RemoveSetterOnlyPropertyAndMethodCallRector.php @@ -101,8 +101,7 @@ class ActiveOnlySetter } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php b/rules/dead-code/src/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php index b816c144cd0..c3be61619f0 100644 --- a/rules/dead-code/src/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php +++ b/rules/dead-code/src/Rector/PropertyProperty/RemoveNullPropertyInitializationRector.php @@ -39,8 +39,7 @@ class SunshineCommand extends ParentClassWithNewConstructor private $myVar; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/StaticCall/RemoveParentCallWithoutParentRector.php b/rules/dead-code/src/Rector/StaticCall/RemoveParentCallWithoutParentRector.php index f63853901b9..4bdf81644d6 100644 --- a/rules/dead-code/src/Rector/StaticCall/RemoveParentCallWithoutParentRector.php +++ b/rules/dead-code/src/Rector/StaticCall/RemoveParentCallWithoutParentRector.php @@ -54,8 +54,7 @@ class OrphanClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-code/src/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php b/rules/dead-code/src/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php index 7451b55fa72..79ef876efc9 100644 --- a/rules/dead-code/src/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php +++ b/rules/dead-code/src/Rector/Switch_/RemoveDuplicatedCaseInSwitchRector.php @@ -60,8 +60,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessParamTagRector.php b/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessParamTagRector.php index 2affd377528..cd7ad984178 100644 --- a/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessParamTagRector.php +++ b/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessParamTagRector.php @@ -65,8 +65,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessReturnTagRector.php b/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessReturnTagRector.php index 0c645b32596..4f32a9f5dd4 100644 --- a/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessReturnTagRector.php +++ b/rules/dead-doc-block/src/Rector/ClassMethod/RemoveUselessReturnTagRector.php @@ -56,8 +56,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/dead-doc-block/src/Rector/Node/RemoveNonExistingVarAnnotationRector.php b/rules/dead-doc-block/src/Rector/Node/RemoveNonExistingVarAnnotationRector.php index 42cecf8b979..0d49c6d7656 100644 --- a/rules/dead-doc-block/src/Rector/Node/RemoveNonExistingVarAnnotationRector.php +++ b/rules/dead-doc-block/src/Rector/Node/RemoveNonExistingVarAnnotationRector.php @@ -93,8 +93,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/defluent/src/Rector/ClassMethod/ReturnThisRemoveRector.php b/rules/defluent/src/Rector/ClassMethod/ReturnThisRemoveRector.php index cec1ac109a8..a9fefdd073a 100644 --- a/rules/defluent/src/Rector/ClassMethod/ReturnThisRemoveRector.php +++ b/rules/defluent/src/Rector/ClassMethod/ReturnThisRemoveRector.php @@ -65,8 +65,7 @@ class SomeExampleClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/defluent/src/Rector/MethodCall/FluentChainMethodCallToNormalMethodCallRector.php b/rules/defluent/src/Rector/MethodCall/FluentChainMethodCallToNormalMethodCallRector.php index 3d69a3d9583..e6ffc1c2b9f 100644 --- a/rules/defluent/src/Rector/MethodCall/FluentChainMethodCallToNormalMethodCallRector.php +++ b/rules/defluent/src/Rector/MethodCall/FluentChainMethodCallToNormalMethodCallRector.php @@ -41,8 +41,7 @@ $someClass = new SomeClass(); $someClass->someFunction(); $someClass->otherFunction(); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/defluent/src/Rector/MethodCall/MethodCallOnSetterMethodCallToStandaloneAssignRector.php b/rules/defluent/src/Rector/MethodCall/MethodCallOnSetterMethodCallToStandaloneAssignRector.php index 589944da30a..48f9bf21b35 100644 --- a/rules/defluent/src/Rector/MethodCall/MethodCallOnSetterMethodCallToStandaloneAssignRector.php +++ b/rules/defluent/src/Rector/MethodCall/MethodCallOnSetterMethodCallToStandaloneAssignRector.php @@ -76,8 +76,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/defluent/src/Rector/MethodCall/NewFluentChainMethodCallToNonFluentRector.php b/rules/defluent/src/Rector/MethodCall/NewFluentChainMethodCallToNonFluentRector.php index 65d0fbd5b62..e3ae5654390 100644 --- a/rules/defluent/src/Rector/MethodCall/NewFluentChainMethodCallToNonFluentRector.php +++ b/rules/defluent/src/Rector/MethodCall/NewFluentChainMethodCallToNonFluentRector.php @@ -51,8 +51,7 @@ $someClass = new SomeClass(); $someClass->someFunction(); $someClass->otherFunction(); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/defluent/src/Rector/Return_/ReturnNewFluentChainMethodCallToNonFluentRector.php b/rules/defluent/src/Rector/Return_/ReturnNewFluentChainMethodCallToNonFluentRector.php index f4014522f02..48308b6c140 100644 --- a/rules/defluent/src/Rector/Return_/ReturnNewFluentChainMethodCallToNonFluentRector.php +++ b/rules/defluent/src/Rector/Return_/ReturnNewFluentChainMethodCallToNonFluentRector.php @@ -39,8 +39,7 @@ $someClass->someFunction(); $someClass->otherFunction(); return $someClass; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntityDateTimePropertyDateTimeInterfaceRector.php b/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntityDateTimePropertyDateTimeInterfaceRector.php index a92067fb1af..b505880eef2 100644 --- a/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntityDateTimePropertyDateTimeInterfaceRector.php +++ b/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntityDateTimePropertyDateTimeInterfaceRector.php @@ -87,8 +87,7 @@ class User } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php b/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php index 2d34379b2d9..ecc07b6dd14 100644 --- a/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php +++ b/rules/doctrine-code-quality/src/Rector/ClassMethod/MakeEntitySetterNullabilityInSyncWithPropertyRector.php @@ -88,8 +88,7 @@ class Product } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-code-quality/src/Rector/Class_/InitializeDefaultEntityCollectionRector.php b/rules/doctrine-code-quality/src/Rector/Class_/InitializeDefaultEntityCollectionRector.php index 8eb3b9f8801..1a968ba8ce9 100644 --- a/rules/doctrine-code-quality/src/Rector/Class_/InitializeDefaultEntityCollectionRector.php +++ b/rules/doctrine-code-quality/src/Rector/Class_/InitializeDefaultEntityCollectionRector.php @@ -74,8 +74,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-code-quality/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php b/rules/doctrine-code-quality/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php index b158c8dd871..a179b9d1efc 100644 --- a/rules/doctrine-code-quality/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php +++ b/rules/doctrine-code-quality/src/Rector/Class_/MoveCurrentDateTimeDefaultInEntityToConstructorRector.php @@ -103,8 +103,7 @@ class User } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-code-quality/src/Rector/MethodCall/ChangeSetParametersArrayToArrayCollectionRector.php b/rules/doctrine-code-quality/src/Rector/MethodCall/ChangeSetParametersArrayToArrayCollectionRector.php index 18464e816e7..b7b50b2b583 100644 --- a/rules/doctrine-code-quality/src/Rector/MethodCall/ChangeSetParametersArrayToArrayCollectionRector.php +++ b/rules/doctrine-code-quality/src/Rector/MethodCall/ChangeSetParametersArrayToArrayCollectionRector.php @@ -120,8 +120,7 @@ class SomeRepository extends EntityRepository } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-code-quality/src/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php b/rules/doctrine-code-quality/src/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php index 32d49719c05..5d0017a50b5 100644 --- a/rules/doctrine-code-quality/src/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php +++ b/rules/doctrine-code-quality/src/Rector/Property/ChangeBigIntEntityPropertyToIntTypeRector.php @@ -73,8 +73,7 @@ class SomeEntity private $bigNumber; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-code-quality/src/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php b/rules/doctrine-code-quality/src/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php index 9f07de8511f..5c12ad7641c 100644 --- a/rules/doctrine-code-quality/src/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php +++ b/rules/doctrine-code-quality/src/Rector/Property/CorrectDefaultTypesOnEntityPropertyRector.php @@ -60,8 +60,7 @@ class User private $isOld = false; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/BlameableBehaviorRector.php b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/BlameableBehaviorRector.php index 5f03870dce4..c855019792c 100644 --- a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/BlameableBehaviorRector.php +++ b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/BlameableBehaviorRector.php @@ -91,8 +91,7 @@ class SomeClass implements BlameableInterface use BlameableTrait; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/LoggableBehaviorRector.php b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/LoggableBehaviorRector.php index 15d67c99659..39c02648077 100644 --- a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/LoggableBehaviorRector.php +++ b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/LoggableBehaviorRector.php @@ -74,8 +74,7 @@ class SomeClass implements LoggableInterface private $title; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/SluggableBehaviorRector.php b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/SluggableBehaviorRector.php index 7db031bc90e..7923629ffdc 100644 --- a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/SluggableBehaviorRector.php +++ b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/SluggableBehaviorRector.php @@ -89,8 +89,7 @@ class SomeClass implements SluggableInterface } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/TranslationBehaviorRector.php b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/TranslationBehaviorRector.php index 2b7406de1d4..680d7950253 100644 --- a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/TranslationBehaviorRector.php +++ b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/TranslationBehaviorRector.php @@ -149,8 +149,7 @@ class SomeClassTranslation implements TranslationInterface private $content; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/TreeBehaviorRector.php b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/TreeBehaviorRector.php index 882c70c8d82..6cefc51367d 100644 --- a/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/TreeBehaviorRector.php +++ b/rules/doctrine-gedmo-to-knplabs/src/Rector/Class_/TreeBehaviorRector.php @@ -121,8 +121,7 @@ class SomeClass implements TreeNodeInterface use TreeNodeTrait; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine/src/Rector/ClassMethod/ChangeGetIdTypeToUuidRector.php b/rules/doctrine/src/Rector/ClassMethod/ChangeGetIdTypeToUuidRector.php index 112330b36e2..e4be65d06f0 100644 --- a/rules/doctrine/src/Rector/ClassMethod/ChangeGetIdTypeToUuidRector.php +++ b/rules/doctrine/src/Rector/ClassMethod/ChangeGetIdTypeToUuidRector.php @@ -64,8 +64,7 @@ class GetId } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine/src/Rector/ClassMethod/ChangeSetIdTypeToUuidRector.php b/rules/doctrine/src/Rector/ClassMethod/ChangeSetIdTypeToUuidRector.php index 1c6b47e87f1..b76a316c7f9 100644 --- a/rules/doctrine/src/Rector/ClassMethod/ChangeSetIdTypeToUuidRector.php +++ b/rules/doctrine/src/Rector/ClassMethod/ChangeSetIdTypeToUuidRector.php @@ -69,8 +69,7 @@ class SetId } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine/src/Rector/Class_/AlwaysInitializeUuidInEntityRector.php b/rules/doctrine/src/Rector/Class_/AlwaysInitializeUuidInEntityRector.php index ef9e6c378b5..14b87b513ea 100644 --- a/rules/doctrine/src/Rector/Class_/AlwaysInitializeUuidInEntityRector.php +++ b/rules/doctrine/src/Rector/Class_/AlwaysInitializeUuidInEntityRector.php @@ -92,8 +92,7 @@ class AddUuidInit } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php b/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php index 2536bd1e3d9..b7d0bb0db4f 100644 --- a/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php +++ b/rules/doctrine/src/Rector/Class_/ManagerRegistryGetManagerToEntityManagerRector.php @@ -106,8 +106,7 @@ class CustomRepository } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine/src/Rector/Class_/RemoveRepositoryFromEntityAnnotationRector.php b/rules/doctrine/src/Rector/Class_/RemoveRepositoryFromEntityAnnotationRector.php index edc9f9c9d36..2ba5b5adda9 100644 --- a/rules/doctrine/src/Rector/Class_/RemoveRepositoryFromEntityAnnotationRector.php +++ b/rules/doctrine/src/Rector/Class_/RemoveRepositoryFromEntityAnnotationRector.php @@ -43,8 +43,7 @@ class Product { } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/doctrine/src/Rector/Identical/ChangeIdenticalUuidToEqualsMethodCallRector.php b/rules/doctrine/src/Rector/Identical/ChangeIdenticalUuidToEqualsMethodCallRector.php index 4d3ad69ab26..0102b5f0ad5 100644 --- a/rules/doctrine/src/Rector/Identical/ChangeIdenticalUuidToEqualsMethodCallRector.php +++ b/rules/doctrine/src/Rector/Identical/ChangeIdenticalUuidToEqualsMethodCallRector.php @@ -58,8 +58,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/downgrade-php72/src/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php b/rules/downgrade-php72/src/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php index 8ff3dd4c25c..4992bfd977a 100644 --- a/rules/downgrade-php72/src/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php +++ b/rules/downgrade-php72/src/Rector/ClassMethod/DowngradeParameterTypeWideningRector.php @@ -82,8 +82,7 @@ class C implements A public function test($input); } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/downgrade-php73/src/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php b/rules/downgrade-php73/src/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php index 1151c42bc49..0b14c96670f 100644 --- a/rules/downgrade-php73/src/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php +++ b/rules/downgrade-php73/src/Rector/String_/DowngradeFlexibleHeredocSyntaxRector.php @@ -43,8 +43,7 @@ FROM `table` WHERE `column` = true; SQL; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/downgrade-php74/src/Rector/Array_/DowngradeArraySpreadRector.php b/rules/downgrade-php74/src/Rector/Array_/DowngradeArraySpreadRector.php index eb62a52b9f1..b880298f18a 100644 --- a/rules/downgrade-php74/src/Rector/Array_/DowngradeArraySpreadRector.php +++ b/rules/downgrade-php74/src/Rector/Array_/DowngradeArraySpreadRector.php @@ -79,8 +79,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/downgrade-php74/src/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php b/rules/downgrade-php74/src/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php index bb81f57171c..1303997fe2c 100644 --- a/rules/downgrade-php74/src/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php +++ b/rules/downgrade-php74/src/Rector/ArrowFunction/ArrowFunctionToAnonymousFunctionRector.php @@ -6,13 +6,9 @@ namespace Rector\DowngradePhp74\Rector\ArrowFunction; use PhpParser\Node; use PhpParser\Node\Expr\ArrowFunction; -use PhpParser\Node\Identifier; -use PhpParser\Node\Name; -use PhpParser\Node\NullableType; -use PhpParser\Node\Param; use PhpParser\Node\Stmt\Return_; -use PhpParser\Node\UnionType; -use Rector\Php72\Rector\FuncCall\AbstractConvertToAnonymousFunctionRector; +use Rector\Core\Rector\AbstractRector; +use Rector\Php72\NodeFactory\AnonymousFunctionFactory; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -21,15 +17,23 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; * * @see \Rector\DowngradePhp74\Tests\Rector\ArrowFunction\ArrowFunctionToAnonymousFunctionRector\ArrowFunctionToAnonymousFunctionRectorTest */ -final class ArrowFunctionToAnonymousFunctionRector extends AbstractConvertToAnonymousFunctionRector +final class ArrowFunctionToAnonymousFunctionRector extends AbstractRector { + /** + * @var AnonymousFunctionFactory + */ + private $anonymousFunctionFactory; + + public function __construct(AnonymousFunctionFactory $anonymousFunctionFactory) + { + $this->anonymousFunctionFactory = $anonymousFunctionFactory; + } + public function getRuleDefinition(): RuleDefinition { - return new RuleDefinition( - 'Replace arrow functions with anonymous functions', - [ - new CodeSample( - <<<'CODE_SAMPLE' + return new RuleDefinition('Replace arrow functions with anonymous functions', [ + new CodeSample( + <<<'CODE_SAMPLE' class SomeClass { public function run() @@ -39,8 +43,8 @@ class SomeClass } } CODE_SAMPLE - , - <<<'CODE_SAMPLE' + , + <<<'CODE_SAMPLE' class SomeClass { public function run() @@ -52,9 +56,8 @@ class SomeClass } } CODE_SAMPLE - ), - - ]); + ), + ]); } /** @@ -68,35 +71,10 @@ CODE_SAMPLE /** * @param ArrowFunction $node */ - public function shouldSkip(Node $node): bool + public function refactor(Node $node): ?Node { - return false; - } + $stmts = [new Return_($node->expr)]; - /** - * @param ArrowFunction $node - * @return Param[] - */ - public function getParameters(Node $node): array - { - return $node->params; - } - - /** - * @param ArrowFunction $node - * @return Identifier|Name|NullableType|UnionType|null - */ - public function getReturnType(Node $node): ?Node - { - return $node->returnType; - } - - /** - * @param ArrowFunction $node - * @return Return_[] - */ - public function getBody(Node $node): array - { - return [new Return_($node->expr)]; + return $this->anonymousFunctionFactory->create($node->params, $stmts, $node->returnType); } } diff --git a/rules/downgrade-php74/src/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector.php b/rules/downgrade-php74/src/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector.php index 64245a6010a..78e3b5cb28d 100644 --- a/rules/downgrade-php74/src/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector.php +++ b/rules/downgrade-php74/src/Rector/FuncCall/DowngradeArrayMergeCallWithoutArgumentsRector.php @@ -44,8 +44,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/downgrade-php74/src/Rector/FuncCall/DowngradeStripTagsCallWithArrayRector.php b/rules/downgrade-php74/src/Rector/FuncCall/DowngradeStripTagsCallWithArrayRector.php index 525c182456d..f8eaf6cf65c 100644 --- a/rules/downgrade-php74/src/Rector/FuncCall/DowngradeStripTagsCallWithArrayRector.php +++ b/rules/downgrade-php74/src/Rector/FuncCall/DowngradeStripTagsCallWithArrayRector.php @@ -83,8 +83,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/downgrade-php74/src/Rector/Identical/DowngradeFreadFwriteFalsyToNegationRector.php b/rules/downgrade-php74/src/Rector/Identical/DowngradeFreadFwriteFalsyToNegationRector.php index 4e2cd261fd3..d99702a96fb 100644 --- a/rules/downgrade-php74/src/Rector/Identical/DowngradeFreadFwriteFalsyToNegationRector.php +++ b/rules/downgrade-php74/src/Rector/Identical/DowngradeFreadFwriteFalsyToNegationRector.php @@ -38,8 +38,7 @@ CODE_SAMPLE !fread($handle, $length); !fwrite($fp, '1'); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/downgrade-php74/src/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php b/rules/downgrade-php74/src/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php index 8aef917bc0b..aa721e1b1e9 100644 --- a/rules/downgrade-php74/src/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php +++ b/rules/downgrade-php74/src/Rector/LNumber/DowngradeNumericLiteralSeparatorRector.php @@ -46,8 +46,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/early-return/src/Rector/If_/RemoveAlwaysElseRector.php b/rules/early-return/src/Rector/If_/RemoveAlwaysElseRector.php index 04a36d5256c..c4212bcbc11 100644 --- a/rules/early-return/src/Rector/If_/RemoveAlwaysElseRector.php +++ b/rules/early-return/src/Rector/If_/RemoveAlwaysElseRector.php @@ -54,8 +54,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/laravel/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php b/rules/laravel/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php index 668b7ca35ad..dc02a329dde 100644 --- a/rules/laravel/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php +++ b/rules/laravel/src/Rector/ClassMethod/AddParentBootToModelClassMethodRector.php @@ -67,8 +67,7 @@ class Product extends Model } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/laravel/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php b/rules/laravel/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php index b643220b61c..872300e67e4 100644 --- a/rules/laravel/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php +++ b/rules/laravel/src/Rector/Class_/AddMockConsoleOutputFalseToConsoleTestsRector.php @@ -81,8 +81,7 @@ final class SomeTest extends TestCase } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php b/rules/laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php index dbe686055d1..96bcc31526b 100644 --- a/rules/laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php +++ b/rules/laravel/src/Rector/Class_/PropertyDeferToDeferrableProviderToRector.php @@ -46,8 +46,7 @@ final class SomeServiceProvider extends ServiceProvider implements DeferrablePro { } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php b/rules/laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php index f50af29b280..cf0e53b8be4 100644 --- a/rules/laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php +++ b/rules/laravel/src/Rector/MethodCall/ChangeQueryWhereDateValueWithCarbonRector.php @@ -57,8 +57,7 @@ final class SomeClass } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/laravel/src/Rector/New_/AddGuardToLoginEventRector.php b/rules/laravel/src/Rector/New_/AddGuardToLoginEventRector.php index 011798714ea..310448f5d34 100644 --- a/rules/laravel/src/Rector/New_/AddGuardToLoginEventRector.php +++ b/rules/laravel/src/Rector/New_/AddGuardToLoginEventRector.php @@ -52,8 +52,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/laravel/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php b/rules/laravel/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php index 924c92e4c78..d2df4157032 100644 --- a/rules/laravel/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php +++ b/rules/laravel/src/Rector/StaticCall/Redirect301ToPermanentRedirectRector.php @@ -56,8 +56,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/laravel/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php b/rules/laravel/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php index 00dc83c2f35..9047259680f 100644 --- a/rules/laravel/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php +++ b/rules/laravel/src/Rector/StaticCall/RequestStaticValidateToInjectRector.php @@ -69,8 +69,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/legacy/src/Rector/Class_/ChangeSingletonToServiceRector.php b/rules/legacy/src/Rector/Class_/ChangeSingletonToServiceRector.php index 4a6c0e3529d..0b92c3f66aa 100644 --- a/rules/legacy/src/Rector/Class_/ChangeSingletonToServiceRector.php +++ b/rules/legacy/src/Rector/Class_/ChangeSingletonToServiceRector.php @@ -66,8 +66,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/mockista-to-mockery/src/Rector/ClassMethod/MockistaMockToMockeryMockRector.php b/rules/mockista-to-mockery/src/Rector/ClassMethod/MockistaMockToMockeryMockRector.php index f8d4132b5a4..106dc1b8291 100644 --- a/rules/mockista-to-mockery/src/Rector/ClassMethod/MockistaMockToMockeryMockRector.php +++ b/rules/mockista-to-mockery/src/Rector/ClassMethod/MockistaMockToMockeryMockRector.php @@ -88,8 +88,7 @@ class SomeTest } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/mockista-to-mockery/src/Rector/Class_/MockeryTearDownRector.php b/rules/mockista-to-mockery/src/Rector/Class_/MockeryTearDownRector.php index 2942c91c523..9e107afd870 100644 --- a/rules/mockista-to-mockery/src/Rector/Class_/MockeryTearDownRector.php +++ b/rules/mockista-to-mockery/src/Rector/Class_/MockeryTearDownRector.php @@ -65,8 +65,7 @@ class SomeTest extends TestCase } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php b/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php index 1db27be0a7b..e47c13659aa 100644 --- a/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php +++ b/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlPConnectToMysqliConnectRector.php @@ -45,8 +45,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php b/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php index 51ba1541611..b01fef2cf74 100644 --- a/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php +++ b/rules/mysql-to-mysqli/src/Rector/FuncCall/MysqlQueryMysqlErrorWithLinkRector.php @@ -109,8 +109,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/naming/src/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php b/rules/naming/src/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php index 0fe4f52f021..ff49bc42bdf 100644 --- a/rules/naming/src/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php +++ b/rules/naming/src/Rector/ClassMethod/MakeGetterClassMethodNameStartWithGetRector.php @@ -80,8 +80,7 @@ class SomeClass } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/naming/src/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php b/rules/naming/src/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php index 6fd16819c2c..353f025a798 100644 --- a/rules/naming/src/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php +++ b/rules/naming/src/Rector/ClassMethod/MakeIsserClassMethodNameStartWithIsRector.php @@ -81,8 +81,7 @@ class SomeClass } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/naming/src/Rector/Class_/RenamePropertyToMatchTypeRector.php b/rules/naming/src/Rector/Class_/RenamePropertyToMatchTypeRector.php index d4dcf0c7471..63508d57a4f 100644 --- a/rules/naming/src/Rector/Class_/RenamePropertyToMatchTypeRector.php +++ b/rules/naming/src/Rector/Class_/RenamePropertyToMatchTypeRector.php @@ -106,8 +106,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/naming/src/Rector/Foreach_/RenameForeachValueVariableToMatchMethodCallReturnTypeRector.php b/rules/naming/src/Rector/Foreach_/RenameForeachValueVariableToMatchMethodCallReturnTypeRector.php index f2aae53066a..1641f51003d 100644 --- a/rules/naming/src/Rector/Foreach_/RenameForeachValueVariableToMatchMethodCallReturnTypeRector.php +++ b/rules/naming/src/Rector/Foreach_/RenameForeachValueVariableToMatchMethodCallReturnTypeRector.php @@ -93,8 +93,7 @@ class SomeClass } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/naming/src/Rector/Variable/UnderscoreToCamelCaseLocalVariableNameRector.php b/rules/naming/src/Rector/Variable/UnderscoreToCamelCaseLocalVariableNameRector.php index 4f14de511b6..558ecafc0fb 100644 --- a/rules/naming/src/Rector/Variable/UnderscoreToCamelCaseLocalVariableNameRector.php +++ b/rules/naming/src/Rector/Variable/UnderscoreToCamelCaseLocalVariableNameRector.php @@ -61,8 +61,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-code-quality/src/Rector/ArrayDimFetch/AnnotateMagicalControlArrayAccessRector.php b/rules/nette-code-quality/src/Rector/ArrayDimFetch/AnnotateMagicalControlArrayAccessRector.php index 011ef700791..d5e42b75b77 100644 --- a/rules/nette-code-quality/src/Rector/ArrayDimFetch/AnnotateMagicalControlArrayAccessRector.php +++ b/rules/nette-code-quality/src/Rector/ArrayDimFetch/AnnotateMagicalControlArrayAccessRector.php @@ -91,8 +91,7 @@ final class SomePresenter extends Presenter } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-code-quality/src/Rector/ArrayDimFetch/ChangeFormArrayAccessToAnnotatedControlVariableRector.php b/rules/nette-code-quality/src/Rector/ArrayDimFetch/ChangeFormArrayAccessToAnnotatedControlVariableRector.php index e44727ffd80..a907eee8b58 100644 --- a/rules/nette-code-quality/src/Rector/ArrayDimFetch/ChangeFormArrayAccessToAnnotatedControlVariableRector.php +++ b/rules/nette-code-quality/src/Rector/ArrayDimFetch/ChangeFormArrayAccessToAnnotatedControlVariableRector.php @@ -79,8 +79,7 @@ class SomePresenter } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-code-quality/src/Rector/Assign/ArrayAccessGetControlToGetComponentMethodCallRector.php b/rules/nette-code-quality/src/Rector/Assign/ArrayAccessGetControlToGetComponentMethodCallRector.php index 32d6850e29e..516f3bc6030 100644 --- a/rules/nette-code-quality/src/Rector/Assign/ArrayAccessGetControlToGetComponentMethodCallRector.php +++ b/rules/nette-code-quality/src/Rector/Assign/ArrayAccessGetControlToGetComponentMethodCallRector.php @@ -51,8 +51,7 @@ class SomeClass extends Presenter } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-code-quality/src/Rector/Assign/ArrayAccessSetControlToAddComponentMethodCallRector.php b/rules/nette-code-quality/src/Rector/Assign/ArrayAccessSetControlToAddComponentMethodCallRector.php index 1a28a169c46..788c083e906 100644 --- a/rules/nette-code-quality/src/Rector/Assign/ArrayAccessSetControlToAddComponentMethodCallRector.php +++ b/rules/nette-code-quality/src/Rector/Assign/ArrayAccessSetControlToAddComponentMethodCallRector.php @@ -56,8 +56,7 @@ class SomeClass extends Presenter } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-code-quality/src/Rector/Assign/MakeGetComponentAssignAnnotatedRector.php b/rules/nette-code-quality/src/Rector/Assign/MakeGetComponentAssignAnnotatedRector.php index e2d78090894..c6cf9bf318f 100644 --- a/rules/nette-code-quality/src/Rector/Assign/MakeGetComponentAssignAnnotatedRector.php +++ b/rules/nette-code-quality/src/Rector/Assign/MakeGetComponentAssignAnnotatedRector.php @@ -97,8 +97,7 @@ final class AnotherControl extends Control { } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-code-quality/src/Rector/Class_/MoveInjectToExistingConstructorRector.php b/rules/nette-code-quality/src/Rector/Class_/MoveInjectToExistingConstructorRector.php index dbbbcf30440..ccf7c480c4e 100644 --- a/rules/nette-code-quality/src/Rector/Class_/MoveInjectToExistingConstructorRector.php +++ b/rules/nette-code-quality/src/Rector/Class_/MoveInjectToExistingConstructorRector.php @@ -80,8 +80,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-code-quality/src/Rector/Identical/SubstrMinusToStringEndsWithRector.php b/rules/nette-code-quality/src/Rector/Identical/SubstrMinusToStringEndsWithRector.php index 6473f42ba84..21377f5f602 100644 --- a/rules/nette-code-quality/src/Rector/Identical/SubstrMinusToStringEndsWithRector.php +++ b/rules/nette-code-quality/src/Rector/Identical/SubstrMinusToStringEndsWithRector.php @@ -53,8 +53,7 @@ CODE_SAMPLE ! \Nette\Utils\Strings::endsWith($var, 'Test'); \Nette\Utils\Strings::endsWith($var, 'Test'); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-kdyby/src/NodeAnalyzer/GetSubscribedEventsClassMethodAnalyzer.php b/rules/nette-kdyby/src/NodeAnalyzer/GetSubscribedEventsClassMethodAnalyzer.php new file mode 100644 index 00000000000..f33cd72f885 --- /dev/null +++ b/rules/nette-kdyby/src/NodeAnalyzer/GetSubscribedEventsClassMethodAnalyzer.php @@ -0,0 +1,45 @@ +nodeTypeResolver = $nodeTypeResolver; + $this->nodeNameResolver = $nodeNameResolver; + } + + public function detect(ClassMethod $classMethod): bool + { + $classLike = $classMethod->getAttribute(AttributeKey::CLASS_NODE); + if (! $classLike instanceof ClassLike) { + return false; + } + + if (! $this->nodeTypeResolver->isObjectType($classLike, new ObjectType('Kdyby\Events\Subscriber'))) { + return false; + } + + return $this->nodeNameResolver->isName($classMethod, 'getSubscribedEvents'); + } +} diff --git a/rules/nette-kdyby/src/Rector/ClassMethod/AbstractKdybyEventSubscriberRector.php b/rules/nette-kdyby/src/Rector/ClassMethod/AbstractKdybyEventSubscriberRector.php deleted file mode 100644 index 720ce6dc4d5..00000000000 --- a/rules/nette-kdyby/src/Rector/ClassMethod/AbstractKdybyEventSubscriberRector.php +++ /dev/null @@ -1,28 +0,0 @@ -getAttribute(AttributeKey::CLASS_NODE); - if (! $classLike instanceof ClassLike) { - return true; - } - - if (! $this->isObjectType($classLike, new ObjectType('Kdyby\Events\Subscriber'))) { - return true; - } - - return ! $this->isName($classMethod, 'getSubscribedEvents'); - } -} diff --git a/rules/nette-kdyby/src/Rector/ClassMethod/ChangeNetteEventNamesInGetSubscribedEventsRector.php b/rules/nette-kdyby/src/Rector/ClassMethod/ChangeNetteEventNamesInGetSubscribedEventsRector.php index 789561e3d96..4421e429a3d 100644 --- a/rules/nette-kdyby/src/Rector/ClassMethod/ChangeNetteEventNamesInGetSubscribedEventsRector.php +++ b/rules/nette-kdyby/src/Rector/ClassMethod/ChangeNetteEventNamesInGetSubscribedEventsRector.php @@ -12,6 +12,8 @@ use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Return_; use Rector\Core\Exception\NotImplementedYetException; +use Rector\Core\Rector\AbstractRector; +use Rector\NetteKdyby\NodeAnalyzer\GetSubscribedEventsClassMethodAnalyzer; use Rector\NetteKdyby\NodeManipulator\GetSubscribedEventsArrayManipulator; use Rector\NetteKdyby\NodeManipulator\ListeningClassMethodArgumentManipulator; use Rector\NetteKdyby\NodeResolver\ListeningMethodsCollector; @@ -23,7 +25,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; * * @see \Rector\NetteKdyby\Tests\Rector\ClassMethod\ChangeNetteEventNamesInGetSubscribedEventsRector\ChangeNetteEventNamesInGetSubscribedEventsRectorTest */ -final class ChangeNetteEventNamesInGetSubscribedEventsRector extends AbstractKdybyEventSubscriberRector +final class ChangeNetteEventNamesInGetSubscribedEventsRector extends AbstractRector { /** * @var GetSubscribedEventsArrayManipulator @@ -40,14 +42,21 @@ final class ChangeNetteEventNamesInGetSubscribedEventsRector extends AbstractKdy */ private $listeningMethodsCollector; + /** + * @var GetSubscribedEventsClassMethodAnalyzer + */ + private $getSubscribedEventsClassMethodAnalyzer; + public function __construct( GetSubscribedEventsArrayManipulator $getSubscribedEventsArrayManipulator, ListeningClassMethodArgumentManipulator $listeningClassMethodArgumentManipulator, - ListeningMethodsCollector $listeningMethodsCollector + ListeningMethodsCollector $listeningMethodsCollector, + GetSubscribedEventsClassMethodAnalyzer $getSubscribedEventsClassMethodAnalyzer ) { $this->getSubscribedEventsArrayManipulator = $getSubscribedEventsArrayManipulator; $this->listeningClassMethodArgumentManipulator = $listeningClassMethodArgumentManipulator; $this->listeningMethodsCollector = $listeningMethodsCollector; + $this->getSubscribedEventsClassMethodAnalyzer = $getSubscribedEventsClassMethodAnalyzer; } public function getRuleDefinition(): RuleDefinition @@ -100,8 +109,7 @@ class GetApplesSubscriber implements Subscriber } } CODE_SAMPLE - ), - + ), ]); } @@ -118,7 +126,7 @@ CODE_SAMPLE */ public function refactor(Node $node): ?Node { - if ($this->shouldSkipClassMethod($node)) { + if (! $this->getSubscribedEventsClassMethodAnalyzer->detect($node)) { return null; } diff --git a/rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicPropertyWithEventClassRector.php b/rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicPropertyWithEventClassRector.php index c477ca913f5..2792b8ef4cd 100644 --- a/rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicPropertyWithEventClassRector.php +++ b/rules/nette-kdyby/src/Rector/ClassMethod/ReplaceMagicPropertyWithEventClassRector.php @@ -9,8 +9,10 @@ use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Stmt\ClassMethod; +use Rector\Core\Rector\AbstractRector; use Rector\NetteKdyby\DataProvider\EventAndListenerTreeProvider; use Rector\NetteKdyby\Naming\EventClassNaming; +use Rector\NetteKdyby\NodeAnalyzer\GetSubscribedEventsClassMethodAnalyzer; use Rector\NetteKdyby\NodeManipulator\ListeningClassMethodArgumentManipulator; use Rector\NodeTypeResolver\Node\AttributeKey; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -21,7 +23,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; * * @see \Rector\NetteKdyby\Tests\Rector\ClassMethod\ReplaceMagicPropertyWithEventClassRector\ReplaceMagicPropertyWithEventClassRectorTest */ -final class ReplaceMagicPropertyWithEventClassRector extends AbstractKdybyEventSubscriberRector +final class ReplaceMagicPropertyWithEventClassRector extends AbstractRector { /** * @var EventClassNaming @@ -38,14 +40,21 @@ final class ReplaceMagicPropertyWithEventClassRector extends AbstractKdybyEventS */ private $eventAndListenerTreeProvider; + /** + * @var GetSubscribedEventsClassMethodAnalyzer + */ + private $getSubscribedEventsClassMethodAnalyzer; + public function __construct( EventAndListenerTreeProvider $eventAndListenerTreeProvider, EventClassNaming $eventClassNaming, - ListeningClassMethodArgumentManipulator $listeningClassMethodArgumentManipulator + ListeningClassMethodArgumentManipulator $listeningClassMethodArgumentManipulator, + GetSubscribedEventsClassMethodAnalyzer $getSubscribedEventsClassMethodAnalyzer ) { $this->eventClassNaming = $eventClassNaming; $this->listeningClassMethodArgumentManipulator = $listeningClassMethodArgumentManipulator; $this->eventAndListenerTreeProvider = $eventAndListenerTreeProvider; + $this->getSubscribedEventsClassMethodAnalyzer = $getSubscribedEventsClassMethodAnalyzer; } public function getRuleDefinition(): RuleDefinition @@ -92,8 +101,7 @@ final class ActionLogEventSubscriber implements Subscriber } } CODE_SAMPLE - ), - + ), ]); } @@ -110,7 +118,7 @@ CODE_SAMPLE */ public function refactor(Node $node): ?Node { - if ($this->shouldSkipClassMethod($node)) { + if (! $this->getSubscribedEventsClassMethodAnalyzer->detect($node)) { return null; } diff --git a/rules/nette-kdyby/src/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector.php b/rules/nette-kdyby/src/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector.php index a998b3fa26d..7aff00cc109 100644 --- a/rules/nette-kdyby/src/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector.php +++ b/rules/nette-kdyby/src/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector.php @@ -99,8 +99,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php b/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php index 1d706bca694..b3149d12d38 100644 --- a/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php +++ b/rules/nette-kdyby/src/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector.php @@ -81,8 +81,7 @@ final class FileManager } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-to-symfony/src/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php b/rules/nette-to-symfony/src/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php index 16af10a6847..86bc4c3d4fb 100644 --- a/rules/nette-to-symfony/src/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php +++ b/rules/nette-to-symfony/src/Rector/ClassMethod/RenameEventNamesInEventSubscriberRector.php @@ -72,8 +72,7 @@ final class SomeClass implements EventSubscriberInterface } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-to-symfony/src/Rector/Class_/NetteControlToSymfonyControllerRector.php b/rules/nette-to-symfony/src/Rector/Class_/NetteControlToSymfonyControllerRector.php index b6647bd5af6..6a4427b5e0b 100644 --- a/rules/nette-to-symfony/src/Rector/Class_/NetteControlToSymfonyControllerRector.php +++ b/rules/nette-to-symfony/src/Rector/Class_/NetteControlToSymfonyControllerRector.php @@ -96,8 +96,7 @@ class SomeController extends AbstractController } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-to-symfony/src/Rector/MethodCall/FromHttpRequestGetHeaderToHeadersGetRector.php b/rules/nette-to-symfony/src/Rector/MethodCall/FromHttpRequestGetHeaderToHeadersGetRector.php index 4fa3f8b181e..c639b26430e 100644 --- a/rules/nette-to-symfony/src/Rector/MethodCall/FromHttpRequestGetHeaderToHeadersGetRector.php +++ b/rules/nette-to-symfony/src/Rector/MethodCall/FromHttpRequestGetHeaderToHeadersGetRector.php @@ -61,8 +61,7 @@ final class SomeController } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-to-symfony/src/Rector/MethodCall/FromRequestGetParameterToAttributesGetRector.php b/rules/nette-to-symfony/src/Rector/MethodCall/FromRequestGetParameterToAttributesGetRector.php index 2e4e3a9303f..ae9a3afde70 100644 --- a/rules/nette-to-symfony/src/Rector/MethodCall/FromRequestGetParameterToAttributesGetRector.php +++ b/rules/nette-to-symfony/src/Rector/MethodCall/FromRequestGetParameterToAttributesGetRector.php @@ -50,8 +50,7 @@ final class SomeController } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-to-symfony/src/Rector/MethodCall/NetteFormToSymfonyFormRector.php b/rules/nette-to-symfony/src/Rector/MethodCall/NetteFormToSymfonyFormRector.php index 2a2b33570b7..38b5361c877 100644 --- a/rules/nette-to-symfony/src/Rector/MethodCall/NetteFormToSymfonyFormRector.php +++ b/rules/nette-to-symfony/src/Rector/MethodCall/NetteFormToSymfonyFormRector.php @@ -96,8 +96,7 @@ class SomePresenter extends UI\Presenter } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-to-symfony/src/Rector/MethodCall/WrapTransParameterNameRector.php b/rules/nette-to-symfony/src/Rector/MethodCall/WrapTransParameterNameRector.php index 4e5f80935e5..1560c333c8a 100644 --- a/rules/nette-to-symfony/src/Rector/MethodCall/WrapTransParameterNameRector.php +++ b/rules/nette-to-symfony/src/Rector/MethodCall/WrapTransParameterNameRector.php @@ -65,8 +65,7 @@ final class SomeController } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette-utils-code-quality/src/Rector/LNumber/ReplaceTimeNumberWithDateTimeConstantRector.php b/rules/nette-utils-code-quality/src/Rector/LNumber/ReplaceTimeNumberWithDateTimeConstantRector.php index c78ec1522f4..f9fc0a4a72b 100644 --- a/rules/nette-utils-code-quality/src/Rector/LNumber/ReplaceTimeNumberWithDateTimeConstantRector.php +++ b/rules/nette-utils-code-quality/src/Rector/LNumber/ReplaceTimeNumberWithDateTimeConstantRector.php @@ -55,8 +55,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/ClassMethod/RemoveParentAndNameFromComponentConstructorRector.php b/rules/nette/src/Rector/ClassMethod/RemoveParentAndNameFromComponentConstructorRector.php index 97d571bd477..71f741a3405 100644 --- a/rules/nette/src/Rector/ClassMethod/RemoveParentAndNameFromComponentConstructorRector.php +++ b/rules/nette/src/Rector/ClassMethod/RemoveParentAndNameFromComponentConstructorRector.php @@ -105,8 +105,7 @@ class SomeControl extends Control } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/ClassMethod/TranslateClassMethodToVariadicsRector.php b/rules/nette/src/Rector/ClassMethod/TranslateClassMethodToVariadicsRector.php index ae6a1d70ffd..cc13caa0ae8 100644 --- a/rules/nette/src/Rector/ClassMethod/TranslateClassMethodToVariadicsRector.php +++ b/rules/nette/src/Rector/ClassMethod/TranslateClassMethodToVariadicsRector.php @@ -63,8 +63,7 @@ final class SomeClass implements ITranslator } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/Class_/MoveFinalGetUserToCheckRequirementsClassMethodRector.php b/rules/nette/src/Rector/Class_/MoveFinalGetUserToCheckRequirementsClassMethodRector.php index fedcb565d79..ee90cff8092 100644 --- a/rules/nette/src/Rector/Class_/MoveFinalGetUserToCheckRequirementsClassMethodRector.php +++ b/rules/nette/src/Rector/Class_/MoveFinalGetUserToCheckRequirementsClassMethodRector.php @@ -74,8 +74,7 @@ class SomeControl extends Presenter } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/FuncCall/FilePutContentsToFileSystemWriteRector.php b/rules/nette/src/Rector/FuncCall/FilePutContentsToFileSystemWriteRector.php index d0e7130b0e7..bc746d0fb2f 100644 --- a/rules/nette/src/Rector/FuncCall/FilePutContentsToFileSystemWriteRector.php +++ b/rules/nette/src/Rector/FuncCall/FilePutContentsToFileSystemWriteRector.php @@ -44,8 +44,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/FuncCall/PregFunctionToNetteUtilsStringsRector.php b/rules/nette/src/Rector/FuncCall/PregFunctionToNetteUtilsStringsRector.php index eda19f9cab0..735b2e098bb 100644 --- a/rules/nette/src/Rector/FuncCall/PregFunctionToNetteUtilsStringsRector.php +++ b/rules/nette/src/Rector/FuncCall/PregFunctionToNetteUtilsStringsRector.php @@ -72,8 +72,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/FuncCall/PregMatchFunctionToNetteUtilsStringsRector.php b/rules/nette/src/Rector/FuncCall/PregMatchFunctionToNetteUtilsStringsRector.php index 6acc6326c49..bc17a95a92b 100644 --- a/rules/nette/src/Rector/FuncCall/PregMatchFunctionToNetteUtilsStringsRector.php +++ b/rules/nette/src/Rector/FuncCall/PregMatchFunctionToNetteUtilsStringsRector.php @@ -64,8 +64,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/FuncCall/SubstrStrlenFunctionToNetteUtilsStringsRector.php b/rules/nette/src/Rector/FuncCall/SubstrStrlenFunctionToNetteUtilsStringsRector.php index a20117803f9..6f6e1c42c02 100644 --- a/rules/nette/src/Rector/FuncCall/SubstrStrlenFunctionToNetteUtilsStringsRector.php +++ b/rules/nette/src/Rector/FuncCall/SubstrStrlenFunctionToNetteUtilsStringsRector.php @@ -48,8 +48,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/Identical/EndsWithFunctionToNetteUtilsStringsRector.php b/rules/nette/src/Rector/Identical/EndsWithFunctionToNetteUtilsStringsRector.php index 675779abd5a..80df2481585 100644 --- a/rules/nette/src/Rector/Identical/EndsWithFunctionToNetteUtilsStringsRector.php +++ b/rules/nette/src/Rector/Identical/EndsWithFunctionToNetteUtilsStringsRector.php @@ -47,8 +47,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/Identical/StartsWithFunctionToNetteUtilsStringsRector.php b/rules/nette/src/Rector/Identical/StartsWithFunctionToNetteUtilsStringsRector.php index be848569241..0a4b0bd4bf1 100644 --- a/rules/nette/src/Rector/Identical/StartsWithFunctionToNetteUtilsStringsRector.php +++ b/rules/nette/src/Rector/Identical/StartsWithFunctionToNetteUtilsStringsRector.php @@ -47,8 +47,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/MethodCall/AddNextrasDatePickerToDateControlRector.php b/rules/nette/src/Rector/MethodCall/AddNextrasDatePickerToDateControlRector.php index 1b2586ce932..630c4557b2d 100644 --- a/rules/nette/src/Rector/MethodCall/AddNextrasDatePickerToDateControlRector.php +++ b/rules/nette/src/Rector/MethodCall/AddNextrasDatePickerToDateControlRector.php @@ -57,8 +57,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/MethodCall/BuilderExpandToHelperExpandRector.php b/rules/nette/src/Rector/MethodCall/BuilderExpandToHelperExpandRector.php index 3d372638550..6e4cf539b55 100644 --- a/rules/nette/src/Rector/MethodCall/BuilderExpandToHelperExpandRector.php +++ b/rules/nette/src/Rector/MethodCall/BuilderExpandToHelperExpandRector.php @@ -56,8 +56,7 @@ final class SomeClass extends CompilerExtension } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/MethodCall/ConvertAddUploadWithThirdArgumentTrueToAddMultiUploadRector.php b/rules/nette/src/Rector/MethodCall/ConvertAddUploadWithThirdArgumentTrueToAddMultiUploadRector.php index d55df77fc6c..6aa12fdf854 100644 --- a/rules/nette/src/Rector/MethodCall/ConvertAddUploadWithThirdArgumentTrueToAddMultiUploadRector.php +++ b/rules/nette/src/Rector/MethodCall/ConvertAddUploadWithThirdArgumentTrueToAddMultiUploadRector.php @@ -34,8 +34,7 @@ $form = new Nette\Forms\Form(); $form->addMultiUpload('...', '...'); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/MethodCall/MagicHtmlCallToAppendAttributeRector.php b/rules/nette/src/Rector/MethodCall/MagicHtmlCallToAppendAttributeRector.php index 3b89349ef82..4bb5c6cb16e 100644 --- a/rules/nette/src/Rector/MethodCall/MagicHtmlCallToAppendAttributeRector.php +++ b/rules/nette/src/Rector/MethodCall/MagicHtmlCallToAppendAttributeRector.php @@ -55,8 +55,7 @@ final class SomeClass } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/MethodCall/MergeDefaultsInGetConfigCompilerExtensionRector.php b/rules/nette/src/Rector/MethodCall/MergeDefaultsInGetConfigCompilerExtensionRector.php index 9b5d861b63b..9faed2dbd5a 100644 --- a/rules/nette/src/Rector/MethodCall/MergeDefaultsInGetConfigCompilerExtensionRector.php +++ b/rules/nette/src/Rector/MethodCall/MergeDefaultsInGetConfigCompilerExtensionRector.php @@ -54,8 +54,7 @@ final class SomeExtension extends CompilerExtension } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/MethodCall/RequestGetCookieDefaultArgumentToCoalesceRector.php b/rules/nette/src/Rector/MethodCall/RequestGetCookieDefaultArgumentToCoalesceRector.php index ae0201bf20a..a831ab58a61 100644 --- a/rules/nette/src/Rector/MethodCall/RequestGetCookieDefaultArgumentToCoalesceRector.php +++ b/rules/nette/src/Rector/MethodCall/RequestGetCookieDefaultArgumentToCoalesceRector.php @@ -50,8 +50,7 @@ class SomeClass } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/MethodCall/SetClassWithArgumentToSetFactoryRector.php b/rules/nette/src/Rector/MethodCall/SetClassWithArgumentToSetFactoryRector.php index d7cb274ce02..3915f71268e 100644 --- a/rules/nette/src/Rector/MethodCall/SetClassWithArgumentToSetFactoryRector.php +++ b/rules/nette/src/Rector/MethodCall/SetClassWithArgumentToSetFactoryRector.php @@ -50,8 +50,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/nette/src/Rector/NotIdentical/StrposToStringsContainsRector.php b/rules/nette/src/Rector/NotIdentical/StrposToStringsContainsRector.php index 97b17e62268..04c9bf87e9d 100644 --- a/rules/nette/src/Rector/NotIdentical/StrposToStringsContainsRector.php +++ b/rules/nette/src/Rector/NotIdentical/StrposToStringsContainsRector.php @@ -49,8 +49,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/order/src/Order/OrderChangeAnalyzer.php b/rules/order/src/Order/OrderChangeAnalyzer.php new file mode 100644 index 00000000000..7a9c51194d1 --- /dev/null +++ b/rules/order/src/Order/OrderChangeAnalyzer.php @@ -0,0 +1,16 @@ + $oldToNewKeys + */ + public function hasOrderChanged(array $oldToNewKeys): bool + { + return array_keys($oldToNewKeys) !== array_values($oldToNewKeys); + } +} diff --git a/rules/order/src/Rector/AbstractConstantPropertyMethodOrderRector.php b/rules/order/src/Rector/AbstractConstantPropertyMethodOrderRector.php deleted file mode 100644 index 836394712c0..00000000000 --- a/rules/order/src/Rector/AbstractConstantPropertyMethodOrderRector.php +++ /dev/null @@ -1,41 +0,0 @@ -stmtOrder = $stmtOrder; - $this->stmtVisibilitySorter = $stmtVisibilitySorter; - } - - /** - * @param array $oldToNewKeys - */ - public function hasOrderChanged(array $oldToNewKeys): bool - { - return array_keys($oldToNewKeys) !== array_values($oldToNewKeys); - } -} diff --git a/rules/order/src/Rector/Class_/OrderClassConstantsByIntegerValueRector.php b/rules/order/src/Rector/Class_/OrderClassConstantsByIntegerValueRector.php index f633fb9b25c..cde6bf29885 100644 --- a/rules/order/src/Rector/Class_/OrderClassConstantsByIntegerValueRector.php +++ b/rules/order/src/Rector/Class_/OrderClassConstantsByIntegerValueRector.php @@ -8,7 +8,9 @@ use PhpParser\Node; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; -use Rector\Order\Rector\AbstractConstantPropertyMethodOrderRector; +use Rector\Core\Rector\AbstractRector; +use Rector\Order\StmtOrder; +use Rector\Order\StmtVisibilitySorter; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -17,8 +19,33 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; * * @see \Rector\Order\Tests\Rector\Class_\OrderClassConstantsByIntegerValueRector\OrderClassConstantsByIntegerValueRectorTest */ -final class OrderClassConstantsByIntegerValueRector extends AbstractConstantPropertyMethodOrderRector +final class OrderClassConstantsByIntegerValueRector extends AbstractRector { + /** + * @var \Rector\Order\Order\OrderChangeAnalyzer + */ + private $orderChangeAnalyzer; + + /** + * @var StmtOrder + */ + private $stmtOrder; + + /** + * @var StmtVisibilitySorter + */ + private $stmtVisibilitySorter; + + public function __construct( + \Rector\Order\Order\OrderChangeAnalyzer $orderChangeAnalyzer, + StmtOrder $stmtOrder, + StmtVisibilitySorter $stmtVisibilitySorter + ) { + $this->orderChangeAnalyzer = $orderChangeAnalyzer; + $this->stmtOrder = $stmtOrder; + $this->stmtVisibilitySorter = $stmtVisibilitySorter; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -46,8 +73,7 @@ class SomeClass const MODE_OFF = 2; } CODE_SAMPLE - ), - + ), ]); } @@ -75,7 +101,7 @@ CODE_SAMPLE asort($sortedClassConstConstsByValue); $oldToNewKeys = $this->stmtOrder->createOldToNewKeys($sortedClassConstConstsByValue, $classConstConstsByValue); - if (! $this->hasOrderChanged($oldToNewKeys)) { + if (! $this->orderChangeAnalyzer->hasOrderChanged($oldToNewKeys)) { return null; } diff --git a/rules/order/src/Rector/Class_/OrderConstantsByVisibilityRector.php b/rules/order/src/Rector/Class_/OrderConstantsByVisibilityRector.php index 5609be0d3d2..53af55dc66c 100644 --- a/rules/order/src/Rector/Class_/OrderConstantsByVisibilityRector.php +++ b/rules/order/src/Rector/Class_/OrderConstantsByVisibilityRector.php @@ -7,15 +7,42 @@ namespace Rector\Order\Rector\Class_; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassConst; -use Rector\Order\Rector\AbstractConstantPropertyMethodOrderRector; +use Rector\Core\Rector\AbstractRector; +use Rector\Order\StmtOrder; +use Rector\Order\StmtVisibilitySorter; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Order\Tests\Rector\Class_\OrderConstantsByVisibilityRector\OrderConstantsByVisibilityRectorTest */ -final class OrderConstantsByVisibilityRector extends AbstractConstantPropertyMethodOrderRector +final class OrderConstantsByVisibilityRector extends AbstractRector { + /** + * @var \Rector\Order\Order\OrderChangeAnalyzer + */ + private $orderChangeAnalyzer; + + /** + * @var StmtOrder + */ + private $stmtOrder; + + /** + * @var StmtVisibilitySorter + */ + private $stmtVisibilitySorter; + + public function __construct( + \Rector\Order\Order\OrderChangeAnalyzer $orderChangeAnalyzer, + StmtOrder $stmtOrder, + StmtVisibilitySorter $stmtVisibilitySorter + ) { + $this->orderChangeAnalyzer = $orderChangeAnalyzer; + $this->stmtOrder = $stmtOrder; + $this->stmtVisibilitySorter = $stmtVisibilitySorter; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Orders constants by visibility', [ @@ -61,7 +88,7 @@ CODE_SAMPLE $oldToNewKeys = $this->stmtOrder->createOldToNewKeys($classConstsInDesiredOrder, $currentClassConstsOrder); - if (! $this->hasOrderChanged($oldToNewKeys)) { + if (! $this->orderChangeAnalyzer->hasOrderChanged($oldToNewKeys)) { return null; } diff --git a/rules/order/src/Rector/Class_/OrderMethodsByVisibilityRector.php b/rules/order/src/Rector/Class_/OrderMethodsByVisibilityRector.php index 4c0e13e36fc..0712b0d30c6 100644 --- a/rules/order/src/Rector/Class_/OrderMethodsByVisibilityRector.php +++ b/rules/order/src/Rector/Class_/OrderMethodsByVisibilityRector.php @@ -9,15 +9,17 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Trait_; +use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; -use Rector\Order\Rector\AbstractConstantPropertyMethodOrderRector; +use Rector\Order\StmtOrder; +use Rector\Order\StmtVisibilitySorter; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Order\Tests\Rector\Class_\OrderMethodsByVisibilityRector\OrderMethodsByVisibilityRectorTest */ -final class OrderMethodsByVisibilityRector extends AbstractConstantPropertyMethodOrderRector +final class OrderMethodsByVisibilityRector extends AbstractRector { /** * @var string[] @@ -45,6 +47,31 @@ final class OrderMethodsByVisibilityRector extends AbstractConstantPropertyMetho MethodName::TEAR_DOWN, ]; + /** + * @var \Rector\Order\Order\OrderChangeAnalyzer + */ + private $orderChangeAnalyzer; + + /** + * @var StmtOrder + */ + private $stmtOrder; + + /** + * @var StmtVisibilitySorter + */ + private $stmtVisibilitySorter; + + public function __construct( + \Rector\Order\Order\OrderChangeAnalyzer $orderChangeAnalyzer, + StmtOrder $stmtOrder, + StmtVisibilitySorter $stmtVisibilitySorter + ) { + $this->orderChangeAnalyzer = $orderChangeAnalyzer; + $this->stmtOrder = $stmtOrder; + $this->stmtVisibilitySorter = $stmtVisibilitySorter; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Orders method by visibility', [ @@ -91,7 +118,7 @@ CODE_SAMPLE $oldToNewKeys = $this->stmtOrder->createOldToNewKeys($methodsInDesiredOrder, $currentMethodsOrder); // nothing to re-order - if (! $this->hasOrderChanged($oldToNewKeys)) { + if (! $this->orderChangeAnalyzer->hasOrderChanged($oldToNewKeys)) { return null; } diff --git a/rules/order/src/Rector/Class_/OrderPrivateMethodsByUseRector.php b/rules/order/src/Rector/Class_/OrderPrivateMethodsByUseRector.php index 56d0e6665ef..1673d17395e 100644 --- a/rules/order/src/Rector/Class_/OrderPrivateMethodsByUseRector.php +++ b/rules/order/src/Rector/Class_/OrderPrivateMethodsByUseRector.php @@ -11,7 +11,8 @@ use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Trait_; use Rector\Core\Exception\ShouldNotHappenException; -use Rector\Order\Rector\AbstractConstantPropertyMethodOrderRector; +use Rector\Core\Rector\AbstractRector; +use Rector\Order\StmtOrder; use Rector\Order\ValueObject\SortedClassMethodsAndOriginalClassMethods; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -19,13 +20,23 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Order\Tests\Rector\Class_\OrderPrivateMethodsByUseRector\OrderPrivateMethodsByUseRectorTest */ -final class OrderPrivateMethodsByUseRector extends AbstractConstantPropertyMethodOrderRector +final class OrderPrivateMethodsByUseRector extends AbstractRector { /** * @var int */ private const MAX_ATTEMPTS = 5; + /** + * @var StmtOrder + */ + private $stmtOrder; + + public function __construct(StmtOrder $stmtOrder) + { + $this->stmtOrder = $stmtOrder; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -69,8 +80,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/order/src/Rector/Class_/OrderPropertiesByVisibilityRector.php b/rules/order/src/Rector/Class_/OrderPropertiesByVisibilityRector.php index 8105a7c6f60..2bc6c618dd5 100644 --- a/rules/order/src/Rector/Class_/OrderPropertiesByVisibilityRector.php +++ b/rules/order/src/Rector/Class_/OrderPropertiesByVisibilityRector.php @@ -8,15 +8,42 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\Trait_; -use Rector\Order\Rector\AbstractConstantPropertyMethodOrderRector; +use Rector\Core\Rector\AbstractRector; +use Rector\Order\StmtOrder; +use Rector\Order\StmtVisibilitySorter; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Order\Tests\Rector\Class_\OrderPropertiesByVisibilityRector\OrderPropertiesByVisibilityRectorTest */ -final class OrderPropertiesByVisibilityRector extends AbstractConstantPropertyMethodOrderRector +final class OrderPropertiesByVisibilityRector extends AbstractRector { + /** + * @var \Rector\Order\Order\OrderChangeAnalyzer + */ + private $orderChangeAnalyzer; + + /** + * @var StmtOrder + */ + private $stmtOrder; + + /** + * @var StmtVisibilitySorter + */ + private $stmtVisibilitySorter; + + public function __construct( + \Rector\Order\Order\OrderChangeAnalyzer $orderChangeAnalyzer, + StmtOrder $stmtOrder, + StmtVisibilitySorter $stmtVisibilitySorter + ) { + $this->orderChangeAnalyzer = $orderChangeAnalyzer; + $this->stmtOrder = $stmtOrder; + $this->stmtVisibilitySorter = $stmtVisibilitySorter; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Orders properties by visibility', [ @@ -63,7 +90,7 @@ CODE_SAMPLE $oldToNewKeys = $this->stmtOrder->createOldToNewKeys($propertiesInDesiredOrder, $currentPropertiesOrder); // nothing to re-order - if (! $this->hasOrderChanged($oldToNewKeys)) { + if (! $this->orderChangeAnalyzer->hasOrderChanged($oldToNewKeys)) { return null; } diff --git a/rules/php-office/src/Rector/MethodCall/ChangeConditionalGetConditionRector.php b/rules/php-office/src/Rector/MethodCall/ChangeConditionalGetConditionRector.php index 32797e9f731..29af8664ea1 100644 --- a/rules/php-office/src/Rector/MethodCall/ChangeConditionalGetConditionRector.php +++ b/rules/php-office/src/Rector/MethodCall/ChangeConditionalGetConditionRector.php @@ -50,8 +50,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php-office/src/Rector/MethodCall/ChangeConditionalSetConditionRector.php b/rules/php-office/src/Rector/MethodCall/ChangeConditionalSetConditionRector.php index bdacfa45dee..f5b838e5016 100644 --- a/rules/php-office/src/Rector/MethodCall/ChangeConditionalSetConditionRector.php +++ b/rules/php-office/src/Rector/MethodCall/ChangeConditionalSetConditionRector.php @@ -48,8 +48,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php-office/src/Rector/MethodCall/ChangeDuplicateStyleArrayToApplyFromArrayRector.php b/rules/php-office/src/Rector/MethodCall/ChangeDuplicateStyleArrayToApplyFromArrayRector.php index 92bf316b482..91a16cb624d 100644 --- a/rules/php-office/src/Rector/MethodCall/ChangeDuplicateStyleArrayToApplyFromArrayRector.php +++ b/rules/php-office/src/Rector/MethodCall/ChangeDuplicateStyleArrayToApplyFromArrayRector.php @@ -46,8 +46,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php-office/src/Rector/MethodCall/RemoveSetTempDirOnExcelWriterRector.php b/rules/php-office/src/Rector/MethodCall/RemoveSetTempDirOnExcelWriterRector.php index 0841007d7c9..f71be716413 100644 --- a/rules/php-office/src/Rector/MethodCall/RemoveSetTempDirOnExcelWriterRector.php +++ b/rules/php-office/src/Rector/MethodCall/RemoveSetTempDirOnExcelWriterRector.php @@ -44,8 +44,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php-office/src/Rector/StaticCall/ChangeDataTypeForValueRector.php b/rules/php-office/src/Rector/StaticCall/ChangeDataTypeForValueRector.php index 0f9fb64e4c4..7c6cd9a22ff 100644 --- a/rules/php-office/src/Rector/StaticCall/ChangeDataTypeForValueRector.php +++ b/rules/php-office/src/Rector/StaticCall/ChangeDataTypeForValueRector.php @@ -43,8 +43,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php-office/src/Rector/StaticCall/ChangeSearchLocationToRegisterReaderRector.php b/rules/php-office/src/Rector/StaticCall/ChangeSearchLocationToRegisterReaderRector.php index bad21c50d11..8e3ab10ef5b 100644 --- a/rules/php-office/src/Rector/StaticCall/ChangeSearchLocationToRegisterReaderRector.php +++ b/rules/php-office/src/Rector/StaticCall/ChangeSearchLocationToRegisterReaderRector.php @@ -44,8 +44,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php-spec-to-phpunit/src/Rector/FileNode/RenameSpecFileToTestFileRector.php b/rules/php-spec-to-phpunit/src/Rector/FileNode/RenameSpecFileToTestFileRector.php index 00c045061e1..7c2ea773839 100644 --- a/rules/php-spec-to-phpunit/src/Rector/FileNode/RenameSpecFileToTestFileRector.php +++ b/rules/php-spec-to-phpunit/src/Rector/FileNode/RenameSpecFileToTestFileRector.php @@ -44,8 +44,7 @@ CODE_SAMPLE <<<'CODE_SAMPLE' // tests/SomeTest.php CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php53/src/Rector/AssignRef/ClearReturnNewByReferenceRector.php b/rules/php53/src/Rector/AssignRef/ClearReturnNewByReferenceRector.php index 4793630bdd5..c143351f7d9 100644 --- a/rules/php53/src/Rector/AssignRef/ClearReturnNewByReferenceRector.php +++ b/rules/php53/src/Rector/AssignRef/ClearReturnNewByReferenceRector.php @@ -33,8 +33,7 @@ CODE_SAMPLE <<<'CODE_SAMPLE' $assign = new Value; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php55/src/Rector/FuncCall/PregReplaceEModifierRector.php b/rules/php55/src/Rector/FuncCall/PregReplaceEModifierRector.php index 285c3c89c85..a4e157947f4 100644 --- a/rules/php55/src/Rector/FuncCall/PregReplaceEModifierRector.php +++ b/rules/php55/src/Rector/FuncCall/PregReplaceEModifierRector.php @@ -66,8 +66,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php70/src/Rector/Break_/BreakNotInLoopOrSwitchToReturnRector.php b/rules/php70/src/Rector/Break_/BreakNotInLoopOrSwitchToReturnRector.php index f351fbc9b5d..f1dbb6a8954 100644 --- a/rules/php70/src/Rector/Break_/BreakNotInLoopOrSwitchToReturnRector.php +++ b/rules/php70/src/Rector/Break_/BreakNotInLoopOrSwitchToReturnRector.php @@ -64,8 +64,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php70/src/Rector/FuncCall/RenameMktimeWithoutArgsToTimeRector.php b/rules/php70/src/Rector/FuncCall/RenameMktimeWithoutArgsToTimeRector.php index ca305ffe7a0..4fbf2d4bbcf 100644 --- a/rules/php70/src/Rector/FuncCall/RenameMktimeWithoutArgsToTimeRector.php +++ b/rules/php70/src/Rector/FuncCall/RenameMktimeWithoutArgsToTimeRector.php @@ -44,8 +44,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php70/src/Rector/If_/IfToSpaceshipRector.php b/rules/php70/src/Rector/If_/IfToSpaceshipRector.php index 88b45fd4b14..b6b43e384d4 100644 --- a/rules/php70/src/Rector/If_/IfToSpaceshipRector.php +++ b/rules/php70/src/Rector/If_/IfToSpaceshipRector.php @@ -93,8 +93,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php70/src/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php b/rules/php70/src/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php index 8095462838e..1c3d2e056a2 100644 --- a/rules/php70/src/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php +++ b/rules/php70/src/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php @@ -71,8 +71,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php b/rules/php70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php index df6965ed6bb..8f9246dcee4 100644 --- a/rules/php70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php +++ b/rules/php70/src/Rector/StaticCall/StaticCallOnNonStaticToInstanceCallRector.php @@ -95,8 +95,7 @@ class Another } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php70/src/Rector/Switch_/ReduceMultipleDefaultSwitchRector.php b/rules/php70/src/Rector/Switch_/ReduceMultipleDefaultSwitchRector.php index c3089c8d614..21952a908e2 100644 --- a/rules/php70/src/Rector/Switch_/ReduceMultipleDefaultSwitchRector.php +++ b/rules/php70/src/Rector/Switch_/ReduceMultipleDefaultSwitchRector.php @@ -45,8 +45,7 @@ switch ($expr) { break; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php70/src/Rector/Ternary/TernaryToSpaceshipRector.php b/rules/php70/src/Rector/Ternary/TernaryToSpaceshipRector.php index d7701602aeb..cd48c51c2c3 100644 --- a/rules/php70/src/Rector/Ternary/TernaryToSpaceshipRector.php +++ b/rules/php70/src/Rector/Ternary/TernaryToSpaceshipRector.php @@ -38,8 +38,7 @@ function order_func($a, $b) { return $a <=> $b; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php70/src/Rector/Variable/WrapVariableVariableNameInCurlyBracesRector.php b/rules/php70/src/Rector/Variable/WrapVariableVariableNameInCurlyBracesRector.php index 839190459de..f16eaa5fece 100644 --- a/rules/php70/src/Rector/Variable/WrapVariableVariableNameInCurlyBracesRector.php +++ b/rules/php70/src/Rector/Variable/WrapVariableVariableNameInCurlyBracesRector.php @@ -36,8 +36,7 @@ function run($foo) global ${$foo->bar}; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php72/config/config.php b/rules/php72/config/config.php new file mode 100644 index 00000000000..cd221645f04 --- /dev/null +++ b/rules/php72/config/config.php @@ -0,0 +1,17 @@ +services(); + + $services->defaults() + ->public() + ->autowire() + ->autoconfigure(); + + $services->load('Rector\Php72\\', __DIR__ . '/../src') + ->exclude([__DIR__ . '/../src/Rector']); +}; diff --git a/rules/php72/src/Contract/ConvertToAnonymousFunctionRectorInterface.php b/rules/php72/src/Contract/ConvertToAnonymousFunctionRectorInterface.php deleted file mode 100644 index 6eade241723..00000000000 --- a/rules/php72/src/Contract/ConvertToAnonymousFunctionRectorInterface.php +++ /dev/null @@ -1,34 +0,0 @@ -nodeNameResolver = $nodeNameResolver; + $this->betterNodeFinder = $betterNodeFinder; + } + + /** + * @param Param[] $params + * @param Stmt[] $stmts + * @param Identifier|Name|NullableType|UnionType|null $returnType + */ + public function create(array $params, array $stmts, ?Node $returnType): Closure + { + $useVariables = $this->createUseVariablesFromParams($stmts, $params); + + $anonymousFunctionNode = new Closure(); + $anonymousFunctionNode->params = $params; + + foreach ($useVariables as $useVariable) { + $anonymousFunctionNode->uses[] = new ClosureUse($useVariable); + } + + if ($returnType instanceof Node) { + $anonymousFunctionNode->returnType = $returnType; + } + + $anonymousFunctionNode->stmts = $stmts; + return $anonymousFunctionNode; + } + + /** + * @param Node[] $nodes + * @param Param[] $paramNodes + * @return Variable[] + */ + private function createUseVariablesFromParams(array $nodes, array $paramNodes): array + { + $paramNames = []; + foreach ($paramNodes as $paramNode) { + $paramNames[] = $this->nodeNameResolver->getName($paramNode); + } + + $variableNodes = $this->betterNodeFinder->findInstanceOf($nodes, Variable::class); + + /** @var Variable[] $filteredVariables */ + $filteredVariables = []; + $alreadyAssignedVariables = []; + foreach ($variableNodes as $variableNode) { + // "$this" is allowed + if ($this->nodeNameResolver-> isName($variableNode, 'this')) { + continue; + } + + $variableName = $this->nodeNameResolver->getName($variableNode); + if ($variableName === null) { + continue; + } + + if (in_array($variableName, $paramNames, true)) { + continue; + } + + $parentNode = $variableNode->getAttribute(AttributeKey::PARENT_NODE); + if ($parentNode instanceof Assign) { + $alreadyAssignedVariables[] = $variableName; + } + + if ($this->nodeNameResolver->isNames($variableNode, $alreadyAssignedVariables)) { + continue; + } + + $filteredVariables[$variableName] = $variableNode; + } + + return $filteredVariables; + } +} diff --git a/rules/php72/src/Rector/FuncCall/AbstractConvertToAnonymousFunctionRector.php b/rules/php72/src/Rector/FuncCall/AbstractConvertToAnonymousFunctionRector.php deleted file mode 100644 index 7acdc32863b..00000000000 --- a/rules/php72/src/Rector/FuncCall/AbstractConvertToAnonymousFunctionRector.php +++ /dev/null @@ -1,94 +0,0 @@ -shouldSkip($node)) { - return null; - } - - $body = $this->getBody($node); - $parameters = $this->getParameters($node); - $useVariables = $this->resolveUseVariables($body, $parameters); - - $anonymousFunctionNode = new Closure(); - $anonymousFunctionNode->params = $parameters; - - foreach ($useVariables as $useVariable) { - $anonymousFunctionNode->uses[] = new ClosureUse($useVariable); - } - - $anonymousFunctionNode->returnType = $this->getReturnType($node); - - if ($body !== []) { - $anonymousFunctionNode->stmts = $body; - } - - return $anonymousFunctionNode; - } - - /** - * @param Node[] $nodes - * @param Param[] $paramNodes - * @return Variable[] - */ - private function resolveUseVariables(array $nodes, array $paramNodes): array - { - $paramNames = []; - foreach ($paramNodes as $paramNode) { - $paramNames[] = $this->getName($paramNode); - } - - $variableNodes = $this->betterNodeFinder->findInstanceOf($nodes, Variable::class); - - /** @var Variable[] $filteredVariables */ - $filteredVariables = []; - $alreadyAssignedVariables = []; - foreach ($variableNodes as $variableNode) { - // "$this" is allowed - if ($this->isName($variableNode, 'this')) { - continue; - } - - $variableName = $this->getName($variableNode); - if ($variableName === null) { - continue; - } - - if (in_array($variableName, $paramNames, true)) { - continue; - } - - $parentNode = $variableNode->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode instanceof Assign) { - $alreadyAssignedVariables[] = $variableName; - } - - if ($this->isNames($variableNode, $alreadyAssignedVariables)) { - continue; - } - - $filteredVariables[$variableName] = $variableNode; - } - - return $filteredVariables; - } -} diff --git a/rules/php72/src/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php b/rules/php72/src/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php index a281a787f93..ebb4dbdc366 100644 --- a/rules/php72/src/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php +++ b/rules/php72/src/Rector/FuncCall/CreateFunctionToAnonymousFunctionRector.php @@ -11,17 +11,16 @@ use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; -use PhpParser\Node\Identifier; use PhpParser\Node\Name; -use PhpParser\Node\NullableType; use PhpParser\Node\Param; use PhpParser\Node\Scalar\Encapsed; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Expression; -use PhpParser\Node\UnionType; use Rector\Core\Exception\ShouldNotHappenException; use Rector\Core\PhpParser\Parser\InlineCodeParser; +use Rector\Core\Rector\AbstractRector; +use Rector\Php72\NodeFactory\AnonymousFunctionFactory; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -31,16 +30,24 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; * * @see \Rector\Php72\Tests\Rector\FuncCall\CreateFunctionToAnonymousFunctionRector\CreateFunctionToAnonymousFunctionRectorTest */ -final class CreateFunctionToAnonymousFunctionRector extends AbstractConvertToAnonymousFunctionRector +final class CreateFunctionToAnonymousFunctionRector extends AbstractRector { /** * @var InlineCodeParser */ private $inlineCodeParser; - public function __construct(InlineCodeParser $inlineCodeParser) - { + /** + * @var AnonymousFunctionFactory + */ + private $anonymousFunctionFactory; + + public function __construct( + InlineCodeParser $inlineCodeParser, + AnonymousFunctionFactory $anonymousFunctionFactory + ) { $this->inlineCodeParser = $inlineCodeParser; + $this->anonymousFunctionFactory = $anonymousFunctionFactory; } public function getRuleDefinition(): RuleDefinition @@ -70,8 +77,7 @@ class ClassWithCreateFunction } } CODE_SAMPLE - ), - + ), ]); } @@ -85,42 +91,25 @@ CODE_SAMPLE /** * @param FuncCall $node + * @return Closure|null */ - public function shouldSkip(Node $node): bool + public function refactor(Node $node): ?Node { - return ! $this->isName($node, 'create_function'); - } + if (! $this->isName($node, 'create_function')) { + return null; + } - /** - * @param FuncCall $node - * @return Param[] - */ - public function getParameters(Node $node): array - { - return $this->parseStringToParameters($node->args[0]->value); - } + $params = $this->createParamsFromString($node->args[0]->value); + $stmts = $this->parseStringToBody($node->args[1]->value); + $returnType = null; - /** - * @return Identifier|Name|NullableType|UnionType|null - */ - public function getReturnType(Node $node): ?Node - { - return null; - } - - /** - * @param FuncCall $node - * @return Stmt[] - */ - public function getBody(Node $node): array - { - return $this->parseStringToBody($node->args[1]->value); + return $this->anonymousFunctionFactory->create($params, $stmts, $returnType); } /** * @return Param[] */ - private function parseStringToParameters(Expr $expr): array + private function createParamsFromString(Expr $expr): array { $content = $this->inlineCodeParser->stringify($expr); $content = 'query, $result); $data = $result; CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php72/src/Rector/FuncCall/StringsAssertNakedRector.php b/rules/php72/src/Rector/FuncCall/StringsAssertNakedRector.php index 28fadb9dc35..5944ae2acac 100644 --- a/rules/php72/src/Rector/FuncCall/StringsAssertNakedRector.php +++ b/rules/php72/src/Rector/FuncCall/StringsAssertNakedRector.php @@ -52,8 +52,7 @@ function nakedAssert() assert(true === true); } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php73/src/Rector/String_/SensitiveHereNowDocRector.php b/rules/php73/src/Rector/String_/SensitiveHereNowDocRector.php index 2a0b42e0cf5..1251ddaa70a 100644 --- a/rules/php73/src/Rector/String_/SensitiveHereNowDocRector.php +++ b/rules/php73/src/Rector/String_/SensitiveHereNowDocRector.php @@ -45,8 +45,7 @@ $value = << 1000000, ] - ), - + ), ]); } diff --git a/rules/php74/src/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php b/rules/php74/src/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php index d4e5e06d900..e3ac66b07a7 100644 --- a/rules/php74/src/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php +++ b/rules/php74/src/Rector/Property/RestoreDefaultNullToNullableTypePropertyRector.php @@ -42,8 +42,7 @@ class SomeClass public ?string $name = null; } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php74/src/Rector/StaticCall/ExportToReflectionFunctionRector.php b/rules/php74/src/Rector/StaticCall/ExportToReflectionFunctionRector.php index aa1d284adc6..9a20a2c03f2 100644 --- a/rules/php74/src/Rector/StaticCall/ExportToReflectionFunctionRector.php +++ b/rules/php74/src/Rector/StaticCall/ExportToReflectionFunctionRector.php @@ -36,8 +36,7 @@ CODE_SAMPLE $reflectionFunction = new ReflectionFunction('foo'); $reflectionFunctionAsString = (string) new ReflectionFunction('foo'); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php80/src/Rector/Class_/StringableForToStringRector.php b/rules/php80/src/Rector/Class_/StringableForToStringRector.php index ab38cc4c53e..7eda94389ae 100644 --- a/rules/php80/src/Rector/Class_/StringableForToStringRector.php +++ b/rules/php80/src/Rector/Class_/StringableForToStringRector.php @@ -62,8 +62,7 @@ class SomeClass implements Stringable } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php80/src/Rector/FuncCall/ClassOnObjectRector.php b/rules/php80/src/Rector/FuncCall/ClassOnObjectRector.php index ee038233ec3..ac3f70dabb8 100644 --- a/rules/php80/src/Rector/FuncCall/ClassOnObjectRector.php +++ b/rules/php80/src/Rector/FuncCall/ClassOnObjectRector.php @@ -45,8 +45,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php80/src/Rector/FuncCall/TokenGetAllToObjectRector.php b/rules/php80/src/Rector/FuncCall/TokenGetAllToObjectRector.php index 01ac854bb1f..e5899f98bb3 100644 --- a/rules/php80/src/Rector/FuncCall/TokenGetAllToObjectRector.php +++ b/rules/php80/src/Rector/FuncCall/TokenGetAllToObjectRector.php @@ -75,8 +75,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php80/src/Rector/Identical/StrStartsWithRector.php b/rules/php80/src/Rector/Identical/StrStartsWithRector.php index e1b5ead6638..b72749eb5c0 100644 --- a/rules/php80/src/Rector/Identical/StrStartsWithRector.php +++ b/rules/php80/src/Rector/Identical/StrStartsWithRector.php @@ -65,8 +65,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php80/src/Rector/If_/NullsafeOperatorRector.php b/rules/php80/src/Rector/If_/NullsafeOperatorRector.php index 74d5f4e4099..f82ae91a884 100644 --- a/rules/php80/src/Rector/If_/NullsafeOperatorRector.php +++ b/rules/php80/src/Rector/If_/NullsafeOperatorRector.php @@ -78,8 +78,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php80/src/Rector/NotIdentical/StrContainsRector.php b/rules/php80/src/Rector/NotIdentical/StrContainsRector.php index 07baea36e95..263d9f44cf8 100644 --- a/rules/php80/src/Rector/NotIdentical/StrContainsRector.php +++ b/rules/php80/src/Rector/NotIdentical/StrContainsRector.php @@ -51,8 +51,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/php80/src/Rector/Ternary/GetDebugTypeRector.php b/rules/php80/src/Rector/Ternary/GetDebugTypeRector.php index 2877cb19518..d7c9b1a1fa3 100644 --- a/rules/php80/src/Rector/Ternary/GetDebugTypeRector.php +++ b/rules/php80/src/Rector/Ternary/GetDebugTypeRector.php @@ -43,8 +43,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/phpunit-symfony/src/Rector/StaticCall/AddMessageToEqualsResponseCodeRector.php b/rules/phpunit-symfony/src/Rector/StaticCall/AddMessageToEqualsResponseCodeRector.php index d1f920dfee8..3451cf72039 100644 --- a/rules/phpunit-symfony/src/Rector/StaticCall/AddMessageToEqualsResponseCodeRector.php +++ b/rules/phpunit-symfony/src/Rector/StaticCall/AddMessageToEqualsResponseCodeRector.php @@ -59,8 +59,7 @@ final class SomeClassTest extends TestCase } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php b/rules/phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php index c945a044775..f3ead0d8fa3 100644 --- a/rules/phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php +++ b/rules/phpunit/src/Rector/ClassMethod/AddDoesNotPerformAssertionToNonAssertingTestRector.php @@ -106,8 +106,7 @@ class SomeClass extends TestCase } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/Class_/AddProphecyTraitRector.php b/rules/phpunit/src/Rector/Class_/AddProphecyTraitRector.php index 5cc62b694ff..0d7725f67b5 100644 --- a/rules/phpunit/src/Rector/Class_/AddProphecyTraitRector.php +++ b/rules/phpunit/src/Rector/Class_/AddProphecyTraitRector.php @@ -84,8 +84,7 @@ final class ExampleTest extends TestCase } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php b/rules/phpunit/src/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php index 7565f9eb116..23e5d0bf71b 100644 --- a/rules/phpunit/src/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php +++ b/rules/phpunit/src/Rector/Class_/ConstructClassMethodToSetUpTestCaseRector.php @@ -87,8 +87,7 @@ final class SomeTest extends TestCase } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/Class_/RemoveDataProviderTestPrefixRector.php b/rules/phpunit/src/Rector/Class_/RemoveDataProviderTestPrefixRector.php index e0bc18e040d..5686a9ce433 100644 --- a/rules/phpunit/src/Rector/Class_/RemoveDataProviderTestPrefixRector.php +++ b/rules/phpunit/src/Rector/Class_/RemoveDataProviderTestPrefixRector.php @@ -77,8 +77,7 @@ class SomeClass extends PHPUnit\Framework\TestCase } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/Class_/TestListenerToHooksRector.php b/rules/phpunit/src/Rector/Class_/TestListenerToHooksRector.php index a59ad558740..a442d211a2c 100644 --- a/rules/phpunit/src/Rector/Class_/TestListenerToHooksRector.php +++ b/rules/phpunit/src/Rector/Class_/TestListenerToHooksRector.php @@ -114,8 +114,7 @@ final class BeforeListHook implements \PHPUnit\Runner\BeforeTestHook, \PHPUnit\R } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/Foreach_/SimplifyForeachInstanceOfRector.php b/rules/phpunit/src/Rector/Foreach_/SimplifyForeachInstanceOfRector.php index 5b128df8ca9..000573abe16 100644 --- a/rules/phpunit/src/Rector/Foreach_/SimplifyForeachInstanceOfRector.php +++ b/rules/phpunit/src/Rector/Foreach_/SimplifyForeachInstanceOfRector.php @@ -43,8 +43,7 @@ foreach ($foos as $foo) { CODE_SAMPLE , '$this->assertContainsOnlyInstancesOf(\SplFileInfo::class, $foos);' - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/MethodCall/AssertCompareToSpecificMethodRector.php b/rules/phpunit/src/Rector/MethodCall/AssertCompareToSpecificMethodRector.php index a92b34bb766..9a99798531b 100644 --- a/rules/phpunit/src/Rector/MethodCall/AssertCompareToSpecificMethodRector.php +++ b/rules/phpunit/src/Rector/MethodCall/AssertCompareToSpecificMethodRector.php @@ -65,8 +65,7 @@ final class AssertCompareToSpecificMethodRector extends AbstractRector new CodeSample( '$this->assertNotEquals(get_class($value), stdClass::class);', '$this->assertNotInstanceOf(stdClass::class, $value);' - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/MethodCall/AssertIssetToSpecificMethodRector.php b/rules/phpunit/src/Rector/MethodCall/AssertIssetToSpecificMethodRector.php index eccaa0e2983..4b39146319c 100644 --- a/rules/phpunit/src/Rector/MethodCall/AssertIssetToSpecificMethodRector.php +++ b/rules/phpunit/src/Rector/MethodCall/AssertIssetToSpecificMethodRector.php @@ -60,8 +60,7 @@ final class AssertIssetToSpecificMethodRector extends AbstractRector new CodeSample( '$this->assertFalse(isset($anything["foo"]), "message");', '$this->assertArrayNotHasKey("foo", $anything, "message");' - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/MethodCall/AssertSameTrueFalseToAssertTrueFalseRector.php b/rules/phpunit/src/Rector/MethodCall/AssertSameTrueFalseToAssertTrueFalseRector.php index 6682a24b679..9ecab4ba93e 100644 --- a/rules/phpunit/src/Rector/MethodCall/AssertSameTrueFalseToAssertTrueFalseRector.php +++ b/rules/phpunit/src/Rector/MethodCall/AssertSameTrueFalseToAssertTrueFalseRector.php @@ -67,8 +67,7 @@ final class SomeTest extends TestCase } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/MethodCall/CreateMockToCreateStubRector.php b/rules/phpunit/src/Rector/MethodCall/CreateMockToCreateStubRector.php index c1bbcca84f4..d470c1a57d8 100644 --- a/rules/phpunit/src/Rector/MethodCall/CreateMockToCreateStubRector.php +++ b/rules/phpunit/src/Rector/MethodCall/CreateMockToCreateStubRector.php @@ -89,8 +89,7 @@ class MyTest extends TestCase } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/phpunit/src/Rector/MethodCall/UseSpecificWillMethodRector.php b/rules/phpunit/src/Rector/MethodCall/UseSpecificWillMethodRector.php index ad3bcc2cfbc..f7d5f5f9160 100644 --- a/rules/phpunit/src/Rector/MethodCall/UseSpecificWillMethodRector.php +++ b/rules/phpunit/src/Rector/MethodCall/UseSpecificWillMethodRector.php @@ -76,8 +76,7 @@ class SomeClass extends PHPUnit\Framework\TestCase } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/privatization/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php b/rules/privatization/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php index 8f14f9e34c6..ff14e3e4b21 100644 --- a/rules/privatization/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php +++ b/rules/privatization/src/Rector/ClassConst/PrivatizeLocalClassConstantRector.php @@ -79,8 +79,7 @@ class ClassWithConstantUsedOnlyHere } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/privatization/src/Rector/ClassMethod/ChangeGlobalVariablesToPropertiesRector.php b/rules/privatization/src/Rector/ClassMethod/ChangeGlobalVariablesToPropertiesRector.php index 23ef8523f89..3b81d80fc9d 100644 --- a/rules/privatization/src/Rector/ClassMethod/ChangeGlobalVariablesToPropertiesRector.php +++ b/rules/privatization/src/Rector/ClassMethod/ChangeGlobalVariablesToPropertiesRector.php @@ -77,8 +77,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/privatization/src/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector.php b/rules/privatization/src/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector.php index 7295f243867..72dad5a91ce 100644 --- a/rules/privatization/src/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector.php +++ b/rules/privatization/src/Rector/ClassMethod/MakeOnlyUsedByChildrenProtectedRector.php @@ -81,8 +81,7 @@ class ChildClass extends AbstractSomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/privatization/src/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php b/rules/privatization/src/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php index 47ebea93add..4c05022092a 100644 --- a/rules/privatization/src/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php +++ b/rules/privatization/src/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php @@ -52,8 +52,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/privatization/src/Rector/Class_/ChangeLocalPropertyToVariableRector.php b/rules/privatization/src/Rector/Class_/ChangeLocalPropertyToVariableRector.php index 599699c923e..98551cb9817 100644 --- a/rules/privatization/src/Rector/Class_/ChangeLocalPropertyToVariableRector.php +++ b/rules/privatization/src/Rector/Class_/ChangeLocalPropertyToVariableRector.php @@ -87,8 +87,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/privatization/src/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php b/rules/privatization/src/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php index f85fc42d8a0..f6f7d8e491e 100644 --- a/rules/privatization/src/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php +++ b/rules/privatization/src/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php @@ -95,8 +95,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/privatization/src/Rector/Class_/MakeUnusedClassesWithChildrenAbstractRector.php b/rules/privatization/src/Rector/Class_/MakeUnusedClassesWithChildrenAbstractRector.php index 5605b6d4991..33ce2b6e66e 100644 --- a/rules/privatization/src/Rector/Class_/MakeUnusedClassesWithChildrenAbstractRector.php +++ b/rules/privatization/src/Rector/Class_/MakeUnusedClassesWithChildrenAbstractRector.php @@ -40,8 +40,7 @@ abstract class PossibleAbstractClass { } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/privatization/src/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php b/rules/privatization/src/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php index eecc30d3773..fc4daf162b2 100644 --- a/rules/privatization/src/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php +++ b/rules/privatization/src/Rector/MethodCall/PrivatizeLocalGetterToPropertyRector.php @@ -59,8 +59,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/privatization/src/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.php b/rules/privatization/src/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.php index b81bab1c097..41bbf278c07 100644 --- a/rules/privatization/src/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.php +++ b/rules/privatization/src/Rector/Property/ChangeReadOnlyPropertyWithDefaultValueToConstantRector.php @@ -92,8 +92,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/removing-static/src/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php b/rules/removing-static/src/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php index f34ed1d73fc..9cd141bb714 100644 --- a/rules/removing-static/src/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php +++ b/rules/removing-static/src/Rector/ClassMethod/LocallyCalledStaticMethodToNonStaticRector.php @@ -66,8 +66,7 @@ class SomeClass } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/renaming/src/Rector/ClassConstFetch/RenameClassConstFetchRector.php b/rules/renaming/src/Rector/ClassConstFetch/RenameClassConstFetchRector.php index d56fa80a86c..fcfb02befd8 100644 --- a/rules/renaming/src/Rector/ClassConstFetch/RenameClassConstFetchRector.php +++ b/rules/renaming/src/Rector/ClassConstFetch/RenameClassConstFetchRector.php @@ -56,8 +56,7 @@ $value = DifferentClass::NEW_CONSTANT; CODE_SAMPLE , $configuration - ), - + ), ]); } diff --git a/rules/sensio/src/Rector/ClassMethod/ReplaceSensioRouteAnnotationWithSymfonyRector.php b/rules/sensio/src/Rector/ClassMethod/ReplaceSensioRouteAnnotationWithSymfonyRector.php index e427eacc9a7..d18315b0892 100644 --- a/rules/sensio/src/Rector/ClassMethod/ReplaceSensioRouteAnnotationWithSymfonyRector.php +++ b/rules/sensio/src/Rector/ClassMethod/ReplaceSensioRouteAnnotationWithSymfonyRector.php @@ -65,8 +65,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/symfony/src/Rector/ClassMethod/ActionSuffixRemoverRector.php b/rules/symfony/src/Rector/ClassMethod/ActionSuffixRemoverRector.php index df6da7cf8ef..b99e87439a1 100644 --- a/rules/symfony/src/Rector/ClassMethod/ActionSuffixRemoverRector.php +++ b/rules/symfony/src/Rector/ClassMethod/ActionSuffixRemoverRector.php @@ -58,8 +58,7 @@ class SomeController } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/symfony/src/Rector/ClassMethod/NormalizeAutowireMethodNamingRector.php b/rules/symfony/src/Rector/ClassMethod/NormalizeAutowireMethodNamingRector.php index 435ef4f6f5d..86669fe8e3d 100644 --- a/rules/symfony/src/Rector/ClassMethod/NormalizeAutowireMethodNamingRector.php +++ b/rules/symfony/src/Rector/ClassMethod/NormalizeAutowireMethodNamingRector.php @@ -43,8 +43,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/symfony2/src/Rector/MethodCall/AddFlashRector.php b/rules/symfony2/src/Rector/MethodCall/AddFlashRector.php index e08e753ea34..ab845d4e226 100644 --- a/rules/symfony2/src/Rector/MethodCall/AddFlashRector.php +++ b/rules/symfony2/src/Rector/MethodCall/AddFlashRector.php @@ -53,8 +53,7 @@ class SomeController extends Controller } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/symfony2/src/Rector/MethodCall/RedirectToRouteRector.php b/rules/symfony2/src/Rector/MethodCall/RedirectToRouteRector.php index 9a64e4bb655..25e6a4b8fd0 100644 --- a/rules/symfony2/src/Rector/MethodCall/RedirectToRouteRector.php +++ b/rules/symfony2/src/Rector/MethodCall/RedirectToRouteRector.php @@ -24,8 +24,7 @@ final class RedirectToRouteRector extends AbstractRector new CodeSample( '$this->redirect($this->generateUrl("homepage"));', '$this->redirectToRoute("homepage");' - ), - + ), ]); } diff --git a/rules/symfony3/src/NodeAnalyzer/FormAddMethodCallAnalyzer.php b/rules/symfony3/src/NodeAnalyzer/FormAddMethodCallAnalyzer.php new file mode 100644 index 00000000000..2c69f1faa2b --- /dev/null +++ b/rules/symfony3/src/NodeAnalyzer/FormAddMethodCallAnalyzer.php @@ -0,0 +1,57 @@ +formObjectTypes = [ + new ObjectType('Symfony\Component\Form\FormBuilderInterface'), + new ObjectType('Symfony\Component\Form\FormInterface'), + ]; + + $this->nodeTypeResolver = $nodeTypeResolver; + $this->nodeNameResolver = $nodeNameResolver; + } + + public function matches(MethodCall $methodCall): bool + { + if (! $this->nodeTypeResolver->isObjectTypes($methodCall->var, $this->formObjectTypes)) { + return false; + } + + if (! $this->nodeNameResolver->isName($methodCall->name, 'add')) { + return false; + } + + // just one argument + if (! isset($methodCall->args[1])) { + return false; + } + + return $methodCall->args[1]->value !== null; + } +} diff --git a/rules/symfony3/src/NodeAnalyzer/FormCollectionAnalyzer.php b/rules/symfony3/src/NodeAnalyzer/FormCollectionAnalyzer.php new file mode 100644 index 00000000000..c8f54a3619f --- /dev/null +++ b/rules/symfony3/src/NodeAnalyzer/FormCollectionAnalyzer.php @@ -0,0 +1,46 @@ +valueResolver = $valueResolver; + $this->nodeNameResolver = $nodeNameResolver; + } + + public function isCollectionType(MethodCall $methodCall): bool + { + $typeValue = $methodCall->args[1]->value; + if (! $typeValue instanceof ClassConstFetch) { + return $this->valueResolver->isValue($typeValue, 'collection'); + } + + if (! $this->nodeNameResolver->isName( + $typeValue->class, + 'Symfony\Component\Form\Extension\Core\Type\CollectionType' + )) { + return $this->valueResolver->isValue($typeValue, 'collection'); + } + + return true; + } +} diff --git a/rules/symfony3/src/NodeAnalyzer/FormOptionsArrayMatcher.php b/rules/symfony3/src/NodeAnalyzer/FormOptionsArrayMatcher.php new file mode 100644 index 00000000000..ec7aae6c611 --- /dev/null +++ b/rules/symfony3/src/NodeAnalyzer/FormOptionsArrayMatcher.php @@ -0,0 +1,25 @@ +args[2])) { + return null; + } + + $optionsArray = $methodCall->args[2]->value; + if (! $optionsArray instanceof Array_) { + return null; + } + + return $optionsArray; + } +} diff --git a/rules/symfony3/src/Rector/ClassConstFetch/ConsoleExceptionToErrorEventConstantRector.php b/rules/symfony3/src/Rector/ClassConstFetch/ConsoleExceptionToErrorEventConstantRector.php index cadba86d581..b2ea922e9a5 100644 --- a/rules/symfony3/src/Rector/ClassConstFetch/ConsoleExceptionToErrorEventConstantRector.php +++ b/rules/symfony3/src/Rector/ClassConstFetch/ConsoleExceptionToErrorEventConstantRector.php @@ -40,8 +40,7 @@ final class ConsoleExceptionToErrorEventConstantRector extends AbstractRector new CodeSample( 'Symfony\Component\Console\ConsoleEvents::EXCEPTION', 'Symfony\Component\Console\ConsoleEvents::ERROR' - ), - + ), ]); } diff --git a/rules/symfony3/src/Rector/ClassMethod/MergeMethodAnnotationToRouteAnnotationRector.php b/rules/symfony3/src/Rector/ClassMethod/MergeMethodAnnotationToRouteAnnotationRector.php index d4998e5c407..e823324fd0b 100644 --- a/rules/symfony3/src/Rector/ClassMethod/MergeMethodAnnotationToRouteAnnotationRector.php +++ b/rules/symfony3/src/Rector/ClassMethod/MergeMethodAnnotationToRouteAnnotationRector.php @@ -57,8 +57,7 @@ class DefaultController extends Controller } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/symfony3/src/Rector/MethodCall/AbstractFormAddRector.php b/rules/symfony3/src/Rector/MethodCall/AbstractFormAddRector.php deleted file mode 100644 index cedf204f744..00000000000 --- a/rules/symfony3/src/Rector/MethodCall/AbstractFormAddRector.php +++ /dev/null @@ -1,84 +0,0 @@ -formTypeStringToTypeProvider = $formTypeStringToTypeProvider; - - $this->formObjectTypes = [ - new ObjectType('Symfony\Component\Form\FormBuilderInterface'), - new ObjectType('Symfony\Component\Form\FormInterface'), - ]; - } - - protected function isFormAddMethodCall(MethodCall $methodCall): bool - { - if (! $this->nodeTypeResolver->isObjectTypes($methodCall->var, $this->formObjectTypes)) { - return false; - } - - if (! $this->isName($methodCall->name, 'add')) { - return false; - } - - // just one argument - if (! isset($methodCall->args[1])) { - return false; - } - - return $methodCall->args[1]->value !== null; - } - - protected function matchOptionsArray(MethodCall $methodCall): ?Array_ - { - if (! isset($methodCall->args[2])) { - return null; - } - - $optionsArray = $methodCall->args[2]->value; - if (! $optionsArray instanceof Array_) { - return null; - } - - return $optionsArray; - } - - protected function isCollectionType(MethodCall $methodCall): bool - { - $typeValue = $methodCall->args[1]->value; - if (! $typeValue instanceof ClassConstFetch) { - return $this->valueResolver->isValue($typeValue, 'collection'); - } - - if (! $this->isName($typeValue->class, 'Symfony\Component\Form\Extension\Core\Type\CollectionType')) { - return $this->valueResolver->isValue($typeValue, 'collection'); - } - - return true; - } -} diff --git a/rules/symfony3/src/Rector/MethodCall/CascadeValidationFormBuilderRector.php b/rules/symfony3/src/Rector/MethodCall/CascadeValidationFormBuilderRector.php index 31b129be26e..ae3fe0e0b45 100644 --- a/rules/symfony3/src/Rector/MethodCall/CascadeValidationFormBuilderRector.php +++ b/rules/symfony3/src/Rector/MethodCall/CascadeValidationFormBuilderRector.php @@ -75,8 +75,7 @@ class SomeController } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/symfony3/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php b/rules/symfony3/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php index d3c41c517b8..54373eb35b8 100644 --- a/rules/symfony3/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php +++ b/rules/symfony3/src/Rector/MethodCall/ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector.php @@ -8,6 +8,10 @@ use PhpParser\Node; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; +use Rector\Core\Rector\AbstractRector; +use Rector\Symfony3\NodeAnalyzer\FormAddMethodCallAnalyzer; +use Rector\Symfony3\NodeAnalyzer\FormCollectionAnalyzer; +use Rector\Symfony3\NodeAnalyzer\FormOptionsArrayMatcher; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -16,7 +20,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; * * @see \Rector\Symfony3\Tests\Rector\MethodCall\ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector\ChangeCollectionTypeOptionNameFromTypeToEntryTypeRectorTest */ -final class ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector extends AbstractFormAddRector +final class ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector extends AbstractRector { /** * @var array @@ -26,6 +30,31 @@ final class ChangeCollectionTypeOptionNameFromTypeToEntryTypeRector extends Abst 'options' => 'entry_options', ]; + /** + * @var FormAddMethodCallAnalyzer + */ + private $formAddMethodCallAnalyzer; + + /** + * @var FormOptionsArrayMatcher + */ + private $formOptionsArrayMatcher; + + /** + * @var FormCollectionAnalyzer + */ + private $formCollectionAnalyzer; + + public function __construct( + FormAddMethodCallAnalyzer $formAddMethodCallAnalyzer, + FormOptionsArrayMatcher $formOptionsArrayMatcher, + FormCollectionAnalyzer $formCollectionAnalyzer + ) { + $this->formAddMethodCallAnalyzer = $formAddMethodCallAnalyzer; + $this->formOptionsArrayMatcher = $formOptionsArrayMatcher; + $this->formCollectionAnalyzer = $formCollectionAnalyzer; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -67,8 +96,7 @@ class TaskType extends AbstractType } } CODE_SAMPLE - ), - + ), ]); } @@ -85,15 +113,15 @@ CODE_SAMPLE */ public function refactor(Node $node): ?Node { - if (! $this->isFormAddMethodCall($node)) { + if (! $this->formAddMethodCallAnalyzer->matches($node)) { return null; } - if (! $this->isCollectionType($node)) { + if (! $this->formCollectionAnalyzer->isCollectionType($node)) { return null; } - $optionsArray = $this->matchOptionsArray($node); + $optionsArray = $this->formOptionsArrayMatcher->match($node); if (! $optionsArray instanceof Array_) { return null; } diff --git a/rules/symfony3/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php b/rules/symfony3/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php index 4eff4849691..a2a6d4317de 100644 --- a/rules/symfony3/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php +++ b/rules/symfony3/src/Rector/MethodCall/ChangeStringCollectionOptionToConstantRector.php @@ -8,6 +8,11 @@ use PhpParser\Node; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; +use Rector\Core\Rector\AbstractRector; +use Rector\Symfony3\FormHelper\FormTypeStringToTypeProvider; +use Rector\Symfony3\NodeAnalyzer\FormAddMethodCallAnalyzer; +use Rector\Symfony3\NodeAnalyzer\FormCollectionAnalyzer; +use Rector\Symfony3\NodeAnalyzer\FormOptionsArrayMatcher; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -18,8 +23,40 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; * * @see \Rector\Symfony3\Tests\Rector\MethodCall\ChangeStringCollectionOptionToConstantRector\ChangeStringCollectionOptionToConstantRectorTest */ -final class ChangeStringCollectionOptionToConstantRector extends AbstractFormAddRector +final class ChangeStringCollectionOptionToConstantRector extends AbstractRector { + /** + * @var FormAddMethodCallAnalyzer + */ + private $formAddMethodCallAnalyzer; + + /** + * @var FormOptionsArrayMatcher + */ + private $formOptionsArrayMatcher; + + /** + * @var FormTypeStringToTypeProvider + */ + private $formTypeStringToTypeProvider; + + /** + * @var FormCollectionAnalyzer + */ + private $formCollectionAnalyzer; + + public function __construct( + FormAddMethodCallAnalyzer $formAddMethodCallAnalyzer, + FormOptionsArrayMatcher $formOptionsArrayMatcher, + FormTypeStringToTypeProvider $formTypeStringToTypeProvider, + FormCollectionAnalyzer $formCollectionAnalyzer + ) { + $this->formAddMethodCallAnalyzer = $formAddMethodCallAnalyzer; + $this->formOptionsArrayMatcher = $formOptionsArrayMatcher; + $this->formTypeStringToTypeProvider = $formTypeStringToTypeProvider; + $this->formCollectionAnalyzer = $formCollectionAnalyzer; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -65,8 +102,7 @@ class TaskType extends AbstractType } } CODE_SAMPLE - ), - + ), ]); } @@ -83,15 +119,15 @@ CODE_SAMPLE */ public function refactor(Node $node): ?Node { - if (! $this->isFormAddMethodCall($node)) { + if (! $this->formAddMethodCallAnalyzer->matches($node)) { return null; } - if (! $this->isCollectionType($node)) { + if (! $this->formCollectionAnalyzer->isCollectionType($node)) { return null; } - $optionsArray = $this->matchOptionsArray($node); + $optionsArray = $this->formOptionsArrayMatcher->match($node); if (! $optionsArray instanceof Array_) { return null; } diff --git a/rules/symfony3/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php b/rules/symfony3/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php index a3c5fd2d8d7..5a55ded517b 100644 --- a/rules/symfony3/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php +++ b/rules/symfony3/src/Rector/MethodCall/FormTypeInstanceToClassConstRector.php @@ -17,7 +17,11 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PHPStan\Reflection\ReflectionProvider; use PHPStan\Type\ObjectType; +use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\MethodName; +use Rector\Symfony3\NodeAnalyzer\FormAddMethodCallAnalyzer; +use Rector\Symfony3\NodeAnalyzer\FormCollectionAnalyzer; +use Rector\Symfony3\NodeAnalyzer\FormOptionsArrayMatcher; use Rector\Symfony3\NodeFactory\BuilderFormNodeFactory; use Rector\Symfony3\NodeFactory\ConfigureOptionsNodeFactory; use ReflectionMethod; @@ -34,7 +38,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; * * @see \Rector\Symfony3\Tests\Rector\MethodCall\FormTypeInstanceToClassConstRector\FormTypeInstanceToClassConstRectorTest */ -final class FormTypeInstanceToClassConstRector extends AbstractFormAddRector +final class FormTypeInstanceToClassConstRector extends AbstractRector { /** * @var ObjectType[] @@ -56,19 +60,40 @@ final class FormTypeInstanceToClassConstRector extends AbstractFormAddRector */ private $reflectionProvider; + /** + * @var FormAddMethodCallAnalyzer + */ + private $formAddMethodCallAnalyzer; + + /** + * @var FormOptionsArrayMatcher + */ + private $formOptionsArrayMatcher; + + /** + * @var FormCollectionAnalyzer + */ + private $formCollectionAnalyzer; + public function __construct( BuilderFormNodeFactory $builderFormNodeFactory, ConfigureOptionsNodeFactory $configureOptionsNodeFactory, - ReflectionProvider $reflectionProvider + ReflectionProvider $reflectionProvider, + FormAddMethodCallAnalyzer $formAddMethodCallAnalyzer, + FormOptionsArrayMatcher $formOptionsArrayMatcher, + FormCollectionAnalyzer $formCollectionAnalyzer ) { $this->builderFormNodeFactory = $builderFormNodeFactory; $this->configureOptionsNodeFactory = $configureOptionsNodeFactory; $this->reflectionProvider = $reflectionProvider; + $this->formAddMethodCallAnalyzer = $formAddMethodCallAnalyzer; + $this->formOptionsArrayMatcher = $formOptionsArrayMatcher; $this->controllerObjectTypes = [ new ObjectType('Symfony\Bundle\FrameworkBundle\Controller\Controller'), new ObjectType('Symfony\Bundle\FrameworkBundle\Controller\AbstractController'), ]; + $this->formCollectionAnalyzer = $formCollectionAnalyzer; } public function getRuleDefinition(): RuleDefinition @@ -121,12 +146,12 @@ CODE_SAMPLE return $this->processNewInstance($node, 0, 2); } - if (! $this->isFormAddMethodCall($node)) { + if (! $this->formAddMethodCallAnalyzer->matches($node)) { return null; } // special case for collections - if ($this->isCollectionType($node)) { + if ($this->formCollectionAnalyzer->isCollectionType($node)) { $this->refactorCollectionOptions($node); } @@ -172,7 +197,7 @@ CODE_SAMPLE private function refactorCollectionOptions(MethodCall $methodCall): void { - $optionsArray = $this->matchOptionsArray($methodCall); + $optionsArray = $this->formOptionsArrayMatcher->match($methodCall); if (! $optionsArray instanceof Array_) { return; } diff --git a/rules/symfony3/src/Rector/MethodCall/OptionNameRector.php b/rules/symfony3/src/Rector/MethodCall/OptionNameRector.php index e344bdaaa85..791edd3c61e 100644 --- a/rules/symfony3/src/Rector/MethodCall/OptionNameRector.php +++ b/rules/symfony3/src/Rector/MethodCall/OptionNameRector.php @@ -8,13 +8,16 @@ use PhpParser\Node; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; +use Rector\Core\Rector\AbstractRector; +use Rector\Symfony3\NodeAnalyzer\FormAddMethodCallAnalyzer; +use Rector\Symfony3\NodeAnalyzer\FormOptionsArrayMatcher; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Symfony3\Tests\Rector\MethodCall\OptionNameRector\OptionNameRectorTest */ -final class OptionNameRector extends AbstractFormAddRector +final class OptionNameRector extends AbstractRector { /** * @var array @@ -24,6 +27,24 @@ final class OptionNameRector extends AbstractFormAddRector 'virtual' => 'inherit_data', ]; + /** + * @var FormAddMethodCallAnalyzer + */ + private $formAddMethodCallAnalyzer; + + /** + * @var FormOptionsArrayMatcher + */ + private $formOptionsArrayMatcher; + + public function __construct( + FormAddMethodCallAnalyzer $formAddMethodCallAnalyzer, + FormOptionsArrayMatcher $formOptionsArrayMatcher + ) { + $this->formAddMethodCallAnalyzer = $formAddMethodCallAnalyzer; + $this->formOptionsArrayMatcher = $formOptionsArrayMatcher; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( @@ -39,8 +60,7 @@ CODE_SAMPLE $builder = new FormBuilder; $builder->add("...", ["scale" => "...", "inherit_data" => "..."]; CODE_SAMPLE - ), - + ), ]); } @@ -57,11 +77,11 @@ CODE_SAMPLE */ public function refactor(Node $node): ?Node { - if (! $this->isFormAddMethodCall($node)) { + if (! $this->formAddMethodCallAnalyzer->matches($node)) { return null; } - $optionsArray = $this->matchOptionsArray($node); + $optionsArray = $this->formOptionsArrayMatcher->match($node); if (! $optionsArray instanceof Array_) { return null; } diff --git a/rules/symfony3/src/Rector/MethodCall/ReadOnlyOptionToAttributeRector.php b/rules/symfony3/src/Rector/MethodCall/ReadOnlyOptionToAttributeRector.php index 71be6f43682..79fc563235d 100644 --- a/rules/symfony3/src/Rector/MethodCall/ReadOnlyOptionToAttributeRector.php +++ b/rules/symfony3/src/Rector/MethodCall/ReadOnlyOptionToAttributeRector.php @@ -10,22 +10,40 @@ use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; use Rector\Core\NodeManipulator\ArrayManipulator; +use Rector\Core\Rector\AbstractRector; +use Rector\Symfony3\NodeAnalyzer\FormAddMethodCallAnalyzer; +use Rector\Symfony3\NodeAnalyzer\FormOptionsArrayMatcher; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Symfony3\Tests\Rector\MethodCall\ReadOnlyOptionToAttributeRector\ReadOnlyOptionToAttributeRectorTest */ -final class ReadOnlyOptionToAttributeRector extends AbstractFormAddRector +final class ReadOnlyOptionToAttributeRector extends AbstractRector { /** * @var ArrayManipulator */ private $arrayManipulator; - public function __construct(ArrayManipulator $arrayManipulator) - { + /** + * @var FormAddMethodCallAnalyzer + */ + private $formAddMethodCallAnalyzer; + + /** + * @var FormOptionsArrayMatcher + */ + private $formOptionsArrayMatcher; + + public function __construct( + ArrayManipulator $arrayManipulator, + FormAddMethodCallAnalyzer $formAddMethodCallAnalyzer, + FormOptionsArrayMatcher $formOptionsArrayMatcher + ) { $this->arrayManipulator = $arrayManipulator; + $this->formAddMethodCallAnalyzer = $formAddMethodCallAnalyzer; + $this->formOptionsArrayMatcher = $formOptionsArrayMatcher; } public function getRuleDefinition(): RuleDefinition @@ -51,8 +69,7 @@ function buildForm(FormBuilderInterface $builder, array $options) $builder->add('cuid', TextType::class, ['attr' => ['read_only' => true]]); } CODE_SAMPLE - ), - + ), ]); } @@ -69,14 +86,11 @@ CODE_SAMPLE */ public function refactor(Node $node): ?Node { - if (! $this->isFormAddMethodCall($node)) { + if (! $this->formAddMethodCallAnalyzer->matches($node)) { return null; } - $optionsArray = $this->matchOptionsArray($node); - if (! $optionsArray instanceof Array_) { - return null; - } + $optionsArray = $this->formOptionsArrayMatcher->match($node); if (! $optionsArray instanceof Array_) { return null; } diff --git a/rules/symfony3/src/Rector/MethodCall/StringFormTypeToClassRector.php b/rules/symfony3/src/Rector/MethodCall/StringFormTypeToClassRector.php index 8ce7d67936d..c5e8b5c74de 100644 --- a/rules/symfony3/src/Rector/MethodCall/StringFormTypeToClassRector.php +++ b/rules/symfony3/src/Rector/MethodCall/StringFormTypeToClassRector.php @@ -7,6 +7,9 @@ namespace Rector\Symfony3\Rector\MethodCall; use PhpParser\Node; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Scalar\String_; +use Rector\Core\Rector\AbstractRector; +use Rector\Symfony3\FormHelper\FormTypeStringToTypeProvider; +use Rector\Symfony3\NodeAnalyzer\FormAddMethodCallAnalyzer; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -15,13 +18,31 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; * * @see \Rector\Symfony3\Tests\Rector\MethodCall\StringFormTypeToClassRector\StringFormTypeToClassRectorTest */ -final class StringFormTypeToClassRector extends AbstractFormAddRector +final class StringFormTypeToClassRector extends AbstractRector { /** * @var string */ private const DESCRIPTION = 'Turns string Form Type references to their CONSTANT alternatives in FormTypes in Form in Symfony. To enable custom types, add link to your container XML dump in "$parameters->set(Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER, ...);"'; + /** + * @var FormAddMethodCallAnalyzer + */ + private $formAddMethodCallAnalyzer; + + /** + * @var FormTypeStringToTypeProvider + */ + private $formTypeStringToTypeProvider; + + public function __construct( + FormAddMethodCallAnalyzer $formAddMethodCallAnalyzer, + FormTypeStringToTypeProvider $formTypeStringToTypeProvider + ) { + $this->formAddMethodCallAnalyzer = $formAddMethodCallAnalyzer; + $this->formTypeStringToTypeProvider = $formTypeStringToTypeProvider; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition(self::DESCRIPTION, [ @@ -52,7 +73,7 @@ CODE_SAMPLE */ public function refactor(Node $node): ?Node { - if (! $this->isFormAddMethodCall($node)) { + if (! $this->formAddMethodCallAnalyzer->matches($node)) { return null; } diff --git a/rules/symfony4/src/Rector/ConstFetch/ConstraintUrlOptionRector.php b/rules/symfony4/src/Rector/ConstFetch/ConstraintUrlOptionRector.php index 83ab82d640d..fde5ef715c1 100644 --- a/rules/symfony4/src/Rector/ConstFetch/ConstraintUrlOptionRector.php +++ b/rules/symfony4/src/Rector/ConstFetch/ConstraintUrlOptionRector.php @@ -31,8 +31,7 @@ final class ConstraintUrlOptionRector extends AbstractRector new CodeSample( '$constraint = new Url(["checkDNS" => true]);', '$constraint = new Url(["checkDNS" => Url::CHECK_DNS_TYPE_ANY]);' - ), - + ), ]); } diff --git a/rules/symfony4/src/Rector/MethodCall/MakeDispatchFirstArgumentEventRector.php b/rules/symfony4/src/Rector/MethodCall/MakeDispatchFirstArgumentEventRector.php index 27f77cfbb13..f43e8979e1a 100644 --- a/rules/symfony4/src/Rector/MethodCall/MakeDispatchFirstArgumentEventRector.php +++ b/rules/symfony4/src/Rector/MethodCall/MakeDispatchFirstArgumentEventRector.php @@ -60,8 +60,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/symfony4/src/Rector/New_/RootNodeTreeBuilderRector.php b/rules/symfony4/src/Rector/New_/RootNodeTreeBuilderRector.php index bc66cdca3e4..1bf51321c7c 100644 --- a/rules/symfony4/src/Rector/New_/RootNodeTreeBuilderRector.php +++ b/rules/symfony4/src/Rector/New_/RootNodeTreeBuilderRector.php @@ -42,8 +42,7 @@ $treeBuilder = new TreeBuilder('acme_root'); $rootNode = $treeBuilder->getRootNode(); $rootNode->someCall(); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/symfony4/src/Rector/New_/StringToArrayArgumentProcessRector.php b/rules/symfony4/src/Rector/New_/StringToArrayArgumentProcessRector.php index 55ef344d15e..1098697b4de 100644 --- a/rules/symfony4/src/Rector/New_/StringToArrayArgumentProcessRector.php +++ b/rules/symfony4/src/Rector/New_/StringToArrayArgumentProcessRector.php @@ -54,8 +54,7 @@ CODE_SAMPLE use Symfony\Component\Process\Process; $process = new Process(['ls', '-l']); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/transform/src/Rector/AbstractToMethodCallRector.php b/rules/transform/src/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php similarity index 67% rename from rules/transform/src/Rector/AbstractToMethodCallRector.php rename to rules/transform/src/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php index fecc2919134..8c60fab7bec 100644 --- a/rules/transform/src/Rector/AbstractToMethodCallRector.php +++ b/rules/transform/src/NodeAnalyzer/FuncCallStaticCallToMethodCallAnalyzer.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rector\Transform\Rector; +namespace Rector\Transform\NodeAnalyzer; use PhpParser\Node\Expr; use PhpParser\Node\Expr\MethodCall; @@ -13,23 +13,34 @@ use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use PHPStan\Type\ObjectType; -use Rector\Core\Contract\Rector\ConfigurableRectorInterface; -use Rector\Core\Rector\AbstractRector; +use Rector\Core\PhpParser\Node\NodeFactory; use Rector\Naming\Naming\PropertyNaming; +use Rector\NodeNameResolver\NodeNameResolver; +use Rector\PostRector\DependencyInjection\PropertyAdder; use Rector\Transform\NodeFactory\PropertyFetchFactory; use Rector\Transform\NodeTypeAnalyzer\TypeProvidingExprFromClassResolver; -abstract class AbstractToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface +final class FuncCallStaticCallToMethodCallAnalyzer { + /** + * @var TypeProvidingExprFromClassResolver + */ + private $typeProvidingExprFromClassResolver; + /** * @var PropertyNaming */ private $propertyNaming; /** - * @var TypeProvidingExprFromClassResolver + * @var NodeNameResolver */ - private $typeProvidingExprFromClassResolver; + private $nodeNameResolver; + + /** + * @var NodeFactory + */ + private $nodeFactory; /** * @var PropertyFetchFactory @@ -37,23 +48,31 @@ abstract class AbstractToMethodCallRector extends AbstractRector implements Conf private $propertyFetchFactory; /** - * @required + * @var PropertyAdder */ - public function autowireAbstractToMethodCallRector( - PropertyNaming $propertyNaming, + private $propertyAdder; + + public function __construct( TypeProvidingExprFromClassResolver $typeProvidingExprFromClassResolver, - PropertyFetchFactory $propertyFetchFactory - ): void { - $this->propertyNaming = $propertyNaming; + PropertyNaming $propertyNaming, + NodeNameResolver $nodeNameResolver, + NodeFactory $nodeFactory, + PropertyFetchFactory $propertyFetchFactory, + PropertyAdder $propertyAdder + ) { $this->typeProvidingExprFromClassResolver = $typeProvidingExprFromClassResolver; + $this->propertyNaming = $propertyNaming; + $this->nodeNameResolver = $nodeNameResolver; + $this->nodeFactory = $nodeFactory; $this->propertyFetchFactory = $propertyFetchFactory; + $this->propertyAdder = $propertyAdder; } /** * @param ClassMethod|Function_ $functionLike * @return MethodCall|PropertyFetch|Variable */ - protected function matchTypeProvidingExpr(Class_ $class, FunctionLike $functionLike, ObjectType $objectType): Expr + public function matchTypeProvidingExpr(Class_ $class, FunctionLike $functionLike, ObjectType $objectType): Expr { $expr = $this->typeProvidingExprFromClassResolver->resolveTypeProvidingExprFromClass( $class, @@ -69,7 +88,7 @@ abstract class AbstractToMethodCallRector extends AbstractRector implements Conf } $propertyName = $this->propertyNaming->fqnToVariableName($objectType); - $this->addConstructorDependencyToClass($class, $objectType, $propertyName); + $this->propertyAdder->addConstructorDependencyToClass($class, $objectType, $propertyName); return $this->propertyFetchFactory->createFromType($objectType); } @@ -82,7 +101,7 @@ abstract class AbstractToMethodCallRector extends AbstractRector implements Conf FunctionLike $functionLike ): void { /** @var string $variableName */ - $variableName = $this->getName($variable); + $variableName = $this->nodeNameResolver->getName($variable); // add variable to __construct as dependency $functionLike->params[] = $this->nodeFactory->createParamFromNameAndType($variableName, $objectType); diff --git a/rules/transform/src/Rector/FileWithoutNamespace/FunctionToStaticMethodRector.php b/rules/transform/src/Rector/FileWithoutNamespace/FunctionToStaticMethodRector.php index 2f9749d4887..1194febf527 100644 --- a/rules/transform/src/Rector/FileWithoutNamespace/FunctionToStaticMethodRector.php +++ b/rules/transform/src/Rector/FileWithoutNamespace/FunctionToStaticMethodRector.php @@ -75,8 +75,7 @@ class SomeUtilsClass SomeUtilsClass::someFunction('lol'); CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/transform/src/Rector/FuncCall/FuncCallToMethodCallRector.php b/rules/transform/src/Rector/FuncCall/FuncCallToMethodCallRector.php index 332691ef5c8..38de6f5efd5 100644 --- a/rules/transform/src/Rector/FuncCall/FuncCallToMethodCallRector.php +++ b/rules/transform/src/Rector/FuncCall/FuncCallToMethodCallRector.php @@ -8,8 +8,10 @@ use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use Rector\Core\Contract\Rector\ConfigurableRectorInterface; +use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\Transform\Rector\AbstractToMethodCallRector; +use Rector\Transform\NodeAnalyzer\FuncCallStaticCallToMethodCallAnalyzer; use Rector\Transform\ValueObject\FuncCallToMethodCall; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -18,7 +20,7 @@ use Webmozart\Assert\Assert; /** * @see \Rector\Transform\Tests\Rector\FuncCall\FuncCallToMethodCallRector\FuncCallToMethodCallRectorTest */ -final class FuncCallToMethodCallRector extends AbstractToMethodCallRector +final class FuncCallToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface { /** * @var string @@ -30,6 +32,16 @@ final class FuncCallToMethodCallRector extends AbstractToMethodCallRector */ private $funcNameToMethodCallNames = []; + /** + * @var FuncCallStaticCallToMethodCallAnalyzer + */ + private $funcCallStaticCallToMethodCallAnalyzer; + + public function __construct(FuncCallStaticCallToMethodCallAnalyzer $funcCallStaticCallToMethodCallAnalyzer) + { + $this->funcCallStaticCallToMethodCallAnalyzer = $funcCallStaticCallToMethodCallAnalyzer; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Turns defined function calls to local method calls.', [ @@ -105,7 +117,7 @@ CODE_SAMPLE continue; } - $expr = $this->matchTypeProvidingExpr( + $expr = $this->funcCallStaticCallToMethodCallAnalyzer->matchTypeProvidingExpr( $classLike, $classMethod, $funcNameToMethodCallName->getNewObjectType() @@ -120,10 +132,14 @@ CODE_SAMPLE return null; } + /** + * @param array $configuration + */ public function configure(array $configuration): void { $funcCallsToClassMethodCalls = $configuration[self::FUNC_CALL_TO_CLASS_METHOD_CALL] ?? []; Assert::allIsInstanceOf($funcCallsToClassMethodCalls, FuncCallToMethodCall::class); + $this->funcNameToMethodCallNames = $funcCallsToClassMethodCalls; } } diff --git a/rules/transform/src/Rector/StaticCall/StaticCallToMethodCallRector.php b/rules/transform/src/Rector/StaticCall/StaticCallToMethodCallRector.php index 55e8be0d0dd..8b2de9dcbce 100644 --- a/rules/transform/src/Rector/StaticCall/StaticCallToMethodCallRector.php +++ b/rules/transform/src/Rector/StaticCall/StaticCallToMethodCallRector.php @@ -11,9 +11,11 @@ use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use Rector\Core\Contract\Rector\ConfigurableRectorInterface; use Rector\Core\Exception\ShouldNotHappenException; +use Rector\Core\Rector\AbstractRector; use Rector\NodeTypeResolver\Node\AttributeKey; -use Rector\Transform\Rector\AbstractToMethodCallRector; +use Rector\Transform\NodeAnalyzer\FuncCallStaticCallToMethodCallAnalyzer; use Rector\Transform\ValueObject\StaticCallToMethodCall; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -22,7 +24,7 @@ use Webmozart\Assert\Assert; /** * @see \Rector\Transform\Tests\Rector\StaticCall\StaticCallToMethodCallRector\StaticCallToMethodCallRectorTest */ -final class StaticCallToMethodCallRector extends AbstractToMethodCallRector +final class StaticCallToMethodCallRector extends AbstractRector implements ConfigurableRectorInterface { /** * @api @@ -35,6 +37,16 @@ final class StaticCallToMethodCallRector extends AbstractToMethodCallRector */ private $staticCallsToMethodCalls = []; + /** + * @var FuncCallStaticCallToMethodCallAnalyzer + */ + private $funcCallStaticCallToMethodCallAnalyzer; + + public function __construct(FuncCallStaticCallToMethodCallAnalyzer $funcCallStaticCallToMethodCallAnalyzer) + { + $this->funcCallStaticCallToMethodCallAnalyzer = $funcCallStaticCallToMethodCallAnalyzer; + } + public function getRuleDefinition(): RuleDefinition { return new RuleDefinition('Change static call to service method via constructor injection', [ @@ -117,7 +129,7 @@ CODE_SAMPLE return $this->refactorToInstanceCall($node, $staticCallToMethodCall); } - $expr = $this->matchTypeProvidingExpr( + $expr = $this->funcCallStaticCallToMethodCallAnalyzer->matchTypeProvidingExpr( $classLike, $classMethod, $staticCallToMethodCall->getClassObjectType() @@ -139,6 +151,9 @@ CODE_SAMPLE return $node; } + /** + * @param array $configuration + */ public function configure(array $configuration): void { $staticCallsToMethodCalls = $configuration[self::STATIC_CALLS_TO_METHOD_CALLS] ?? []; diff --git a/rules/type-declaration/src/Rector/ClassMethod/AddArrayParamDocTypeRector.php b/rules/type-declaration/src/Rector/ClassMethod/AddArrayParamDocTypeRector.php index 72a457a75db..f1a5cabfe66 100644 --- a/rules/type-declaration/src/Rector/ClassMethod/AddArrayParamDocTypeRector.php +++ b/rules/type-declaration/src/Rector/ClassMethod/AddArrayParamDocTypeRector.php @@ -77,8 +77,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/type-declaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php b/rules/type-declaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php index 012fd5b2e92..a7eecb23385 100644 --- a/rules/type-declaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php +++ b/rules/type-declaration/src/Rector/ClassMethod/AddArrayReturnDocTypeRector.php @@ -118,8 +118,7 @@ class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/type-declaration/src/Rector/FunctionLike/ParamTypeDeclarationRector.php b/rules/type-declaration/src/Rector/FunctionLike/ParamTypeDeclarationRector.php index 2c16ac712da..bc1175e7920 100644 --- a/rules/type-declaration/src/Rector/FunctionLike/ParamTypeDeclarationRector.php +++ b/rules/type-declaration/src/Rector/FunctionLike/ParamTypeDeclarationRector.php @@ -119,8 +119,7 @@ final class ChildClass extends ParentClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/type-declaration/src/Rector/MethodCall/FormerNullableArgumentToScalarTypedRector.php b/rules/type-declaration/src/Rector/MethodCall/FormerNullableArgumentToScalarTypedRector.php index 2d04e8f75ad..8b3b7231c6b 100644 --- a/rules/type-declaration/src/Rector/MethodCall/FormerNullableArgumentToScalarTypedRector.php +++ b/rules/type-declaration/src/Rector/MethodCall/FormerNullableArgumentToScalarTypedRector.php @@ -71,8 +71,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/rules/type-declaration/src/Rector/Property/CompleteVarDocTypePropertyRector.php b/rules/type-declaration/src/Rector/Property/CompleteVarDocTypePropertyRector.php index 665731916f1..7e55b3504f9 100644 --- a/rules/type-declaration/src/Rector/Property/CompleteVarDocTypePropertyRector.php +++ b/rules/type-declaration/src/Rector/Property/CompleteVarDocTypePropertyRector.php @@ -66,8 +66,7 @@ final class SomeClass } } CODE_SAMPLE - ), - + ), ]); } diff --git a/utils/phpstan-extensions/config/rector-rules.neon b/utils/phpstan-extensions/config/rector-rules.neon index 8124350152b..340cb93eb6f 100644 --- a/utils/phpstan-extensions/config/rector-rules.neon +++ b/utils/phpstan-extensions/config/rector-rules.neon @@ -21,16 +21,11 @@ services: # solve later - Rector\Nette\Rector\FuncCall\AbstractPregToNetteUtilsStringsRector - Rector\Nette\Rector\Identical\AbstractWithFunctionToNetteUtilsStringsRector - - Rector\Order\Rector\AbstractConstantPropertyMethodOrderRector - - Rector\Php72\Rector\FuncCall\AbstractConvertToAnonymousFunctionRector - Rector\TypeDeclaration\Rector\FunctionLike\AbstractTypeDeclarationRector - - Rector\Transform\Rector\AbstractToMethodCallRector - - Rector\Symfony3\Rector\MethodCall\AbstractFormAddRector - Rector\Symfony\Rector\MethodCall\AbstractToConstructorInjectionRector - Rector\NetteCodeQuality\Rector\ArrayDimFetch\AbstractArrayDimFetchToAnnotatedControlVariableRector - Rector\DowngradePhp74\Rector\Property\AbstractDowngradeTypedPropertyRector - Rector\Defluent\Rector\AbstractFluentChainMethodCallRector - - Rector\NetteKdyby\Rector\ClassMethod\AbstractKdybyEventSubscriberRector - class: Symplify\PHPStanRules\Rules\ServiceAndValueObjectHaveSameStartsRule