Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign a name for each ArchRule #230

Open
ricfio opened this issue Jan 9, 2022 · 0 comments
Open

Assign a name for each ArchRule #230

ricfio opened this issue Jan 9, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@ricfio
Copy link
Contributor

ricfio commented Jan 9, 2022

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
@AlessandroMinoccheri AlessandroMinoccheri added the enhancement New feature or request label Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants