diff --git a/composer.json b/composer.json index 21fda1c..7000f25 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "phpstan/phpstan": "^1.9.0", "pluswerk/grumphp-bom-task": "^8.0.0", "pluswerk/grumphp-xliff-task": "^6.0.0", - "rector/rector": "^0.17.0", + "rector/rector": "^1.0.4", "squizlabs/php_codesniffer": "^3.7.1", "symfony/yaml": "^5.4.0 || ^6.0 || ^7.0" }, @@ -75,6 +75,6 @@ }, "require-typo3": { "saschaegerer/phpstan-typo3": "^1.8.2", - "ssch/typo3-rector": "^1.3.5" + "ssch/typo3-rector": "^2.3.2" } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index aab4991..331ae55 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,2 +1,56 @@ parameters: - ignoreErrors: [] + ignoreErrors: + - + message: "#^Class Ssch\\\\TYPO3Rector\\\\CodeQuality\\\\General\\\\ConvertImplicitVariablesToExplicitGlobalsRector not found\\.$#" + count: 1 + path: rector-typo3-rule-set.php + + - + message: "#^Parameter \\#1 \\$rectorClasses of method Rector\\\\Config\\\\RectorConfig\\:\\:rules\\(\\) expects array\\\\>, array\\ given\\.$#" + count: 1 + path: rector-typo3-rule-set.php + + - + message: "#^Access to constant CODE_QUALITY on an unknown class Ssch\\\\TYPO3Rector\\\\Set\\\\Typo3SetList\\.$#" + count: 1 + path: src/RectorSettings.php + + - + message: "#^Access to constant GENERAL on an unknown class Ssch\\\\TYPO3Rector\\\\Set\\\\Typo3SetList\\.$#" + count: 1 + path: src/RectorSettings.php + + - + message: "#^Access to constant TYPO3_11 on an unknown class Ssch\\\\TYPO3Rector\\\\Set\\\\Typo3SetList\\.$#" + count: 1 + path: src/RectorSettings.php + + - + message: "#^Access to constant TYPO3_12 on an unknown class Ssch\\\\TYPO3Rector\\\\Set\\\\Typo3SetList\\.$#" + count: 1 + path: src/RectorSettings.php + + - + message: "#^Access to constant TYPO3_13 on an unknown class Ssch\\\\TYPO3Rector\\\\Set\\\\Typo3SetList\\.$#" + count: 1 + path: src/RectorSettings.php + + - + message: "#^Access to constant UP_TO_TYPO3_10 on an unknown class Ssch\\\\TYPO3Rector\\\\Set\\\\Typo3LevelSetList\\.$#" + count: 1 + path: src/RectorSettings.php + + - + message: "#^Access to constant UP_TO_TYPO3_11 on an unknown class Ssch\\\\TYPO3Rector\\\\Set\\\\Typo3LevelSetList\\.$#" + count: 1 + path: src/RectorSettings.php + + - + message: "#^Access to constant UP_TO_TYPO3_12 on an unknown class Ssch\\\\TYPO3Rector\\\\Set\\\\Typo3LevelSetList\\.$#" + count: 1 + path: src/RectorSettings.php + + - + message: "#^Class Ssch\\\\TYPO3Rector\\\\CodeQuality\\\\General\\\\RenameClassMapAliasRector not found\\.$#" + count: 1 + path: src/RectorSettings.php diff --git a/rector-typo3-rule-set.php b/rector-typo3-rule-set.php index 497e0e1..40d7a51 100644 --- a/rector-typo3-rule-set.php +++ b/rector-typo3-rule-set.php @@ -2,8 +2,8 @@ declare(strict_types=1); -use Ssch\TYPO3Rector\Rector\General\InjectMethodToConstructorInjectionRector; -use Ssch\TYPO3Rector\Rector\General\ConvertImplicitVariablesToExplicitGlobalsRector; +use Ssch\TYPO3Rector\CodeQuality\General\ConvertImplicitVariablesToExplicitGlobalsRector; +use Ssch\TYPO3Rector\CodeQuality\General\InjectMethodToConstructorInjectionRector; use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { diff --git a/src/RectorSettings.php b/src/RectorSettings.php index e988105..fd9d455 100644 --- a/src/RectorSettings.php +++ b/src/RectorSettings.php @@ -9,22 +9,21 @@ use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector; -use Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector; use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector; use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector; -use Rector\CodingStyle\Rector\Switch_\BinarySwitchToIfElseRector; use Rector\Php70\Rector\Assign\ListSwapArrayOrderRector; use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector; use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; +use Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector; +use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector; +use Rector\Strict\Rector\Ternary\DisallowedShortTernaryRuleFixerRector; use Rector\TypeDeclaration\Rector\BooleanAnd\BinaryOpNullableToInstanceofRector; -use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictGetterMethodReturnTypeRector; -use Ssch\TYPO3Rector\Rector\Migrations\RenameClassMapAliasRector; +use Ssch\TYPO3Rector\CodeQuality\General\RenameClassMapAliasRector; use Ssch\TYPO3Rector\Set\Typo3LevelSetList; use Ssch\TYPO3Rector\Set\Typo3SetList; -use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector; use Rector\Php73\Rector\ConstFetch\SensitiveConstantNameRector; final class RectorSettings @@ -45,14 +44,16 @@ public static function sets(bool $entirety = false): array return array_filter( [ - // SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION, // NO SetList::CODE_QUALITY, // YES SetList::CODING_STYLE, // YES SetList::DEAD_CODE, // YES + SetList::STRICT_BOOLEANS, // only DisallowedEmptyRuleFixerRector //SetList::GMAGICK_TO_IMAGICK, // NO - //SetList::MONOLOG_20, // no usage - //SetList::MYSQL_TO_MYSQLI, // no usage //SetList::NAMING, //NO is not good + SetList::PRIVATIZATION, // some things may be bad + SetList::TYPE_DECLARATION, // YES + SetList::EARLY_RETURN, // YES + SetList::INSTANCEOF, $phpFile, //SetList::PHP_52, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... //SetList::PHP_53, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... @@ -67,10 +68,6 @@ public static function sets(bool $entirety = false): array //SetList::PHP_80, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... //SetList::PHP_81, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... //SetList::PHP_82, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - SetList::PRIVATIZATION, // some things may be bad - SetList::TYPE_DECLARATION, // YES - SetList::EARLY_RETURN, //YES - SetList::INSTANCEOF, ] ); } @@ -89,31 +86,27 @@ public static function setsTypo3(bool $entirety = false): array [$major] = explode('.', $minimalTypo3Version, 2); switch ($major) { - case 7: - $setList = $entirety ? Typo3LevelSetList::UP_TO_TYPO3_7 : Typo3SetList::TYPO3_76; - break; - case 8: - $setList = $entirety ? Typo3LevelSetList::UP_TO_TYPO3_8 : Typo3SetList::TYPO3_87; - break; - case 9: - $setList = $entirety ? Typo3LevelSetList::UP_TO_TYPO3_9 : Typo3SetList::TYPO3_95; - break; case 10: - $setList = $entirety ? Typo3LevelSetList::UP_TO_TYPO3_10 : Typo3SetList::TYPO3_104; + $setList = Typo3LevelSetList::UP_TO_TYPO3_10; break; case 11: $setList = $entirety ? Typo3LevelSetList::UP_TO_TYPO3_11 : Typo3SetList::TYPO3_11; break; case 12: - case 'dev-main': $setList = $entirety ? Typo3LevelSetList::UP_TO_TYPO3_12 : Typo3SetList::TYPO3_12; break; + case 13: + case 'dev-main': + $setList = Typo3SetList::TYPO3_13; + break; } assert(is_string($setList)); return [ $setList, __DIR__ . '/../rector-typo3-rule-set.php', + Typo3SetList::CODE_QUALITY, + Typo3SetList::GENERAL, ]; } @@ -148,16 +141,6 @@ public static function skip(): array * TO: if($array !== []) { */ CountArrayToEmptyArrayComparisonRector::class, - /** - * FROM: switch($x) { - * TO: if($X === '...') { - */ - BinarySwitchToIfElseRector::class, - /** - * FROM: ->select('a', 'b') - * TO: ->select(['a', 'b']) - */ - UnSpreadOperatorRector::class, /** * FROM: protected string $name; * TO: private string $name; @@ -190,20 +173,21 @@ public static function skip(): array */ ExplicitBoolCompareRector::class, /** - * FROM: isset($this->x); - * TO: property_exists($this, 'x') && $this->x !== null; + * FROM: (!self::$email) { + * TO: if (self::$email === '' || self::$email === '0') { */ - IssetOnPropertyObjectToPropertyExistsRector::class, + BooleanInBooleanNotRuleFixerRector::class, + BooleanInIfConditionRuleFixerRector::class, /** - * FROM: * @ var ObjectStorage - * TO: * @ var ObjectStorage + * FROM: $filter['userGroup'] = max($userGroups ?: [0]); + * TO: $filter['userGroup'] = max($userGroups !== [] ? $userGroups : [0]); */ - TypedPropertyFromStrictGetterMethodReturnTypeRector::class, + DisallowedShortTernaryRuleFixerRector::class, /** - * perfomance issues in many projects - * @deprecated remove if rector 0.17.0 is not supported anymore: + * FROM: isset($this->x); + * TO: property_exists($this, 'x') && $this->x !== null; */ - class_exists(RemoveEmptyMethodCallRector::class) ? RemoveEmptyMethodCallRector::class : null, + IssetOnPropertyObjectToPropertyExistsRector::class, ]); }