cooldevguys / phpstan-dhexpendency-rules
A set of rules for PHPStan based on the Hexagonal architecture layers dependency
Installs: 189
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:phpstan-extension
Requires
- php: >=7.4.0
- phpstan/phpstan: ^1.8
Requires (Dev)
- phpunit/phpunit: ^9.6
- roave/security-advisories: dev-latest
README
A set of additional rules for phpstan. The intention of this rules is to foment to respect the dependency flow in a hexagonal architecture.
These rules assume that in the typical hexagonal architecture there are 3 layers: Infrastructure, Application and Domain.
There is a flow within these layers, this defines how the dependencies should interact to each other according the layer they are located in, and the flow is: Infrastructure ➡️ Application ➡️ Domain.
The interpretation of this flow is:
- The Infrastructure layer can "know" or communicate with the Application and Domain layers
- The Application layer can "known" or communicate ONLY with the Domain layer
- The Domain layer can ONLY communicate with itself
This ruleset attempts to help verifying the dependency flow is being applied properly in your project.
Installation
Run
composer require --dev cooldevguys/phpstan-dhexpendency-rules
If you use PHPStan extension installer, you're all set. If not, you need to manually register all the rules in your phpstan.neon
file:
includes: - vendor/cooldevguys/phpstan-dhexpendency-rules/rules.neon
Configuration
You need to add your own values as parameters to your phpstan.neon:
parameters: myVendorName: CoolDevGuys vendorStrictMode: true ignoredExternalVendors: ['IgnoredVendor'] infrastructureLayerName: Infra applicationLayerName: App domainLayerName: Dom
myVendorName
(string): Your project vendorvendorStrictMode
(bool): Indicates if you want to validate that no external vendors are imported from Application or Domain layersignoredExternalVendors
(string[]): A list of external vendors that you want to exclude from the checkinfrastructureLayerName
(string): The name you define in your project for the Infrastructure layerapplicationLayerName
(string): The name you define in your project for the Application layerdomainLayerName
(string): The name you define in your project for the Domain layer
Rules
Currently there are two rules:
LayersDependencyFlowRule
NoExternalVendorsAllowedFromDomainRule