arkitect icon indicating copy to clipboard operation
arkitect copied to clipboard

Assign a name for each ArchRule

Open ricfio opened this issue 4 years ago • 0 comments

Feature Request

Q A
New Feature yes
RFC yes
BC Break no

Summary

I would like assign a name for each ArchRule, specially using several rule groups.

For example, if i use this configuration:

<?php

declare(strict_types=1);

use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses\HaveNameMatching;
use Arkitect\Expression\ForClasses\ResideInOneOfTheseNamespaces;
use Arkitect\RuleBuilders\Architecture\Architecture;
use Arkitect\Rules\Rule;

return static function (Config $config): void {
    $allClasses = ClassSet::fromDir(__DIR__.'/src');

    $exagonalRules = Architecture::withComponents()
        ->component('Domain')->definedBy('App\Domain\*')
        ->component('Application')->definedBy('App\Application\*')
        ->component('Infrastructure')->definedBy('App\Infrastructure\*')
        ->where('Domain')->shouldNotDependOnAnyComponent()
        ->where('Application')->mayDependOnComponents('Domain')
        ->where('Infrastructure')->mayDependOnComponents('Domain', 'Application')
        ->rules();

    $layeredRules = Architecture::withComponents()
        ->component('Entity')->definedBy('App\Entity\*')
        ->component('Repository')->definedBy('App\Repository\*')
        ->component('Service')->definedBy('App\Service\*')
        ->component('Controller')->definedBy('App\Controller\*')
        ->where('Entity')->shouldNotDependOnAnyComponent()
        ->where('Repository')->mayDependOnComponents('Entity')
        ->where('Service')->mayDependOnComponents('Entity', 'Repository')
        ->where('Controller')->mayDependOnComponents('Entity', 'Service')
        ->rules();

    $namingRules = [];

    $namingRules[] = Rule::allClasses()
        ->that(new ResideInOneOfTheseNamespaces('App\Controller'))
        ->should(new HaveNameMatching('*Controller'))
        ->because('we want uniform naming');

    $config
        ->add($allClasses, ...$exagonalRules)
        ->add($allClasses, ...$layeredRules)
        ->add($allClasses, ...$namingRules);
};

Executing the check with ./vendor/bin/phparkitect check I got the following output:

PHPArkitect 0.2.10

Config file: phparkitect.php

analyze class set /app/src

 36/36 [============================] 100%

analyze class set /app/src

 36/36 [============================] 100%

analyze class set /app/src

 36/36 [============================] 100%

NO VIOLATIONS DETECTED!

Instead I would like to assign and then see the name for each ArchRule to check, like this example:

analyze class set /app/src for rule: "Exagonal Architecture Rules"
...
analyze class set /app/src for rule: "Layered Architecture Rules"
...
analyze class set /app/src for rule: "Naming Convention Rules"

So I would like to have a way to assign a name in the configuration for each of these rules:

  • $exagonalRules
  • $layeredRules
  • $namingRules

ricfio avatar Jan 09 '22 16:01 ricfio