atournayre / phparkitect-rules
Provides additional rules for phparkitect/phparkitect for Symfony and API Platform
0.1.0
2024-06-09 19:58 UTC
Requires
- php: >=8.1
- phparkitect/phparkitect: ^0.3
- webmozart/assert: ^1.11
Requires (Dev)
- phpstan/phpstan: ^1.10.44
- phpstan/phpstan-deprecation-rules: ^1.1.4
- phpstan/phpstan-strict-rules: ^1.5.2
- phpunit/phpunit: ^10.5
README
The project is structured around the concept of architectural rules for PHP classes, with a focus on namespace dependencies and class naming conventions.
Installing
composer require --dev atournayre/phparkitect-rules
Usage
Rules must be used in a phparkitect configuration file.
Here is an example of how to use it:
// phparkitect.php use Arkitect\ClassSet; use Arkitect\CLI\Config; use Arkitect\Expression\ForClasses\IsFinal; use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces; use Arkitect\Rules\Rule; use Atournayre\PHPArkitect\Builder\RuleBuilder; use Atournayre\PHPArkitect\Rules\ListenerMustBeLoggableLog; use Atournayre\PHPArkitect\Set\Sets; return static function (Config $config): void { $classSet = ClassSet::fromDir(__DIR__ . '/src'); $rules = RulesBuilder::create ->add(new ListenerMustBeLoggableLog) // Add rules for Symfony Command ->set(Sets::symfonyCommand()) // Add rules for Doctrine Naming ->set(Sets::doctrineUniformNaming()) // Add regular rules ->add( Rule::allClasses() ->that(new ResideInOneOfTheseNamespaces('App')) ->should(new IsFinal()) ->because('All classes in App namespace must be final') ) ->rules(); $config->add($classSet, ...$rules); };
You can use sets or rules individually.
Contributing
Contributions are welcome!
License
This project is licensed under the MIT License.