Skip to content

Commit

Permalink
✨ update rector config (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanti authored May 16, 2023
1 parent a925c6a commit 67ec2c9
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 46 deletions.
1 change: 0 additions & 1 deletion .github/workflows/run-grumphp-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ jobs:
fail-fast: false
matrix:
php:
- '8.0'
- '8.1'
- '8.2'
container:
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": {
Expand Down
16 changes: 16 additions & 0 deletions rector-typo3-rule-set.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

use Ssch\TYPO3Rector\Rector\General\InjectMethodToConstructorInjectionRector;
use Ssch\TYPO3Rector\Rector\General\ConvertImplicitVariablesToExplicitGlobalsRector;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules(
[
InjectMethodToConstructorInjectionRector::class,
ConvertImplicitVariablesToExplicitGlobalsRector::class,
]
);
};
104 changes: 63 additions & 41 deletions src/RectorSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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,
]
);
}

/**
Expand Down Expand Up @@ -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<int, string>
* @return array<string|string[]>
*/
public static function skip(): array
{
Expand All @@ -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
Expand All @@ -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!
Expand All @@ -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?
*
Expand Down

0 comments on commit 67ec2c9

Please sign in to comment.