-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from kenjis/chore-add-rector
refactor: add Rector and refactor
- Loading branch information
Showing
11 changed files
with
169 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of Shield OAuth. | ||
* | ||
* (c) Datamweb <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector; | ||
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; | ||
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector; | ||
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector; | ||
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector; | ||
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector; | ||
use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector; | ||
use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; | ||
use Rector\CodeQuality\Rector\If_\CombineIfRector; | ||
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; | ||
use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; | ||
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector; | ||
use Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector; | ||
use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector; | ||
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; | ||
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; | ||
use Rector\Config\RectorConfig; | ||
use Rector\Core\ValueObject\PhpVersion; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector; | ||
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector; | ||
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector; | ||
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; | ||
use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector; | ||
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; | ||
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; | ||
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; | ||
use Rector\PHPUnit\Set\PHPUnitSetList; | ||
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; | ||
use Rector\Set\ValueObject\LevelSetList; | ||
use Rector\Set\ValueObject\SetList; | ||
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->sets([ | ||
SetList::DEAD_CODE, | ||
LevelSetList::UP_TO_PHP_74, | ||
PHPUnitSetList::PHPUNIT_CODE_QUALITY, | ||
PHPUnitSetList::PHPUNIT_100, | ||
]); | ||
|
||
$rectorConfig->parallel(); | ||
|
||
// The paths to refactor (can also be supplied with CLI arguments) | ||
$rectorConfig->paths([ | ||
__DIR__ . '/src/', | ||
// __DIR__ . '/tests/', | ||
]); | ||
|
||
// Include Composer's autoload - required for global execution, remove if running locally | ||
$rectorConfig->autoloadPaths([ | ||
__DIR__ . '/vendor/autoload.php', | ||
]); | ||
|
||
// Do you need to include constants, class aliases, or a custom autoloader? | ||
$rectorConfig->bootstrapFiles([ | ||
realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php', | ||
]); | ||
|
||
if (is_file(__DIR__ . '/phpstan.neon.dist')) { | ||
$rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist'); | ||
} | ||
|
||
// Set the target version for refactoring | ||
$rectorConfig->phpVersion(PhpVersion::PHP_74); | ||
|
||
// Auto-import fully qualified class names | ||
$rectorConfig->importNames(); | ||
|
||
// Are there files or rules you need to skip? | ||
$rectorConfig->skip([ | ||
__DIR__ . '/app/Views', | ||
|
||
JsonThrowOnErrorRector::class, | ||
StringifyStrNeedlesRector::class, | ||
|
||
// Note: requires php 8 | ||
RemoveUnusedPromotedPropertyRector::class, | ||
|
||
// May load view files directly when detecting classes | ||
StringClassNameToClassConstantRector::class, | ||
|
||
TypedPropertyFromAssignsRector::class => [ | ||
__DIR__ . '/src/Commands/OAuthSetup.php', | ||
__DIR__ . '/src/Commands/Generators/NewShieldOauthGenerator.php', | ||
], | ||
]); | ||
|
||
// auto import fully qualified class names | ||
$rectorConfig->importNames(); | ||
|
||
$rectorConfig->rule(SimplifyUselessVariableRector::class); | ||
$rectorConfig->rule(RemoveAlwaysElseRector::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(SimplifyRegexPatternRector::class); | ||
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class); | ||
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); | ||
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); | ||
$rectorConfig | ||
->ruleWithConfiguration(TypedPropertyFromAssignsRector::class, [ | ||
/** | ||
* The INLINE_PUBLIC value is default to false to avoid BC break, if you use for libraries and want to preserve BC break, you don't need to configure it, as it included in LevelSetList::UP_TO_PHP_74 | ||
* Set to true for projects that allow BC break | ||
*/ | ||
TypedPropertyFromAssignsRector::INLINE_PUBLIC => true, | ||
]); | ||
$rectorConfig->rule(StringClassNameToClassConstantRector::class); | ||
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); | ||
$rectorConfig->rule(CompleteDynamicPropertiesRector::class); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.