-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Rector for code quality enhancements (#26)
A new PHP file, `rector.php`, has been introduced for using the Rector tool, which is set up to apply a variety of automated refactoring and code quality improvement rules. In addition, Rector has been added as a dependency in the `composer.json` file and included in the project's testing scripts and GitHub workflow. This tool helps in improving the codebase and maintaining a robust code quality standard.
- Loading branch information
1 parent
99587f9
commit e062884
Showing
4 changed files
with
82 additions
and
8 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,71 @@ | ||
<?php | ||
|
||
/** | ||
* @noinspection DevelopmentDependenciesUsageInspection | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector; | ||
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector; | ||
use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector; | ||
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector; | ||
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector; | ||
use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector; | ||
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector; | ||
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; | ||
use Rector\CodingStyle\Rector\Use_\SeparateMultiUseImportsRector; | ||
use Rector\Config\RectorConfig; | ||
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchExprVariableRector; | ||
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector; | ||
use Rector\Set\ValueObject\LevelSetList; | ||
use Rector\Set\ValueObject\SetList; | ||
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector; | ||
use Rector\ValueObject\PhpVersion; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->bootstrapFiles([__DIR__ . '/vendor/autoload.php']); | ||
|
||
$rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/tests']); | ||
|
||
// register a single rule | ||
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class); | ||
$rectorConfig->rule(RenameForeachValueVariableToMatchExprVariableRector::class); | ||
$rectorConfig->rule(RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class); | ||
$rectorConfig->rule(TypedPropertyFromStrictConstructorRector::class); | ||
$rectorConfig->rule(NullableCompareToNullRector::class); | ||
$rectorConfig->rule(EncapsedStringsToSprintfRector::class); | ||
$rectorConfig->rule(NewlineAfterStatementRector::class); | ||
$rectorConfig->rule(NewlineBeforeNewAssignSetRector::class); | ||
$rectorConfig->rule(PostIncDecToPreIncDecRector::class); | ||
$rectorConfig->rule(SeparateMultiUseImportsRector::class); | ||
$rectorConfig->rule(SplitDoubleAssignRector::class); | ||
|
||
$rectorConfig->phpVersion(PhpVersion::PHP_81); | ||
|
||
// define sets of rules | ||
$rectorConfig->sets( | ||
[ | ||
LevelSetList::UP_TO_PHP_81, | ||
SetList::CODE_QUALITY, | ||
SetList::CODING_STYLE, | ||
SetList::DEAD_CODE, | ||
SetList::EARLY_RETURN, | ||
SetList::PHP_81, | ||
SetList::TYPE_DECLARATION, | ||
SetList::NAMING, | ||
SetList::PRIVATIZATION, | ||
SetList::STRICT_BOOLEANS, | ||
SetList::INSTANCEOF, | ||
] | ||
); | ||
|
||
$rectorConfig->importNames(); | ||
$rectorConfig->importShortClasses(false); | ||
|
||
$rectorConfig->skip( | ||
[ | ||
FlipTypeControlToUseExclusiveTypeRector::class, | ||
] | ||
); | ||
}; |