1

我在phpmd.xml文件中设置了这个规则:

<rule ref="rulesets/codesize.xml/ExcessiveClassLength">
    <properties>
        <property name="minimum" value="1500"/>
    </properties>
</rule>

但是这个规则被忽略了,我仍然得到这个错误:

/var/www/html/tests/Model/AdvertTest.php:18 The class AdvertTest has 1026 lines of code. Current threshold is 1000. Avoid really long classes.

知道为什么 phpmd 不阅读此规则。实际上,修复它的唯一方法是在类的顶部添加抑制错误。

更多信息:我在 MAC 上运行 phpmd,使用 Docker 使用以下命令: docker-compose exec php sh -c "./vendor/bin/phpmd ./tests text phpmd.test.xml"

完整的 XML:PHP Mess Detector 规则集

<rule ref="rulesets/codesize.xml">
    <exclude name="CyclomaticComplexity"/>
    <exclude name="ExcessiveMethodLength"/>
    <exclude name="NPathComplexity"/>
    <exclude name="TooManyMethods"/>
    <exclude name="ExcessiveClassComplexity"/>
    <exclude name="ExcessivePublicCount"/>
    <exclude name="TooManyPublicMethods"/>
    <exclude name="TooManyFields"/>
</rule>
<rule ref="rulesets/codesize.xml/TooManyFields">
    <properties>
        <property name="maxfields" value="21"/>
    </properties>
</rule>
<rule ref="rulesets/cleancode.xml">
    <exclude name="StaticAccess"/>
    <exclude name="ElseExpression"/>
</rule>
<rule ref="rulesets/controversial.xml"/>
<rule ref="rulesets/design.xml">
    <exclude name="CouplingBetweenObjects" />
    <exclude name="NumberOfChildren" />
</rule>
<rule ref="rulesets/design.xml/NumberOfChildren">
    <properties>
        <property name="minimum" value="20"/>
    </properties>
</rule>
<rule ref="rulesets/naming.xml">
    <exclude name="ShortVariable"/>
    <exclude name="LongVariable"/>
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
    <properties>
        <property name="maximum" value="25"/>
    </properties>
</rule>
<rule ref="rulesets/unusedcode.xml">
    <exclude name="UnusedFormalParameter"/>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength">
    <properties>
        <property name="minimum" value="1500"/>
    </properties>
</rule>

4

0 回答 0