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

Percentage based rules #895

Open
AJenbo opened this issue May 22, 2021 · 1 comment
Open

Percentage based rules #895

AJenbo opened this issue May 22, 2021 · 1 comment

Comments

@AJenbo
Copy link
Member

AJenbo commented May 22, 2021

Description

ISO/IEC 25010:2011 is an industry standard for code maintainability, it is often set as a sales requirement for software that it must live up to this standard.

There are tools that will check the status of a project as well as CI services, but there does not appear to be any developer tools that would help to verify the adherence as the developer works on the code.

PHPMD can analyze and catch a lot of the patterns described in the standard. But one aspect that PHPMD is not able to reflect is the allowance of gradation in code that falls outside the idea. For example PHPMD will simply report any function that is longer then a configured max of 15 lines, but ISO-25010 allows for 44% of the code to be in functions of 15 or more lines, 22% can be 30+ and 7% maybe be 60+. Only when one of these limits are broken should the functions in that range be reported ass violations.

In order to facilitate this feature we would need to expand the rule set to allow multiple entries for the same rule.
The analyzer would also need to know the total line number before it concludes what is a violation.

To keep backwards comparability any rule that does not have a percentage defined should assume that 100% of the code must comply with the rule.

Suggested config format:

<?xml version="1.0" encoding="UTF-8"?>
<ruleset>
    <rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
        <properties>
            <property name="minimum" value="15" precentage="56"/>
            <property name="ignore-whitespace" value="true"/>
        </properties>
        <properties>
            <property name="minimum" value="31" precentage="78"/>
            <property name="ignore-whitespace" value="true"/>
        </properties>
        <properties>
            <property name="minimum" value="60" precentage="93"/>
            <property name="ignore-whitespace" value="true"/>
        </properties>
    </rule>
</ruleset>
@ravage84
Copy link
Member

Interesting idea.

I question whether this should be the responsibility of PHPMD itself, though. May be I'm just coming too much from a "do one thing and do it well" point of view....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants