我已在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>