PHP code example of atournayre / phparkitect-rules

1. Go to this page and download the library: Download atournayre/phparkitect-rules library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

atournayre / phparkitect-rules example snippets


// 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);
};