phparkitect / arkitect

Put your architectural rules under test!
MIT License
742 stars 40 forks source link

Detect if methods, or a set of methods, within a given namespace exceed a limit of lines #438

Open floriankraemer opened 3 months ago

floriankraemer commented 3 months ago

Feature Request

Make it possible to detect if methods, or a set of methods, within a given class or namespace exceed a limit of lines. The background is that we would like to prevent having controllers more than X lines.

Rule::allClasses()
    ->that(new ResideInOneOfTheseNamespaces('App\Controller'))
    ->should(new NotHaveMethodsLongerThanXCharacters(10))
    ->because('Controllers must not implement business logic');

I'm happy to help implementing this if somebody gives me some info how to get it done. I see no obvious way at the moment to get the line count of a methods from a class.

There is ClassDescription which does not contain a list of the method names, which would be nice and then have a MethodDescription for each that might also contain the line count and cyclomatic complexity? I'm aware of phpmd but it would be nice to have this in one tool and a more fine grained control via the DSL of Arkitekt vs the rule sets of phpmd.

Q A
New Feature yes
RFC yes/no
BC Break yes/no

Summary

Make it possible to detect if methods, or a set of methods, within a given class or namespace exceed a limit of lines. The background is that we would like to prevent having controllers more than X lines.

AlessandroMinoccheri commented 3 months ago

Hello @floriankraemer I am happy to help but I don't know if it's possible.