diff --git a/CHANGELOG.md b/CHANGELOG.md index 68ce616..70ca35a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Bug #116: Update `LICENSE` and `composer.json` (@terabytesoftw) - Bug #117: Raise PHPStan level to `5` (@terabytesoftw) - Bug #118: Add `phpdoc_param_order` rule and update namespace references in `rector.php` (@terabytesoftw) +- Enh #119: Add `php-forge/coding-standard` to development dependencies for code quality checks (@terabytesoftw) ## 0.1.2 June 10, 2024 diff --git a/composer.json b/composer.json index ce39b2d..65f5afa 100644 --- a/composer.json +++ b/composer.json @@ -32,13 +32,12 @@ }, "require-dev": { "maglnet/composer-require-checker": "^4.7", + "php-forge/coding-standard": "^0.1", "php-forge/support": "^0.3", "phpstan/extension-installer": "^1.4", "phpstan/phpstan": "^2.1", "phpstan/phpstan-strict-rules": "^2.0.3", "phpunit/phpunit": "^10.5", - "rector/rector": "^2.2", - "symplify/easy-coding-standard": "^13.0", "xepozz/internal-mocker": "^1.4" }, "suggest": { @@ -81,11 +80,9 @@ "curl -fsSL -o .editorconfig https://raw.githubusercontent.com/yii2-extensions/template/main/.editorconfig", "curl -fsSL -o .gitattributes https://raw.githubusercontent.com/yii2-extensions/template/main/.gitattributes", "curl -fsSL -o .gitignore https://raw.githubusercontent.com/yii2-extensions/template/main/.gitignore", - "curl -fsSL -o ecs.php https://raw.githubusercontent.com/yii2-extensions/template/main/ecs.php", "curl -fsSL -o infection.json5 https://raw.githubusercontent.com/yii2-extensions/template/main/infection.json5", "curl -fsSL -o phpstan.neon https://raw.githubusercontent.com/yii2-extensions/template/main/phpstan.neon", - "curl -fsSL -o phpunit.xml.dist https://raw.githubusercontent.com/yii2-extensions/template/main/phpunit.xml.dist", - "curl -fsSL -o rector.php https://raw.githubusercontent.com/yii2-extensions/template/main/rector.php" + "curl -fsSL -o phpunit.xml.dist https://raw.githubusercontent.com/yii2-extensions/template/main/phpunit.xml.dist" ], "tests": "./vendor/bin/phpunit" } diff --git a/ecs.php b/ecs.php index 4f78988..300b0b5 100644 --- a/ecs.php +++ b/ecs.php @@ -2,94 +2,12 @@ declare(strict_types=1); -use PhpCsFixer\Fixer\ClassNotation\{ClassDefinitionFixer, OrderedClassElementsFixer, OrderedTraitsFixer}; -use PhpCsFixer\Fixer\Import\{NoUnusedImportsFixer, OrderedImportsFixer}; -use PhpCsFixer\Fixer\LanguageConstruct\NullableTypeDeclarationFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer; -use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer; -use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer; -use Symplify\EasyCodingStandard\Config\ECSConfig; +/** @var \Symplify\EasyCodingStandard\Configuration\ECSConfigBuilder $ecsConfigBuilder */ +$ecsConfigBuilder = require __DIR__ . '/vendor/php-forge/coding-standard/config/ecs.php'; -return ECSConfig::configure() - ->withConfiguredRule( - ClassDefinitionFixer::class, - [ - 'space_before_parenthesis' => true, - ], - ) - ->withConfiguredRule( - NullableTypeDeclarationFixer::class, - [ - 'syntax' => 'union', - ], - ) - ->withConfiguredRule( - OrderedClassElementsFixer::class, - [ - 'order' => [ - 'use_trait', - 'constant_public', - 'constant_protected', - 'constant_private', - 'case', - 'property_public', - 'property_protected', - 'property_private', - 'construct', - 'destruct', - 'magic', - 'method_public_abstract', - 'method_protected_abstract', - 'method_public', - 'method_protected', - 'method_private', - ], - 'sort_algorithm' => 'alpha', - ], - ) - ->withConfiguredRule( - OrderedImportsFixer::class, - [ - 'imports_order' => [ - 'class', - 'function', - 'const', - ], - 'sort_algorithm' => 'alpha', - ], - ) - ->withConfiguredRule( - PhpdocTypesOrderFixer::class, - [ - 'sort_algorithm' => 'none', - 'null_adjustment' => 'always_last', - ], - ) - ->withConfiguredRule( - PhpUnitTestCaseStaticMethodCallsFixer::class, - [ - 'call_type' => 'self', - ], - ) - ->withFileExtensions(['php']) - ->withPaths( - [ - __DIR__ . '/src', - __DIR__ . '/tests', - ], - ) - ->withPhpCsFixerSets(perCS30: true) - ->withPreparedSets( - cleanCode: true, - comments: true, - docblocks: true, - namespaces: true, - strict: true, - ) - ->withRules( - [ - NoUnusedImportsFixer::class, - OrderedTraitsFixer::class, - SingleQuoteFixer::class, - ] - ); +return $ecsConfigBuilder->withPaths( + [ + __DIR__ . '/src', + __DIR__ . '/tests', + ], +); diff --git a/rector.php b/rector.php index 25d1066..6fce667 100644 --- a/rector.php +++ b/rector.php @@ -2,10 +2,10 @@ declare(strict_types=1); -return static function (\Rector\Config\RectorConfig $rectorConfig): void { - $rectorConfig->parallel(); +use Rector\Config\RectorConfig; - $rectorConfig->importNames(); +return static function (RectorConfig $rectorConfig): void { + $rectorConfig->import(__DIR__ . '/vendor/php-forge/coding-standard/config/rector.php'); $rectorConfig->paths( [ @@ -13,24 +13,4 @@ __DIR__ . '/tests', ], ); - - $rectorConfig->sets( - [ - \Rector\Set\ValueObject\SetList::PHP_81, - \Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_81, - \Rector\Set\ValueObject\SetList::TYPE_DECLARATION, - ], - ); - - $rectorConfig->skip( - [ - \Rector\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector::class, - ], - ); - - $rectorConfig->rules( - [ - \Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector::class, - ], - ); };