From 3f5b5d3cfc59cc0f3397d5e975572fa0363b4030 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 26 Jan 2026 10:26:43 -0300 Subject: [PATCH 1/2] feat(dev): Add `php-forge/coding-standard` to development dependencies for code quality checks. --- .styleci.yml | 1 + CHANGELOG.md | 2 + README.md | 4 +- composer.json | 12 +++--- docs/development.md | 5 +-- docs/testing.md | 29 ++++++++++----- ecs.php | 89 ++++----------------------------------------- rector.php | 18 ++------- 8 files changed, 42 insertions(+), 118 deletions(-) diff --git a/.styleci.yml b/.styleci.yml index 6cf29b2..40c1c55 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -55,6 +55,7 @@ enabled: - phpdoc_no_empty_return - phpdoc_no_useless_inheritdoc - phpdoc_order + - phpdoc_param_order - phpdoc_property - phpdoc_scalar - phpdoc_singular_inheritdoc diff --git a/CHANGELOG.md b/CHANGELOG.md index fd055c4..85fe61a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.3.2 Under development +- Bug #17: Add `php-forge/coding-standard` to development dependencies for code quality checks (@terabytesoftw) + ## 0.3.1 January 20, 2026 - Bug #14: Update descriptions in stub classes to clarify purpose (@terabytesoftw) diff --git a/README.md b/README.md index 36b9036..edbe82c 100644 --- a/README.md +++ b/README.md @@ -299,8 +299,8 @@ final class EnumDataProviderTagCasesTest extends TestCase For detailed configuration options and advanced usage. -- [Testing Guide](docs/testing.md) -- [Development Guide](docs/development.md) +- 🧪 [Testing Guide](docs/testing.md) +- 🛠️ [Development Guide](docs/development.md) ## Package information diff --git a/composer.json b/composer.json index 9156b1f..407ca12 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "type": "library", "description": "Support utilities for enhanced testing capabilities.", "keywords": [ - "php", "php-forge", + "php", "support", "testing", "tests" @@ -16,12 +16,11 @@ "require-dev": { "infection/infection": "^0.27|^0.32", "maglnet/composer-require-checker": "^4.1", + "php-forge/coding-standard": "^0.1", "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" + "phpunit/phpunit": "^10.5" }, "autoload": { "psr-4": { @@ -56,11 +55,10 @@ "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 .styleci.yml https://raw.githubusercontent.com/yii2-extensions/template/main/.styleci.yml", "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/docs/development.md b/docs/development.md index dfb83e9..0e75489 100644 --- a/docs/development.md +++ b/docs/development.md @@ -8,7 +8,7 @@ To keep configuration files synchronized with the latest template updates, use t downloads the latest configuration files from the template repository. ```bash -composer run sync-metadata +composer sync-metadata ``` ### Updated Files @@ -20,11 +20,10 @@ This command updates the following configuration files: | `.editorconfig` | Editor settings and code style configuration | | `.gitattributes` | Git attributes and file handling rules | | `.gitignore` | Git ignore patterns and exclusions | -| `ecs.php` | Easy Coding Standard configuration | +| `.styleci.yml` | StyleCI code style analysis configuration | | `infection.json5` | Infection mutation testing configuration | | `phpstan.neon` | PHPStan static analysis configuration | | `phpunit.xml.dist` | PHPUnit test configuration | -| `rector.php` | Rector refactoring configuration | ### When to Run diff --git a/docs/testing.md b/docs/testing.md index c3f1ca8..e0e9d88 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -9,13 +9,22 @@ Tool references: - [Infection](https://infection.github.io/) for mutation testing. - [PHPStan](https://phpstan.org/) for static analysis. - [PHPUnit](https://phpunit.de/) for unit tests. +- [Rector](https://github.com/rectorphp/rector) for automated refactoring. + +## Automated refactoring (Rector) + +Run Rector to apply automated code refactoring. + +```bash +composer rector +``` ## Coding standards (ECS) Run Easy Coding Standard (ECS) and apply fixes. ```bash -composer run ecs +composer ecs ``` ## Dependency definition check @@ -23,7 +32,7 @@ composer run ecs Verify that runtime dependencies are correctly declared in `composer.json`. ```bash -composer run check-dependencies +composer check-dependencies ``` ## Mutation testing (Infection) @@ -31,13 +40,13 @@ composer run check-dependencies Run mutation testing. ```bash -composer run mutation +composer mutation ``` Run mutation testing with static analysis enabled. ```bash -composer run mutation-static +composer mutation-static ``` ## Static analysis (PHPStan) @@ -45,7 +54,7 @@ composer run mutation-static Run static analysis. ```bash -composer run static +composer static ``` ## Unit tests (PHPUnit) @@ -53,21 +62,21 @@ composer run static Run the full test suite. ```bash -composer run tests +composer tests ``` ## Passing extra arguments Composer scripts support forwarding additional arguments using `--`. -Example: run a specific PHPUnit test or filter by name. +Run PHPUnit with code coverage report generation. ```bash -composer run tests -- --filter SvgTest +composer tests -- --coverage-html code_coverage ``` -Example: run PHPStan with a different memory limit: +Run PHPStan with a different memory limit. ```bash -composer run static -- --memory-limit=512M +composer static -- --memory-limit=512M ``` diff --git a/ecs.php b/ecs.php index 726b0dd..300b0b5 100644 --- a/ecs.php +++ b/ecs.php @@ -2,85 +2,12 @@ declare(strict_types=1); -use PhpCsFixer\Fixer\ClassNotation\{ClassDefinitionFixer, OrderedClassElementsFixer, OrderedTraitsFixer}; -use PhpCsFixer\Fixer\Import\{NoUnusedImportsFixer, OrderedImportsFixer}; -use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer; -use PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer; -use PhpCsFixer\Fixer\LanguageConstruct\NullableTypeDeclarationFixer; -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( - OrderedClassElementsFixer::class, - [ - 'order' => [ - 'use_trait', - 'constant_public', - 'constant_protected', - 'constant_private', - 'case', - 'property_public', - 'property_protected', - 'property_private', - 'construct', - 'destruct', - 'magic', - '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', - ], - ) - ->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, - ] - ) - ->withSkip( - [ - NullableTypeDeclarationFixer::class, - ] - ); +return $ecsConfigBuilder->withPaths( + [ + __DIR__ . '/src', + __DIR__ . '/tests', + ], +); diff --git a/rector.php b/rector.php index 4a7a938..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,16 +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->rule( - Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector::class - ); }; From fc914e739373a63e27b0087b8b2718a19344977e Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Mon, 26 Jan 2026 10:47:59 -0300 Subject: [PATCH 2/2] Apply fixed Coderabbitai review. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85fe61a..0e4c80b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## 0.3.2 Under development -- Bug #17: Add `php-forge/coding-standard` to development dependencies for code quality checks (@terabytesoftw) +- Enh #17: Add `php-forge/coding-standard` to development dependencies for code quality checks (@terabytesoftw) ## 0.3.1 January 20, 2026