Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <script-name>`.

- `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:
Expand Down
23 changes: 22 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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"
]
}
}
26 changes: 26 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersion;

return RectorConfig::configure()
->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
);
15 changes: 8 additions & 7 deletions tests/DDD/Attribute/DDDAttributeTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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