rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.77k stars 687 forks source link

Update to `0.18.3` from `0.18.2` #8199

Closed ddevsr closed 1 year ago

ddevsr commented 1 year ago

Bug Report

Subject Details
Rector version 0.18.3 (invoke vendor/bin/rector --version)

Rules

<?php

declare(strict_types=1);

use Rector\CodeQuality\Rector\Assign\CombinedAssignRector;
use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector;
use Rector\CodeQuality\Rector\BooleanNot\ReplaceMultipleBooleanNotRector;
use Rector\CodeQuality\Rector\BooleanNot\SimplifyDeMorganBinaryRector;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\CodeQuality\Rector\ClassMethod\InlineArrayReturnAssignRector;
use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector;
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
use Rector\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector;
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
use Rector\CodeQuality\Rector\FuncCall\ArrayMergeOfNonArraysToSimpleArrayRector;
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
use Rector\CodeQuality\Rector\If_\CombineIfRector;
use Rector\CodeQuality\Rector\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfNotNullReturnRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfNullableReturnRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
use Rector\CodeQuality\Rector\LogicalAnd\AndAssignsToSeparateLinesRector;
use Rector\CodeQuality\Rector\LogicalAnd\LogicalToBooleanRector;
use Rector\CodeQuality\Rector\NotEqual\CommonNotEqualRector;
use Rector\CodeQuality\Rector\Ternary\ArrayKeyExistsTernaryThenValueToCoalescingRector;
use Rector\CodeQuality\Rector\Ternary\NumberCompareToMaxFuncCallRector;
use Rector\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector;
use Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector;
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\Config\RectorConfig;
use Rector\Core\ValueObject\PhpVersion;
use Rector\DeadCode\Rector\Array_\RemoveDuplicatedArrayKeyRector;
use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector;
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
use Rector\DeadCode\Rector\BooleanAnd\RemoveAndTrueRector;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedPrivateClassConstantRector;
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodParameterRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector;
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
use Rector\DeadCode\Rector\Expression\SimplifyMirrorAssignRector;
use Rector\DeadCode\Rector\Plus\RemoveDeadZeroAndOneOperationRector;
use Rector\DeadCode\Rector\Return_\RemoveDeadConditionAboveReturnRector;
use Rector\DeadCode\Rector\TryCatch\RemoveDeadTryCatchRector;
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
use Rector\Php80\Rector\Catch_\RemoveUnusedVariableInCatchRector;
use Rector\Php80\Rector\Switch_\ChangeSwitchToMatchRector;
use Rector\Php81\Rector\Array_\FirstClassCallableRector;
use Rector\Php82\Rector\FuncCall\Utf8DecodeEncodeToMbConvertEncodingRector;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->sets([
        SetList::DEAD_CODE,
        SetList::CODE_QUALITY,
        SetList::STRICT_BOOLEANS,
        LevelSetList::UP_TO_PHP_82,
    ]);

    // The paths to refactor (can also be supplied with CLI arguments)
    $rectorConfig->paths([
        __DIR__ . '/app',
    ]);

    // Include Composer's autoload - required for global execution, remove if running locally
    $rectorConfig->autoloadPaths([
        __DIR__ . '/vendor/autoload.php',
    ]);

    // Do you need to include constants, class aliases, or a custom autoloader?
    $rectorConfig->bootstrapFiles([
        realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php',
    ]);

    if (is_file(__DIR__ . '/phpstan.neon.dist')) {
        $rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist');
    }

    // Set the target version for refactoring
    $rectorConfig->phpVersion(PhpVersion::PHP_82);

    // Auto-import fully qualified class names
    $rectorConfig->importNames();

    // Are there files or rules you need to skip?
    $rectorConfig->skip([
        __DIR__ . '/app/Common.php',
        __DIR__ . '/app/Config',
        __DIR__ . '/app/Database',
        __DIR__ . '/app/Language',
        __DIR__ . '/app/Views',

        JsonThrowOnErrorRector::class,
        StringifyStrNeedlesRector::class,

        // Note: requires php 8
        RemoveUnusedPromotedPropertyRector::class,

        // May load view files directly when detecting classes
        StringClassNameToClassConstantRector::class,
    ]);
    // auto import fully qualified class names
    $rectorConfig->importNames();

    $rectorConfig->rule(RemoveDeadZeroAndOneOperationRector::class);
    $rectorConfig->rule(InlineArrayReturnAssignRector::class);
    $rectorConfig->rule(LogicalToBooleanRector::class);
    $rectorConfig->rule(AndAssignsToSeparateLinesRector::class);
    $rectorConfig->rule(SwitchNegatedTernaryRector::class);
    $rectorConfig->rule(ArrayKeyExistsTernaryThenValueToCoalescingRector::class);
    $rectorConfig->rule(TernaryFalseExpressionToIfRector::class);
    $rectorConfig->rule(UseIdenticalOverEqualWithSameTypeRector::class);
    $rectorConfig->rule(ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class);
    $rectorConfig->rule(ExplicitBoolCompareRector::class);
    $rectorConfig->rule(SimplifyIfNullableReturnRector::class);
    $rectorConfig->rule(SimplifyIfNotNullReturnRector::class);
    $rectorConfig->rule(ArrayMergeOfNonArraysToSimpleArrayRector::class);
    $rectorConfig->rule(SimplifyDeMorganBinaryRector::class);
    $rectorConfig->rule(CommonNotEqualRector::class);
    $rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class);
    $rectorConfig->rule(JoinStringConcatRector::class);
    $rectorConfig->rule(SimplifyMirrorAssignRector::class);
    $rectorConfig->rule(RemoveDeadStmtRector::class);
    $rectorConfig->rule(RemovePhpVersionIdCheckRector::class);
    $rectorConfig->rule(RemoveConcatAutocastRector::class);
    $rectorConfig->rule(RemoveUnusedPrivateMethodRector::class);
    $rectorConfig->rule(RemoveUnusedPrivateMethodParameterRector::class);
    $rectorConfig->rule(RemoveUnusedConstructorParamRector::class);
    $rectorConfig->rule(RemoveEmptyClassMethodRector::class);
    $rectorConfig->rule(RemoveUselessParamTagRector::class);
    $rectorConfig->rule(RemoveUnusedPrivateClassConstantRector::class);
    $rectorConfig->rule(RemoveAnnotationRector::class);
    $rectorConfig->rule(RemoveAndTrueRector::class);
    $rectorConfig->rule(RecastingRemovalRector::class);
    $rectorConfig->rule(RemoveDeadTryCatchRector::class);
    $rectorConfig->rule(ReplaceMultipleBooleanNotRector::class);
    $rectorConfig->rule(CombinedAssignRector::class);
    $rectorConfig->rule(NumberCompareToMaxFuncCallRector::class);
    $rectorConfig->rule(RemoveDeadConditionAboveReturnRector::class);
    $rectorConfig->rule(RemoveUselessReturnTagRector::class);
    $rectorConfig->rule(RemoveDuplicatedArrayKeyRector::class);
    $rectorConfig->rule(RemoveDoubleAssignRector::class);
    $rectorConfig->rule(RemoveUnusedVariableAssignRector::class);
    $rectorConfig->rule(SimplifyUselessVariableRector::class);
    $rectorConfig->rule(RemoveAlwaysElseRector::class);
    $rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class);
    $rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class);
    $rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class);
    $rectorConfig->rule(SimplifyStrposLowerRector::class);
    $rectorConfig->rule(CombineIfRector::class);
    $rectorConfig->rule(SimplifyIfReturnBoolRector::class);
    $rectorConfig->rule(InlineIfToExplicitIfRector::class);
    $rectorConfig->rule(PreparedValueToEarlyReturnRector::class);
    $rectorConfig->rule(ShortenElseIfRector::class);
    $rectorConfig->rule(SimplifyIfElseToTernaryRector::class);
    $rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class);
    $rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
    $rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);
    $rectorConfig->rule(SimplifyRegexPatternRector::class);
    $rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
    $rectorConfig->rule(RemoveUnusedVariableInCatchRector::class);
    $rectorConfig->rule(ChangeSwitchToMatchRector::class);
    $rectorConfig->rule(FirstClassCallableRector::class);
    $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
    $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
    $rectorConfig->rule(StringClassNameToClassConstantRector::class);
    $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
    $rectorConfig->rule(CompleteDynamicPropertiesRector::class);
    $rectorConfig->rule(Utf8DecodeEncodeToMbConvertEncodingRector::class);
};

