diff --git a/.github/workflows/run-grumphp-test.yml b/.github/workflows/run-grumphp-test.yml index d5d7fd9..7987d7f 100644 --- a/.github/workflows/run-grumphp-test.yml +++ b/.github/workflows/run-grumphp-test.yml @@ -7,7 +7,6 @@ jobs: fail-fast: false matrix: php: - - '8.0' - '8.1' - '8.2' container: diff --git a/composer.json b/composer.json index a026cf8..cc400cf 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "issues": "https://github.com/pluswerk/grumphp-config/issues" }, "require": { - "php": "~8.0.0 || ~8.1.0 || ~8.2.0", + "php": "~8.1.0 || ~8.2.0", "composer-plugin-api": "^2.1.0", "andersundsehr/phpstan-git-files": "^1.0.1", "composer/semver": "^3.3.0", @@ -35,10 +35,10 @@ "symfony/yaml": "^5.4.0 || ^6.0" }, "require-dev": { - "composer/composer": "^2.4.2", + "composer/composer": "^2.5.5", "roave/security-advisories": "dev-latest", - "saschaegerer/phpstan-typo3": "^1.8.2", - "ssch/typo3-rector": "^1.1.3" + "saschaegerer/phpstan-typo3": "^1.8.5", + "ssch/typo3-rector": "^1.2.2" }, "autoload": { "psr-4": { diff --git a/rector-typo3-rule-set.php b/rector-typo3-rule-set.php new file mode 100644 index 0000000..fdbfae5 --- /dev/null +++ b/rector-typo3-rule-set.php @@ -0,0 +1,16 @@ +rules( + [ + InjectMethodToConstructorInjectionRector::class, + ConvertImplicitVariablesToExplicitGlobalsRector::class, + ] + ); +}; diff --git a/src/RectorSettings.php b/src/RectorSettings.php index 290ff35..3296b63 100644 --- a/src/RectorSettings.php +++ b/src/RectorSettings.php @@ -5,6 +5,7 @@ namespace PLUS\GrumPHPConfig; use Composer\InstalledVersions; +use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector; use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector; @@ -15,11 +16,12 @@ use Rector\CodingStyle\Rector\Switch_\BinarySwitchToIfElseRector; use Rector\Php70\Rector\Assign\ListSwapArrayOrderRector; use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector; -use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; use Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector; -use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector; +use Rector\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector; +use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; +use Rector\TypeDeclaration\Rector\BooleanAnd\BinaryOpNullableToInstanceofRector; use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictGetterMethodReturnTypeRector; use Ssch\TYPO3Rector\Rector\Migrations\RenameClassMapAliasRector; use Ssch\TYPO3Rector\Set\Typo3LevelSetList; @@ -41,34 +43,37 @@ public static function sets(bool $entirety = false): array assert(is_string($phpFile)); - return array_filter([ - // SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION, // NO - SetList::CODE_QUALITY, // YES - SetList::CODING_STYLE, // YES - SetList::DEAD_CODE, // YES - //SetList::GMAGICK_TO_IMAGICK, // NO - //SetList::MONOLOG_20, // no usage - //SetList::MYSQL_TO_MYSQLI, // no usage - //SetList::NAMING, //NO is not good - $phpFile, - //SetList::PHP_52, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //SetList::PHP_53, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //SetList::PHP_54, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //SetList::PHP_55, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //SetList::PHP_56, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //SetList::PHP_70, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //SetList::PHP_71, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //SetList::PHP_72, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //SetList::PHP_73, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //SetList::PHP_74, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... - //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 - $entirety ? SetList::PSR_4 : null, - SetList::TYPE_DECLARATION, // YES - SetList::EARLY_RETURN, //YES - ]); + return array_filter( + [ + // SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION, // NO + SetList::CODE_QUALITY, // YES + SetList::CODING_STYLE, // YES + SetList::DEAD_CODE, // YES + //SetList::GMAGICK_TO_IMAGICK, // NO + //SetList::MONOLOG_20, // no usage + //SetList::MYSQL_TO_MYSQLI, // no usage + //SetList::NAMING, //NO is not good + $phpFile, + //SetList::PHP_52, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //SetList::PHP_53, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //SetList::PHP_54, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //SetList::PHP_55, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //SetList::PHP_56, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //SetList::PHP_70, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //SetList::PHP_71, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //SetList::PHP_72, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //SetList::PHP_73, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //SetList::PHP_74, // YES, included in LevelSetList::class . '::UP_TO_PHP_' ... + //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 + $entirety ? SetList::PSR_4 : null, + SetList::TYPE_DECLARATION, // YES + SetList::EARLY_RETURN, //YES + SetList::INSTANCEOF, + ] + ); } /** @@ -109,11 +114,12 @@ public static function setsTypo3(bool $entirety = false): array assert(is_string($setList)); return [ $setList, + __DIR__ . '/../rector-typo3-rule-set.php', ]; } /** - * @return array + * @return array */ public static function skip(): array { @@ -123,6 +129,16 @@ public static function skip(): array * TO: if($object !== null) { */ NullableCompareToNullRector::class, + /** + * FROM: if ($dateTime === null) { + * TO: if (! $dateTime instanceof DateTime) { + */ + FlipTypeControlToUseExclusiveTypeRector::class, + /** + * FROM: if ($someClass && $someClass->someMethod()) { + * TO: if ($someClass instanceof SomeClass && $someClass->someMethod()) { + */ + BinaryOpNullableToInstanceofRector::class, /** * FROM: $i++ * TO: ++$i @@ -149,10 +165,23 @@ public static function skip(): array */ ChangeReadOnlyVariableWithDefaultValueToConstantRector::class, /** - * FROM: class XYZ { - * TO: final class XYZ { + * FROM: protected string $name = ''; + * TO: const NAME = ''; + * + * ignore for models so the attributes are not made to const */ - FinalizeClassesWithoutChildrenRector::class, + ChangeReadOnlyPropertyWithDefaultValueToConstantRector::class => [ + '/*/Model/*', + ], + /** + * FROM: protected string $name; + * TO: private string $name; + * + * ignore for models so the protected attributes are not made private + */ + PrivatizeFinalClassPropertyRector::class => [ + '/*/Model/*', + ], /** * DOCS: be careful, run this just once, since it can keep swapping order back and forth * => we don't do it once! @@ -163,13 +192,6 @@ public static function skip(): array * TO: 1_305_630_314 */ AddLiteralSeparatorToNumberRector::class, - /** - * Maybe to a later date? - * - * FROM: public string $username = ''; - * TO: __construct(public string $username = '') - */ - ClassPropertyAssignToConstructorPromotionRector::class, /** * Maybe to a later date? *