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-02-16 10:44:29 +07:00
|
|
|
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
|
2021-02-01 13:23:04 +07:00
|
|
|
use Rector\CodeQuality\Rector\For_\ForToForeachRector;
|
2021-03-13 01:17:32 +07:00
|
|
|
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
|
2021-06-07 12:53:24 +02:00
|
|
|
use Rector\CodeQuality\Rector\FuncCall\AddPregQuoteDelimiterRector;
|
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;
|
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;
|
2021-02-01 13:23:04 +07:00
|
|
|
use Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector;
|
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;
|
2020-09-25 10:41:42 +07:00
|
|
|
use Rector\Core\Configuration\Option;
|
2021-01-08 13:40:57 +07:00
|
|
|
use Rector\Core\ValueObject\PhpVersion;
|
2021-08-17 18:14:12 +07:00
|
|
|
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
|
|
|
|
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
|
|
|
|
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
|
|
|
|
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
|
|
|
|
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
|
|
|
|
use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector;
|
|
|
|
use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector;
|
|
|
|
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
|
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-05-24 03:46:44 +02:00
|
|
|
use Rector\Php70\Rector\Ternary\TernaryToNullCoalescingRector;
|
2021-06-23 08:19:54 +07:00
|
|
|
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
|
2021-05-26 13:29:51 +07:00
|
|
|
use Rector\Php71\Rector\List_\ListToArrayDestructRector;
|
2021-04-23 14:35:33 +07:00
|
|
|
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
|
|
|
|
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
|
|
|
|
use Rector\Set\ValueObject\SetList;
|
2020-09-25 10:41:42 +07:00
|
|
|
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
2020-10-23 19:19:47 +07:00
|
|
|
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
|
2021-05-22 09:06:19 +07:00
|
|
|
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
|
2021-06-02 10:29:44 +07:00
|
|
|
use Utils\Rector\RemoveVarTagFromClassConstantRector;
|
2020-09-28 18:56:04 +07:00
|
|
|
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;
|
2020-09-25 10:41:42 +07:00
|
|
|
|
|
|
|
return static function (ContainerConfigurator $containerConfigurator): void {
|
2021-08-17 18:14:12 +07:00
|
|
|
$containerConfigurator->import(SetList::DEAD_CODE);
|
2021-06-04 22:51:52 +08:00
|
|
|
$containerConfigurator->import(SetList::PHP_73);
|
2021-05-10 15:57:40 +07:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
$parameters = $containerConfigurator->parameters();
|
2020-09-25 10:41:42 +07:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
// paths to refactor; solid alternative to CLI arguments
|
|
|
|
$parameters->set(Option::PATHS, [__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils/Rector']);
|
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
|
|
|
|
$parameters->set(Option::BOOTSTRAP_FILES, [
|
|
|
|
__DIR__ . '/system/Test/bootstrap.php',
|
|
|
|
]);
|
2021-03-24 08:38:22 +07:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
// is there a file you need to skip?
|
|
|
|
$parameters->set(Option::SKIP, [
|
|
|
|
__DIR__ . '/app/Views',
|
|
|
|
__DIR__ . '/system/Debug/Toolbar/Views/toolbar.tpl.php',
|
|
|
|
__DIR__ . '/system/ThirdParty',
|
|
|
|
__DIR__ . '/tests/system/Config/fixtures',
|
|
|
|
__DIR__ . '/tests/_support',
|
|
|
|
JsonThrowOnErrorRector::class,
|
|
|
|
StringifyStrNeedlesRector::class,
|
2021-08-17 18:14:12 +07:00
|
|
|
|
|
|
|
// requires php 8
|
|
|
|
RemoveUnusedPromotedPropertyRector::class,
|
|
|
|
|
|
|
|
// currently buggy on call inside assign, wait for next release
|
|
|
|
RemoveParentCallWithoutParentRector::class,
|
|
|
|
|
|
|
|
// private method called via getPrivateMethodInvoker
|
|
|
|
RemoveUnusedPrivateMethodRector::class => [
|
|
|
|
__DIR__ . '/system/Entity/Entity.php',
|
|
|
|
__DIR__ . '/tests/system/Test/ReflectionHelperTest.php',
|
|
|
|
],
|
|
|
|
|
|
|
|
// call on purpose for nothing happen check
|
|
|
|
RemoveEmptyMethodCallRector::class => [
|
|
|
|
__DIR__ . '/tests',
|
|
|
|
],
|
|
|
|
|
|
|
|
// currently buggy on class implements ArrayAccess, wait for next release
|
|
|
|
RemoveDeadStmtRector::class => [
|
|
|
|
__DIR__ . '/tests/system/Cookie/CookieTest.php',
|
|
|
|
],
|
|
|
|
|
|
|
|
// check on constant compare
|
|
|
|
UnwrapFutureCompatibleIfPhpVersionRector::class => [
|
|
|
|
__DIR__ . '/system/CodeIgniter.php',
|
|
|
|
],
|
|
|
|
|
|
|
|
// check context ResponseTrait
|
|
|
|
RemoveUselessReturnTagRector::class => [
|
|
|
|
__DIR__ . '/system/HTTP/MessageTrait.php',
|
|
|
|
],
|
|
|
|
|
|
|
|
// casted to Entity via EntityTest->getCastEntity()
|
|
|
|
RecastingRemovalRector::class => [
|
|
|
|
__DIR__ . '/tests/system/Entity/EntityTest.php',
|
|
|
|
],
|
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
|
|
|
|
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
|
|
|
|
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_73);
|
2020-10-16 10:08:54 +07:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
$services = $containerConfigurator->services();
|
|
|
|
$services->load('Symplify\\PackageBuilder\\', __DIR__ . '/vendor/symplify/package-builder/src');
|
2021-05-14 20:16:31 +07:00
|
|
|
|
2021-06-04 22:51:52 +08:00
|
|
|
$services->set(UnderscoreToCamelCaseVariableNameRector::class);
|
|
|
|
$services->set(SimplifyUselessVariableRector::class);
|
|
|
|
$services->set(RemoveAlwaysElseRector::class);
|
|
|
|
$services->set(PassStrictParameterToFunctionParameterRector::class);
|
|
|
|
$services->set(CountArrayToEmptyArrayComparisonRector::class);
|
|
|
|
$services->set(ForToForeachRector::class);
|
|
|
|
$services->set(ChangeNestedForeachIfsToEarlyContinueRector::class);
|
|
|
|
$services->set(ChangeIfElseValueAssignToEarlyReturnRector::class);
|
|
|
|
$services->set(SimplifyStrposLowerRector::class);
|
|
|
|
$services->set(CombineIfRector::class);
|
|
|
|
$services->set(SimplifyIfReturnBoolRector::class);
|
|
|
|
$services->set(InlineIfToExplicitIfRector::class);
|
|
|
|
$services->set(PreparedValueToEarlyReturnRector::class);
|
|
|
|
$services->set(ShortenElseIfRector::class);
|
|
|
|
$services->set(SimplifyIfElseToTernaryRector::class);
|
|
|
|
$services->set(UnusedForeachValueToArrayKeysRector::class);
|
|
|
|
$services->set(ChangeArrayPushToArrayAssignRector::class);
|
|
|
|
$services->set(UnnecessaryTernaryExpressionRector::class);
|
|
|
|
$services->set(RemoveErrorSuppressInTryCatchStmtsRector::class);
|
|
|
|
$services->set(TernaryToNullCoalescingRector::class);
|
|
|
|
$services->set(ListToArrayDestructRector::class);
|
|
|
|
$services->set(RemoveVarTagFromClassConstantRector::class);
|
2021-06-07 12:53:24 +02:00
|
|
|
$services->set(AddPregQuoteDelimiterRector::class);
|
2021-06-09 14:12:46 +07:00
|
|
|
$services->set(SimplifyRegexPatternRector::class);
|
2021-06-23 08:19:54 +07:00
|
|
|
$services->set(RemoveExtraParametersRector::class);
|
2021-07-24 16:13:19 +07:00
|
|
|
$services->set(FuncGetArgsToVariadicParamRector::class);
|
2021-07-26 09:37:09 +07:00
|
|
|
$services->set(MakeInheritedMethodVisibilitySameAsParentRector::class);
|
2020-09-25 10:41:42 +07:00
|
|
|
};
|