Skip to content

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

Open
@floriankraemer

Description

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.

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions