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

Suggestion: change the way expressions are used in the docs to make it easier to understand #407

Open
dkarlovi opened this issue Aug 15, 2023 · 0 comments

Comments

@dkarlovi
Copy link

In the README, you're using each expression FQCN directly.

What I've done is add an alias to the ForClasses namespace, allowing me to use expressions without cluttering up the import map, this convention is used in Symfony for attributes from Doctrine, Validator, Serializer, etc.

My config file

<?php

declare(strict_types=1);

use Arkitect\ClassSet;
use Arkitect\CLI\Config;
use Arkitect\Expression\ForClasses as Assert;
use Arkitect\Rules\Rule;

return static function (Config $config): void {
    $src = ClassSet::fromDir(__DIR__.'/src');
    $naming = [
        Rule::allClasses()
            ->that(new Assert\IsInterface())
            ->should(new Assert\NotHaveNameMatching('*Interface'))
            ->because('we do not use the Interface suffix for interfaces'),
        Rule::allClasses()
            ->that(new Assert\IsAbstract())
            ->should(new Assert\HaveNameMatching('Abstract*'))
            ->because('we want abstract classes to have a Abstract prefix'),
        Rule::allClasses()
            ->that(new Assert\IsTrait())
            ->should(new Assert\HaveNameMatching('*Trait'))
            ->because('we want traits to have a Trait suffix'),
        Rule::allClasses()
            ->that(new Assert\ResideInOneOfTheseNamespaces('App'))
            ->should(new Assert\NotHaveNameMatching('*Manager'))
            ->because('*Manager is too vague in naming classes'),
    ];

    $config->add($src, ...$naming);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant