Download the PHP package solidframe/phpstan-rules without Composer
On this page you can find all versions of the php package solidframe/phpstan-rules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download solidframe/phpstan-rules
More information about solidframe/phpstan-rules
Files in solidframe/phpstan-rules
Package phpstan-rules
Short Description PHPStan rules for DDD, CQRS, and Event Sourcing architectural enforcement
License MIT
Informations about the package phpstan-rules
SolidFrame PHPStan Rules
PHPStan rules for DDD, CQRS, and Event Sourcing architectural enforcement.
Static analysis catches architectural violations before tests even run.
Installation
The rules are auto-registered via PHPStan's extension mechanism. No manual configuration needed.
Rules
CQRS Rules
Command Handler Must Return Void
Command handlers perform side effects and must not return values.
Query Handler Must Not Return Void
Query handlers must return data.
Handler Must Be Invokable
Handlers must implement __invoke() and have only one public method (besides __construct).
Messages Must Be Final Readonly
Commands and Queries must be declared as final readonly.
Messages Must Not Extend
Commands and Queries must not extend other classes. Use composition.
DDD Rules
Value Object Must Be Readonly
Value objects are immutable. The class must be declared as readonly.
No Direct Aggregate Construction
Aggregate roots must be created via static factory methods, not new.
Construction inside the aggregate class itself is allowed.
Event Sourcing Rules
Events Must Be Final Readonly
Domain events are immutable data structures.
Apply Method Must Exist
For every event recorded via recordThat(), a corresponding apply{EventName}() method must exist.
Configuration
Rules work out of the box with SolidFrame interfaces. To use with custom interfaces, override in your phpstan.neon:
Rule Summary
| Rule | ID | Area |
|---|---|---|
| Command handler returns void | solidframe.commandHandlerMustReturnVoid |
CQRS |
| Query handler returns data | solidframe.queryHandlerMustNotReturnVoid |
CQRS |
| Handler is invokable | solidframe.handlerMustBeInvokable |
CQRS |
| Handler has single public method | solidframe.handlerSinglePublicMethod |
CQRS |
| Command is final | solidframe.commandMustBeFinal |
CQRS |
| Command is readonly | solidframe.commandMustBeReadonly |
CQRS |
| Query is final | solidframe.queryMustBeFinal |
CQRS |
| Query is readonly | solidframe.queryMustBeReadonly |
CQRS |
| Message has no parent class | solidframe.messageMustNotExtend |
CQRS |
| Value object is readonly | solidframe.valueObjectMustBeReadonly |
DDD |
| No direct aggregate construction | solidframe.noDirectAggregateConstruction |
DDD |
| Event is final | solidframe.eventMustBeFinal |
Event Sourcing |
| Event is readonly | solidframe.eventMustBeReadonly |
Event Sourcing |
| Apply method exists for recorded events | solidframe.applyMethodMustExist |
Event Sourcing |
Complementary: ArchTest vs PHPStan Rules
| Concern | ArchTest | PHPStan Rules |
|---|---|---|
| Namespace dependencies | doesNotDependOn() |
— |
| Class structure (final, readonly) | areFinal(), areReadonly() |
Message/VO/Event rules |
| Handler return types | — | Command void, Query non-void |
| Handler conventions | — | Invokable, single public method |
| Event apply methods | — | applyMethodMustExist |
| Aggregate construction | — | noDirectAggregateConstruction |
| Module isolation | Modular preset | — |
Use both for comprehensive architectural enforcement.
Related Packages
- solidframe/core — DomainEventInterface
- solidframe/cqrs — Command, Query, Handler interfaces
- solidframe/ddd — ValueObjectInterface
- solidframe/event-sourcing — AbstractEventSourcedAggregateRoot
- solidframe/archtest — Complementary PHPUnit-based architecture tests
Contributing
This repository is a read-only split of the solidframe/solidframe monorepo, auto-synced on every push to main. Issues, pull requests, and discussions belong in the monorepo.