Skip to content

Instantly share code, notes, and snippets.

@lucaslz
Forked from u01jmg3/rector-codeigniter.php
Created December 12, 2022 16:36
Show Gist options
  • Save lucaslz/173210ae0305ed3898ff5762684ea988 to your computer and use it in GitHub Desktop.
Save lucaslz/173210ae0305ed3898ff5762684ea988 to your computer and use it in GitHub Desktop.
Rector configs
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php53\Rector\Ternary\TernaryToElvisRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
// rector process application --config=rector-codeigniter.php
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_56); // PhpVersion::PHP_74
$parameters->set(Option::AUTOLOAD_PATHS, [
'../composer_plugins/autoload.php', # __DIR__ . '/vendor/autoload.php',
'system/core',
'system/libraries',
'application/core',
'application/controllers',
'application/libraries',
'application/migrations',
'application/models',
'rector.php', # Create from `src/index.php` without the code for configuring environments
]);
$parameters->set(Option::SKIP, [
// Rectors
Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector::class,
Rector\CodeQuality\Rector\Concat\JoinStringConcatRector::class,
Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector::class,
Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector::class,
Rector\CodeQuality\Rector\FuncCall\IntvalToTypeCastRector::class,
Rector\CodeQuality\Rector\Identical\BooleanNotIdenticalToNotIdenticalRector::class,
Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector::class,
Rector\CodeQuality\Rector\If_\CombineIfRector::class,
Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector::class,
Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector::class,
Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector::class,
Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector::class,
Rector\CodeQuality\Rector\PropertyFetch\ExplicitMethodCallOverMagicGetSetRector::class,
Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector::class,
Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector::class,
Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector::class,
Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector::class,
Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector::class,
Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector::class,
Rector\Php70\Rector\FuncCall\NonVariableToVariableOnFunctionCallRector::class,
Rector\Php70\Rector\MethodCall\ThisCallOnStaticMethodToStaticCallRector::class,
Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector::class,
Rector\Php71\Rector\FuncCall\CountOnNullRector::class,
Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector::class,
Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector::class,
Rector\Php74\Rector\Property\TypedPropertyRector::class,
Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector::class,
Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector::class,
Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector::class,
Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector::class,
Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector::class,
Rector\CodeQuality\Rector\ClassMethod\DateTimeToDateTimeInterfaceRector::class,
Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector::class,
Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector::class,
Rector\Transform\Rector\String_\StringToClassConstantRector::class,
// PHP 5.6 incompatible
Rector\CodeQuality\Rector\Ternary\ArrayKeyExistsTernaryThenValueToCoalescingRector::class, // PHP 7
Rector\Php70\Rector\If_\IfToSpaceshipRector::class,
Rector\Php70\Rector\Ternary\TernaryToSpaceshipRector::class,
Rector\Php71\Rector\BooleanOr\IsIterableRector::class,
Rector\Php71\Rector\List_\ListToArrayDestructRector::class,
Rector\Php71\Rector\TryCatch\MultiExceptionCatchRector::class,
Rector\Php73\Rector\FuncCall\ArrayKeyFirstLastRector::class,
Rector\Php73\Rector\BooleanOr\IsCountableRector::class,
Rector\Php74\Rector\Assign\NullCoalescingOperatorRector::class,
Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector::class,
Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector::class,
Rector\Php74\Rector\MethodCall\ChangeReflectionTypeToStringToGetNameRector::class,
Rector\Php74\Rector\StaticCall\ExportToReflectionFunctionRector::class,
Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector::class, // PHP 8
// Paths
'application\views\templates',
]);
$parameters->set(Option::PATHS, [
'application\config',
'application\controllers',
'application\core',
'application\helpers',
'application\migrations',
'application\models',
'application\views',
]);
$containerConfigurator->import(SetList::CODE_QUALITY);
$containerConfigurator->import(SetList::CODING_STYLE);
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PHP_70);
$containerConfigurator->import(SetList::PHP_71);
$containerConfigurator->import(SetList::PHP_72);
$containerConfigurator->import(SetList::PHP_73);
$containerConfigurator->import(SetList::PHP_74);
$services = $containerConfigurator->services();
$services->set(TernaryToElvisRector::class);
};
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Laravel\Set\LaravelSetList;
use Rector\Php53\Rector\Ternary\TernaryToElvisRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
// rector process app --config=rector-laravel.php
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_56); // PhpVersion::PHP_74
$parameters->set(Option::AUTOLOAD_PATHS, [__DIR__ . '/vendor/autoload.php']);
$parameters->set(Option::SKIP, [
// Rectors
Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector::class,
Rector\CodeQuality\Rector\Concat\JoinStringConcatRector::class,
Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector::class,
Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector::class,
Rector\CodeQuality\Rector\FuncCall\IntvalToTypeCastRector::class,
Rector\CodeQuality\Rector\Identical\BooleanNotIdenticalToNotIdenticalRector::class,
Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector::class,
Rector\CodeQuality\Rector\If_\CombineIfRector::class,
Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector::class,
Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector::class,
Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector::class,
Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector::class,
Rector\CodeQuality\Rector\PropertyFetch\ExplicitMethodCallOverMagicGetSetRector::class,
Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector::class,
Rector\CodingStyle\Rector\ClassConst\VarConstantCommentRector::class,
Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector::class,
Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector::class,
Rector\CodingStyle\Rector\String_\SymplifyQuoteEscapeRector::class,
Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector::class,
Rector\Php70\Rector\FuncCall\NonVariableToVariableOnFunctionCallRector::class,
Rector\Php70\Rector\MethodCall\ThisCallOnStaticMethodToStaticCallRector::class,
Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector::class,
Rector\Php71\Rector\FuncCall\CountOnNullRector::class,
Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector::class,
Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector::class,
Rector\Php74\Rector\Property\TypedPropertyRector::class,
Rector\TypeDeclaration\Rector\FunctionLike\ParamTypeDeclarationRector::class,
Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector::class,
Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector::class,
Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector::class,
Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector::class,
Rector\CodeQuality\Rector\ClassMethod\DateTimeToDateTimeInterfaceRector::class,
Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector::class,
Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector::class,
Rector\Transform\Rector\String_\StringToClassConstantRector::class,
// PHP 5.6 incompatible
Rector\CodeQuality\Rector\Ternary\ArrayKeyExistsTernaryThenValueToCoalescingRector::class, // PHP 7
Rector\Php70\Rector\If_\IfToSpaceshipRector::class,
Rector\Php70\Rector\Ternary\TernaryToSpaceshipRector::class,
Rector\Php71\Rector\BooleanOr\IsIterableRector::class,
Rector\Php71\Rector\List_\ListToArrayDestructRector::class,
Rector\Php71\Rector\TryCatch\MultiExceptionCatchRector::class,
Rector\Php73\Rector\FuncCall\ArrayKeyFirstLastRector::class,
Rector\Php73\Rector\BooleanOr\IsCountableRector::class,
Rector\Php74\Rector\Assign\NullCoalescingOperatorRector::class,
Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector::class,
Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector::class,
Rector\Php74\Rector\MethodCall\ChangeReflectionTypeToStringToGetNameRector::class,
Rector\Php74\Rector\StaticCall\ExportToReflectionFunctionRector::class,
Rector\CodingStyle\Rector\ClassConst\RemoveFinalFromConstRector::class, // PHP 8
// Paths
'app\Console\Kernel.php',
'app\Exceptions\Handler.php',
'app\Http\Kernel.php',
]);
$parameters->set(Option::PATHS, [
'app\Auth',
'app\Console',
'app\Events',
'app\Exceptions',
'app\Helpers',
'app\Http',
'app\Listeners',
'app\Mail',
'app\Models',
'app\Notifications',
'app\Observers',
'app\Providers',
'app\Repositories',
'app\Sanitizers',
'app\Services',
'app\Validators',
]);
$containerConfigurator->import(SetList::CODE_QUALITY);
$containerConfigurator->import(SetList::CODING_STYLE);
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(LaravelSetList::LARAVEL_50);
$containerConfigurator->import(LaravelSetList::LARAVEL_51);
$containerConfigurator->import(LaravelSetList::LARAVEL_52);
$containerConfigurator->import(LaravelSetList::LARAVEL_53);
$containerConfigurator->import(LaravelSetList::LARAVEL_54);
$containerConfigurator->import(SetList::PHP_70);
$containerConfigurator->import(SetList::PHP_71);
$containerConfigurator->import(SetList::PHP_72);
$containerConfigurator->import(SetList::PHP_73);
$containerConfigurator->import(SetList::PHP_74);
$services = $containerConfigurator->services();
$services->set(TernaryToElvisRector::class);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment