2020-09-25 10:41:42 +07:00
|
|
|
<?php
|
|
|
|
|
2021-07-19 21:32:33 +08:00
|
|
|
/**
|
|
|
|
* This file is part of CodeIgniter 4 framework.
|
|
|
|
*
|
|
|
|
* (c) CodeIgniter Foundation <admin@codeigniter.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view
|
|
|
|
* the LICENSE file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2021-09-17 05:11:14 +07:00
|
|
|
use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector;
|
2022-06-27 18:24:07 +09:00
|
|
|
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
|
2023-12-17 17:30:15 +09:00
|
|
|
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
|
2021-02-16 10:44:29 +07:00
|
|
|
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
|
2021-03-13 01:17:32 +07:00
|
|
|
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
|
2021-04-12 20:44:31 +07:00
|
|
|
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
|
2021-06-09 14:12:46 +07:00
|
|
|
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
|
2021-02-04 22:55:38 +07:00
|
|
|
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector;
|
2023-10-27 13:22:26 +07:00
|
|
|
use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector;
|
2022-04-19 18:55:03 +07:00
|
|
|
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector;
|
2021-02-05 16:07:12 +07:00
|
|
|
use Rector\CodeQuality\Rector\If_\CombineIfRector;
|
2021-02-25 11:11:12 +07:00
|
|
|
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
|
2021-03-12 13:37:57 +07:00
|
|
|
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector;
|
2021-02-06 12:24:49 +07:00
|
|
|
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
|
2023-12-18 08:54:06 +09:00
|
|
|
use Rector\CodeQuality\Rector\Ternary\TernaryEmptyArrayArrayDimFetchToCoalesceRector;
|
2021-04-13 01:57:54 +07:00
|
|
|
use Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector;
|
2021-07-24 16:13:19 +07:00
|
|
|
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector;
|
2021-07-26 09:37:09 +07:00
|
|
|
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
|
2021-02-26 08:30:35 +07:00
|
|
|
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
|
2022-04-18 22:15:59 +07:00
|
|
|
use Rector\Config\RectorConfig;
|
2023-02-09 08:46:23 +09:00
|
|
|
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
|
2021-08-17 18:14:12 +07:00
|
|
|
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
|
|
|
|
use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector;
|
2021-02-02 02:39:20 +07:00
|
|
|
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
|
2021-02-02 15:08:32 +07:00
|
|
|
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
|
2021-02-26 08:30:35 +07:00
|
|
|
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
|
2021-02-22 19:48:58 +07:00
|
|
|
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector;
|
2021-10-25 14:35:29 +07:00
|
|
|
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
|
|
|
|
use Rector\Php70\Rector\FuncCall\RandomFunctionRector;
|
2021-04-23 14:35:33 +07:00
|
|
|
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
|
2023-09-06 18:22:17 +09:00
|
|
|
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
|
2021-11-14 10:20:51 +09:00
|
|
|
use Rector\PHPUnit\Set\PHPUnitSetList;
|
2022-04-29 01:32:05 +07:00
|
|
|
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
|
2021-10-25 14:35:29 +07:00
|
|
|
use Rector\Set\ValueObject\LevelSetList;
|
2021-04-23 14:35:33 +07:00
|
|
|
use Rector\Set\ValueObject\SetList;
|
2023-09-18 14:49:59 +07:00
|
|
|
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
|
2020-10-23 19:19:47 +07:00
|
|
|
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
|
2021-05-22 09:06:19 +07:00
|
|
|
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
|
2020-09-28 18:56:04 +07:00
|
|
|
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;
|
2020-09-25 10:41:42 +07:00
|
|
|
|
2022-04-18 22:15:59 +07:00
|
|
|
return static function (RectorConfig $rectorConfig): void {
|
|
|
|
$rectorConfig->sets([
|
|
|
|
SetList::DEAD_CODE,
|
|
|
|
LevelSetList::UP_TO_PHP_74,
|
2023-09-06 18:22:17 +09:00
|
|
|
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
|
2023-09-07 15:51:15 +09:00
|
|
|
PHPUnitSetList::PHPUNIT_100,
|
2022-04-18 22:15:59 +07:00
|
|
|
]);
|
2021-05-10 15:57:40 +07:00
|
|
|
|
2023-09-13 22:35:47 +07:00
|
|
|
$rectorConfig->parallel();
|
2020-09-25 10:41:42 +07:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
// paths to refactor; solid alternative to CLI arguments
|
2022-07-03 11:35:07 +07:00
|
|
|
$rectorConfig->paths([__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils']);
|
2020-09-25 10:41:42 +07:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
// do you need to include constants, class aliases or custom autoloader? files listed will be executed
|
2022-04-18 22:15:59 +07:00
|
|
|
$rectorConfig->bootstrapFiles([
|
2021-06-04 22:51:52 +08:00
|
|
|
__DIR__ . '/system/Test/bootstrap.php',
|
|
|
|
]);
|
2021-03-24 08:38:22 +07:00
|
|
|
|
2023-09-11 15:24:28 +08:00
|
|
|
$rectorConfig->phpstanConfigs([
|
|
|
|
__DIR__ . '/phpstan.neon.dist',
|
|
|
|
__DIR__ . '/vendor/codeigniter/phpstan-codeigniter/extension.neon',
|
|
|
|
__DIR__ . '/vendor/phpstan/phpstan-strict-rules/rules.neon',
|
|
|
|
]);
|
2022-07-26 19:28:02 +07:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
// is there a file you need to skip?
|
2022-04-18 22:15:59 +07:00
|
|
|
$rectorConfig->skip([
|
2021-06-04 22:51:52 +08:00
|
|
|
__DIR__ . '/system/Debug/Toolbar/Views/toolbar.tpl.php',
|
|
|
|
__DIR__ . '/system/ThirdParty',
|
|
|
|
__DIR__ . '/tests/system/Config/fixtures',
|
2023-02-28 23:08:25 +07:00
|
|
|
__DIR__ . '/tests/system/Filters/fixtures',
|
2021-06-04 22:51:52 +08:00
|
|
|
__DIR__ . '/tests/_support',
|
|
|
|
JsonThrowOnErrorRector::class,
|
2023-09-06 18:22:17 +09:00
|
|
|
YieldDataProviderRector::class,
|
2021-08-17 18:14:12 +07:00
|
|
|
|
|
|
|
RemoveUnusedPrivateMethodRector::class => [
|
2022-02-08 10:27:52 +09:00
|
|
|
// private method called via getPrivateMethodInvoker
|
2021-08-17 18:14:12 +07:00
|
|
|
__DIR__ . '/tests/system/Test/ReflectionHelperTest.php',
|
|
|
|
],
|
|
|
|
|
2023-02-09 08:46:23 +09:00
|
|
|
RemoveUnusedConstructorParamRector::class => [
|
|
|
|
// there are deprecated parameters
|
|
|
|
__DIR__ . '/system/Debug/Exceptions.php',
|
2023-06-08 08:10:45 +09:00
|
|
|
// @TODO remove if deprecated $httpVerb is removed
|
|
|
|
__DIR__ . '/system/Router/AutoRouterImproved.php',
|
2023-06-26 20:37:41 +09:00
|
|
|
// @TODO remove if deprecated $config is removed
|
|
|
|
__DIR__ . '/system/HTTP/Request.php',
|
2023-02-09 08:46:23 +09:00
|
|
|
],
|
|
|
|
|
2021-08-17 18:14:12 +07:00
|
|
|
// check on constant compare
|
|
|
|
UnwrapFutureCompatibleIfPhpVersionRector::class => [
|
2022-07-01 16:54:55 +09:00
|
|
|
__DIR__ . '/system/Autoloader/Autoloader.php',
|
2021-08-17 18:14:12 +07:00
|
|
|
],
|
|
|
|
|
2021-08-19 22:59:20 +08:00
|
|
|
// session handlers have the gc() method with underscored parameter `$max_lifetime`
|
|
|
|
UnderscoreToCamelCaseVariableNameRector::class => [
|
|
|
|
__DIR__ . '/system/Session/Handlers',
|
|
|
|
],
|
2021-10-25 14:35:29 +07:00
|
|
|
|
|
|
|
// use mt_rand instead of random_int on purpose on non-cryptographically random
|
|
|
|
RandomFunctionRector::class,
|
2022-07-01 15:33:56 +09:00
|
|
|
|
2023-06-15 09:50:44 +07:00
|
|
|
SimplifyRegexPatternRector::class,
|
2021-06-04 22:51:52 +08:00
|
|
|
]);
|
2020-09-25 10:41:42 +07:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
// auto import fully qualified class names
|
2022-04-18 22:15:59 +07:00
|
|
|
$rectorConfig->importNames();
|
2023-10-16 06:59:56 +07:00
|
|
|
$rectorConfig->removeUnusedImports();
|
2022-04-18 22:15:59 +07:00
|
|
|
|
|
|
|
$rectorConfig->rule(UnderscoreToCamelCaseVariableNameRector::class);
|
2022-04-19 18:55:03 +07:00
|
|
|
$rectorConfig->rule(SimplifyUselessVariableRector::class);
|
2022-04-18 22:15:59 +07:00
|
|
|
$rectorConfig->rule(RemoveAlwaysElseRector::class);
|
|
|
|
$rectorConfig->rule(PassStrictParameterToFunctionParameterRector::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(RemoveErrorSuppressInTryCatchStmtsRector::class);
|
|
|
|
$rectorConfig->rule(SimplifyRegexPatternRector::class);
|
|
|
|
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
|
|
|
|
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
|
|
|
|
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
|
2023-12-17 17:30:15 +09:00
|
|
|
$rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class);
|
2023-12-18 08:54:06 +09:00
|
|
|
$rectorConfig->rule(TernaryEmptyArrayArrayDimFetchToCoalesceRector::class);
|
2022-09-29 02:41:44 +07:00
|
|
|
$rectorConfig->rule(StringClassNameToClassConstantRector::class);
|
2022-04-29 01:32:05 +07:00
|
|
|
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
|
2022-06-27 18:24:07 +09:00
|
|
|
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
|
2023-09-18 14:49:59 +07:00
|
|
|
$rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class);
|
2023-10-27 13:22:26 +07:00
|
|
|
$rectorConfig->rule(SingleInArrayToCompareRector::class);
|
2020-09-25 10:41:42 +07:00
|
|
|
};
|