diff --git a/README.md b/README.md index 4ef4529..c2ce304 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,27 @@ To use phpMolecules in your project just install it with Composer from Packagist composer require xmolecules/phpmolecules ``` +## Development Scripts + +This project includes several Composer scripts to assist with development, testing, and code quality checks. You can run these scripts using `composer run `. + +- `unit`: Runs PHPUnit tests with colored output. +- `stan`: Performs static analysis using PHPStan. +- `cs-check`: Checks code style compliance using PHP CodeSniffer, including version display and caching for performance. +- `cs-fix`: Automatically fixes code style issues using PHP CodeSniffer. +- `composer-audit`: Runs Composer audit to check for security vulnerabilities in dependencies. +- `rector`: Runs Rector in dry-run mode to check for potential code improvements. +- `rector-fix`: Runs Rector to apply code improvements. +- `fix`: Runs both code style fixes and Rector improvements. +- `test`: Runs a comprehensive test suite including unit tests, code style checks, static analysis, Rector checks, and security audit. + +Example usage: + +```fish +composer run test +composer run fix +``` + ## Release Instructions Create a new Git version tag and push it: diff --git a/composer.json b/composer.json index bb417bb..1a109a2 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "require-dev": { "phpunit/phpunit": "^9.6", "phpstan/phpstan": "^1.10", - "squizlabs/php_codesniffer": "^3.7" + "squizlabs/php_codesniffer": "^3.7", + "rector/rector": "^1.2" }, "autoload": { "psr-4": { @@ -28,5 +29,25 @@ "psr-4": { "PHPMolecules\\DDD\\": "tests/DDD" } + }, + "scripts": { + "unit": "phpunit --colors=always", + "stan": "phpstan analyse", + "cs-check": "phpcs --version && phpcs -p --cache", + "cs-fix": "phpcbf", + "composer-audit": "composer audit", + "rector": "vendor/bin/rector process --dry-run", + "rector-fix": "vendor/bin/rector process", + "fix": [ + "@cs-fix", + "@rector-fix" + ], + "test": [ + "@unit", + "@cs-check", + "@stan", + "@rector", + "@composer-audit" + ] } } diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..d71f9d4 --- /dev/null +++ b/rector.php @@ -0,0 +1,26 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withPhpSets(php80: true) + ->withPhpVersion(PhpVersion::PHP_80) + ->withAttributesSets() + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + naming: true, + privatization: true, + rectorPreset: true, + typeDeclarations: true, + earlyReturn: true, + strictBooleans: true + ); diff --git a/tests/DDD/Attribute/DDDAttributeTests.php b/tests/DDD/Attribute/DDDAttributeTests.php index bc5947a..bd96e9c 100644 --- a/tests/DDD/Attribute/DDDAttributeTests.php +++ b/tests/DDD/Attribute/DDDAttributeTests.php @@ -20,22 +20,23 @@ class BankAccount private IBAN $iban; /* @phpstan-ignore-line */ } -class DDDAttributesTest extends TestCase +final class DDDAttributesTest extends TestCase { public function testValueObjectAttribute(): void { - $reflector = new ReflectionClass(IBAN::class); - $attributes = $reflector->getAttributes(); + $reflectionClass = new ReflectionClass(IBAN::class); + $attributes = $reflectionClass->getAttributes(); $this->assertCount(1, $attributes); - $this->assertEquals("PHPMolecules\DDD\Attribute\ValueObject", $attributes[0]->getName()); + $this->assertEquals(\PHPMolecules\DDD\Attribute\ValueObject::class, $attributes[0]->getName()); } public function testEntityAttributes(): void { - $reflector = new ReflectionClass(BankAccount::class); - $attributes = $reflector->getAttributes(); + $reflectionClass = new ReflectionClass(BankAccount::class); + $attributes = $reflectionClass->getAttributes(); $this->assertCount(1, $attributes); - $this->assertEquals("PHPMolecules\DDD\Attribute\Entity", $attributes[0]->getName()); + $this->assertEquals(\PHPMolecules\DDD\Attribute\Entity::class, $attributes[0]->getName()); } } + // phpcs:enable