Debug

$ vendor/bin/rector process --dry-run --debug
D:\Project\laragon\www\claimon\app\Controllers\BaseController.php
D:\Project\laragon\www\claimon\app\Controllers\Home.php
D:\Project\laragon\www\claimon\app\Controllers\MasterUser.php
D:\Project\laragon\www\claimon\app\Filters\AuthFilter.php
D:\Project\laragon\www\claimon\app\Helpers\levels_helper.php
D:\Project\laragon\www\claimon\app\Libraries\CURLRequest.php

          ould not process "D:\Project\laragon\www\claimon\app\Controllers\BaseController.php" file, due to: 
                                                       t: array"

         #0 D:\Project\laragon\www\claimon\vendor\rector\rector\vendor\webmozart\assert\src\Assert.php(451):            
         RectorPrefix202309\Webmozart\Assert\Assert::reportInvalidArgument('Expected a non-...')                        
         #1                                                                                                             
         D:\Project\laragon\www\claimon\vendor\rector\rector\rules\DeadCode\Rector\ClassLike\RemoveAnnotationRector.php(
         73): RectorPrefix202309\Webmozart\Assert\Assert::notEmpty(Array)                              
         #28 D:\Project\laragon\www\claimon\vendor\bin\rector(120): include('D:\\Project\\lara...')                     
         #29 {main}". On line: 1601                                                                                     

                    rocess "D:\Project\laragon\www\claimon\app\Controllers\Home.php" file, due to: 
                                                       t: array"

         #0 D:\Project\laragon\www\claimon\vendor\rector\rector\vendor\webmozart\assert\src\Assert.php(451):            
         RectorPrefix202309\Webmozart\Assert\Assert::reportInvalidArgument('Expected a non-...')                        
         #1                                                                                                             
         D:\Project\laragon\www\claimon\vendor\rector\rector\rules\DeadCode\Rector\ClassLike\RemoveAnnotationRector.php(
         73): RectorPrefix202309\Webmozart\Assert\Assert::notEmpty(Array)                                   
         #28 D:\Project\laragon\www\claimon\vendor\bin\rector(120): include('D:\\Project\\lara...')                     
         #29 {main}". On line: 1601                                                                                     

               not process "D:\Project\laragon\www\claimon\app\Controllers\MasterUser.php" file, due to: 
                                                       t: array"

         #0 D:\Project\laragon\www\claimon\vendor\rector\rector\vendor\webmozart\assert\src\Assert.php(451):            
         RectorPrefix202309\Webmozart\Assert\Assert::reportInvalidArgument('Expected a non-...')                        
         #1                                                                                                             
         D:\Project\laragon\www\claimon\vendor\rector\rector\rules\DeadCode\Rector\ClassLike\RemoveAnnotationRector.php(
         73): RectorPrefix202309\Webmozart\Assert\Assert::notEmpty(Array)                           
         #28 D:\Project\laragon\www\claimon\vendor\bin\rector(120): include('D:\\Project\\lara...')                     
         #29 {main}". On line: 1601                                                                                     

                   process "D:\Project\laragon\www\claimon\app\Filters\AuthFilter.php" file, due to: 
                                                       t: array"

         #0 D:\Project\laragon\www\claimon\vendor\rector\rector\vendor\webmozart\assert\src\Assert.php(451):            
         RectorPrefix202309\Webmozart\Assert\Assert::reportInvalidArgument('Expected a non-...')                        
         #1                                                                                                             
         D:\Project\laragon\www\claimon\vendor\rector\rector\rules\DeadCode\Rector\ClassLike\RemoveAnnotationRector.php(
         73): RectorPrefix202309\Webmozart\Assert\Assert::notEmpty(Array)                                            
         #28 D:\Project\laragon\www\claimon\vendor\bin\rector(120): include('D:\\Project\\lara...')                     
         #29 {main}". On line: 1601                                                                                     

               not process "D:\Project\laragon\www\claimon\app\Helpers\levels_helper.php" file, due to: 
                                                       t: array"

         #0 D:\Project\laragon\www\claimon\vendor\rector\rector\vendor\webmozart\assert\src\Assert.php(451):            
         RectorPrefix202309\Webmozart\Assert\Assert::reportInvalidArgument('Expected a non-...')                        
         #1                                                                                                             
         D:\Project\laragon\www\claimon\vendor\rector\rector\rules\DeadCode\Rector\ClassLike\RemoveAnnotationRector.php(
         73): RectorPrefix202309\Webmozart\Assert\Assert::notEmpty(Array)                                               
         #30 D:\Project\laragon\www\claimon\vendor\bin\rector(120): include('D:\\Project\\lara...')                     
         #31 {main}". On line: 1601                                                                                     

               not process "D:\Project\laragon\www\claimon\app\Libraries\CURLRequest.php" file, due to: 
                                                       t: array"

         #0 D:\Project\laragon\www\claimon\vendor\rector\rector\vendor\webmozart\assert\src\Assert.php(451):            
         RectorPrefix202309\Webmozart\Assert\Assert::reportInvalidArgument('Expected a non-...')                        
         #1                                                                                                             
         D:\Project\laragon\www\claimon\vendor\rector\rector\rules\DeadCode\Rector\ClassLike\RemoveAnnotationRector.php(
         73): RectorPrefix202309\Webmozart\Assert\Assert::notEmpty(Array)

Expected Behaviour

Is related to RemoveAnnotationRector? i see on release 0.18.3 no one mentioned it at all

samsonasik commented 1 year ago

RemoveAnnotationRector is implements ConfigurableRectorInterface, you can configure:

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig
        ->ruleWithConfiguration(RemoveAnnotationRector::class, ['method', 'JMS\DiExtraBundle\Annotation\InjectParams']);
};

or just remove the rule if you don't use it :)