2020-09-25 10:41:42 +07:00
|
|
|
<?php
|
|
|
|
|
2023-10-22 15:23:05 +09:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2024-03-24 02:06:21 +07:00
|
|
|
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
|
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-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;
|
2024-04-03 22:25:35 +07:00
|
|
|
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
|
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;
|
2024-03-11 22:52:34 +01:00
|
|
|
use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector;
|
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;
|
2024-02-06 09:14:58 +09:00
|
|
|
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
|
2023-12-21 11:35:19 +09:00
|
|
|
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
|
|
|
|
use Rector\Php80\Rector\FunctionLike\MixedTypeRector;
|
|
|
|
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
|
2024-02-06 09:14:58 +09:00
|
|
|
use Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector;
|
|
|
|
use Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\CoversAnnotationWithValueToAttributeRector;
|
|
|
|
use Rector\PHPUnit\AnnotationsToAttributes\Rector\ClassMethod\DataProviderAnnotationToAttributeRector;
|
|
|
|
use Rector\PHPUnit\AnnotationsToAttributes\Rector\ClassMethod\DependsAnnotationWithValueToAttributeRector;
|
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;
|
2023-12-18 09:02:59 +09:00
|
|
|
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
|
2023-09-18 14:49:59 +07:00
|
|
|
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
|
2023-12-21 11:35:19 +09:00
|
|
|
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
|
2024-06-27 22:19:28 +07:00
|
|
|
use Rector\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector;
|
2023-12-18 08:57:56 +09:00
|
|
|
use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector;
|
2023-10-30 12:58:52 +09:00
|
|
|
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
|
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
|
|
|
|
2024-06-26 00:36:20 +07:00
|
|
|
return RectorConfig::configure()
|
|
|
|
->withPhpSets(php81: true)
|
|
|
|
->withPreparedSets(deadCode: true)
|
|
|
|
->withSets([
|
2023-09-06 18:22:17 +09:00
|
|
|
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
|
2023-09-07 15:51:15 +09:00
|
|
|
PHPUnitSetList::PHPUNIT_100,
|
2024-06-26 00:36:20 +07:00
|
|
|
])
|
|
|
|
->withParallel(120, 8, 10)
|
|
|
|
->withCache(
|
|
|
|
// Github action cache or local
|
2024-06-26 07:36:11 +07:00
|
|
|
is_dir('/tmp') ? '/tmp/rector' : null,
|
2024-06-26 00:36:20 +07:00
|
|
|
FileCacheStorage::class
|
|
|
|
)
|
2021-06-04 22:51:52 +08:00
|
|
|
// paths to refactor; solid alternative to CLI arguments
|
2024-06-26 00:36:20 +07:00
|
|
|
->withPaths(
|
|
|
|
[__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils']
|
|
|
|
)
|
2021-06-04 22:51:52 +08:00
|
|
|
// do you need to include constants, class aliases or custom autoloader? files listed will be executed
|
2024-06-26 00:36:20 +07:00
|
|
|
->withBootstrapFiles([
|
2021-06-04 22:51:52 +08:00
|
|
|
__DIR__ . '/system/Test/bootstrap.php',
|
2024-06-26 00:36:20 +07:00
|
|
|
])
|
|
|
|
->withPHPStanConfigs([
|
2023-09-11 15:24:28 +08:00
|
|
|
__DIR__ . '/phpstan.neon.dist',
|
|
|
|
__DIR__ . '/vendor/codeigniter/phpstan-codeigniter/extension.neon',
|
|
|
|
__DIR__ . '/vendor/phpstan/phpstan-strict-rules/rules.neon',
|
2024-06-26 00:36:20 +07:00
|
|
|
])
|
2021-06-04 22:51:52 +08:00
|
|
|
// is there a file you need to skip?
|
2024-06-26 00:36:20 +07:00
|
|
|
->withSkip([
|
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',
|
2023-12-08 09:31:02 +09:00
|
|
|
__DIR__ . '/tests/_support/Commands/Foobar.php',
|
|
|
|
__DIR__ . '/tests/_support/View',
|
|
|
|
|
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-12-08 09:31:02 +09:00
|
|
|
__DIR__ . '/tests/_support/Test/TestForReflectionHelper.php',
|
2021-08-17 18:14:12 +07:00
|
|
|
],
|
|
|
|
|
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-11-03 17:01:30 +09:00
|
|
|
__DIR__ . '/system/HTTP/Response.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
|
|
|
UnderscoreToCamelCaseVariableNameRector::class => [
|
2023-12-29 10:48:35 +09:00
|
|
|
// session handlers have the gc() method with underscored parameter `$max_lifetime`
|
2021-08-19 22:59:20 +08:00
|
|
|
__DIR__ . '/system/Session/Handlers',
|
2023-12-29 10:48:35 +09:00
|
|
|
__DIR__ . '/tests/_support/Entity/CustomUser.php',
|
2021-08-19 22:59:20 +08:00
|
|
|
],
|
2021-10-25 14:35:29 +07:00
|
|
|
|
2023-10-30 12:58:52 +09:00
|
|
|
DeclareStrictTypesRector::class => [
|
|
|
|
__DIR__ . '/app',
|
|
|
|
__DIR__ . '/system/CodeIgniter.php',
|
|
|
|
__DIR__ . '/system/Config/BaseConfig.php',
|
|
|
|
__DIR__ . '/system/Commands/Generators/Views',
|
|
|
|
__DIR__ . '/system/Pager/Views',
|
|
|
|
__DIR__ . '/system/Test/ControllerTestTrait.php',
|
|
|
|
__DIR__ . '/system/Validation/Views',
|
|
|
|
__DIR__ . '/system/View/Parser.php',
|
|
|
|
__DIR__ . '/tests/system/Debug/ExceptionsTest.php',
|
|
|
|
__DIR__ . '/tests/system/View/Views',
|
|
|
|
],
|
|
|
|
|
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-12-21 11:35:19 +09:00
|
|
|
// PHP 8.0 features but cause breaking changes
|
|
|
|
ClassPropertyAssignToConstructorPromotionRector::class => [
|
|
|
|
__DIR__ . '/system/Database/BaseResult.php',
|
|
|
|
__DIR__ . '/system/Database/RawSql.php',
|
|
|
|
__DIR__ . '/system/Debug/BaseExceptionHandler.php',
|
|
|
|
__DIR__ . '/system/Filters/Filters.php',
|
|
|
|
__DIR__ . '/system/HTTP/CURLRequest.php',
|
|
|
|
__DIR__ . '/system/HTTP/DownloadResponse.php',
|
|
|
|
__DIR__ . '/system/HTTP/IncomingRequest.php',
|
|
|
|
__DIR__ . '/system/Security/Security.php',
|
|
|
|
__DIR__ . '/system/Session/Session.php',
|
|
|
|
],
|
|
|
|
MixedTypeRector::class,
|
|
|
|
|
|
|
|
ReturnNeverTypeRector::class => [
|
|
|
|
__DIR__ . '/system/Cache/Handlers/BaseHandler.php',
|
|
|
|
__DIR__ . '/system/Cache/Handlers/MemcachedHandler.php',
|
|
|
|
__DIR__ . '/system/Cache/Handlers/WincacheHandler.php',
|
|
|
|
__DIR__ . '/system/CodeIgniter.php',
|
|
|
|
__DIR__ . '/system/Database/MySQLi/Utils.php',
|
|
|
|
__DIR__ . '/system/Database/OCI8/Utils.php',
|
|
|
|
__DIR__ . '/system/Database/Postgre/Utils.php',
|
|
|
|
__DIR__ . '/system/Database/SQLSRV/Utils.php',
|
|
|
|
__DIR__ . '/system/Database/SQLite3/Utils.php',
|
|
|
|
__DIR__ . '/system/HTTP/DownloadResponse.php',
|
|
|
|
__DIR__ . '/system/HTTP/SiteURI.php',
|
|
|
|
__DIR__ . '/system/Helpers/kint_helper.php',
|
2024-03-30 18:02:33 +09:00
|
|
|
__DIR__ . '/tests/_support/Autoloader/FatalLocator.php',
|
2023-12-21 11:35:19 +09:00
|
|
|
],
|
|
|
|
|
|
|
|
// Unnecessary (string) is inserted
|
|
|
|
NullToStrictStringFuncCallArgRector::class,
|
|
|
|
|
2024-02-06 09:14:58 +09:00
|
|
|
// PHPUnit 10 (requires PHP 8.1) features
|
|
|
|
DataProviderAnnotationToAttributeRector::class,
|
|
|
|
DependsAnnotationWithValueToAttributeRector::class,
|
|
|
|
AnnotationWithValueToAttributeRector::class,
|
|
|
|
AnnotationToAttributeRector::class,
|
|
|
|
CoversAnnotationWithValueToAttributeRector::class,
|
2024-06-26 00:36:20 +07:00
|
|
|
])
|
2021-06-04 22:51:52 +08:00
|
|
|
// auto import fully qualified class names
|
2024-06-26 00:36:20 +07:00
|
|
|
->withImportNames(removeUnusedImports: true)
|
|
|
|
->withRules([
|
|
|
|
DeclareStrictTypesRector::class,
|
|
|
|
UnderscoreToCamelCaseVariableNameRector::class,
|
|
|
|
SimplifyUselessVariableRector::class,
|
|
|
|
RemoveAlwaysElseRector::class,
|
|
|
|
PassStrictParameterToFunctionParameterRector::class,
|
|
|
|
CountArrayToEmptyArrayComparisonRector::class,
|
|
|
|
ChangeNestedForeachIfsToEarlyContinueRector::class,
|
|
|
|
ChangeIfElseValueAssignToEarlyReturnRector::class,
|
|
|
|
SimplifyStrposLowerRector::class,
|
|
|
|
CombineIfRector::class,
|
|
|
|
SimplifyIfReturnBoolRector::class,
|
|
|
|
InlineIfToExplicitIfRector::class,
|
|
|
|
PreparedValueToEarlyReturnRector::class,
|
|
|
|
ShortenElseIfRector::class,
|
|
|
|
SimplifyIfElseToTernaryRector::class,
|
|
|
|
UnusedForeachValueToArrayKeysRector::class,
|
|
|
|
ChangeArrayPushToArrayAssignRector::class,
|
|
|
|
UnnecessaryTernaryExpressionRector::class,
|
|
|
|
RemoveErrorSuppressInTryCatchStmtsRector::class,
|
|
|
|
FuncGetArgsToVariadicParamRector::class,
|
|
|
|
MakeInheritedMethodVisibilitySameAsParentRector::class,
|
|
|
|
SimplifyEmptyArrayCheckRector::class,
|
|
|
|
SimplifyEmptyCheckOnEmptyArrayRector::class,
|
|
|
|
TernaryEmptyArrayArrayDimFetchToCoalesceRector::class,
|
|
|
|
EmptyOnNullableObjectToInstanceOfRector::class,
|
|
|
|
DisallowedEmptyRuleFixerRector::class,
|
|
|
|
PrivatizeFinalClassPropertyRector::class,
|
|
|
|
CompleteDynamicPropertiesRector::class,
|
|
|
|
BooleanInIfConditionRuleFixerRector::class,
|
|
|
|
SingleInArrayToCompareRector::class,
|
|
|
|
VersionCompareFuncCallToConstantRector::class,
|
|
|
|
ExplicitBoolCompareRector::class,
|
2024-06-27 22:19:28 +07:00
|
|
|
AddClosureVoidReturnTypeWhereNoReturnRector::class,
|
2024-06-26 00:36:20 +07:00
|
|
|
])
|
|
|
|
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
|
|
|
|
// keep '\\' prefix string on string '\Foo\Bar'
|
|
|
|
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true,
|
|
|
|
]);
|