You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHPMD规则设置异常报错:添加短方法名例外后触发致命错误

Fixing PHPMD 2.6.0 ShortMethod Rule Exception Configuration Error

I’ve run into this exact issue with PHPMD 2.6.0 before—your problem boils down to how you’re specifying multiple rules to exclude in a single <exclude> tag. Older versions of PHPMD don’t support comma-separated rule names in one exclude entry, which causes the ShortMethod rule to not be properly excluded before you try to redefine it with custom properties.

Here’s the Corrected Configuration

Replace your combined exclude line with separate <exclude> tags for each rule, keeping your custom ShortMethod rule definition as-is:

<?xml version="1.0" encoding="UTF-8" ?>
<ruleset name="Complex PHP Mess Detector Rule Set" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<rule ref="rulesets/naming.xml">
<exclude name="LongVariable" />
<exclude name="ShortMethod" />
</rule>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum" value="32" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethod">
<properties>
<property name="minimum" value="3" />
<property name="exceptions" value="ln" />
</properties>
</rule>
<rule ref="rulesets/design.xml/ExitExpression" />
<rule ref="rulesets/design.xml/EvalExpression" />
<rule ref="rulesets/design.xml/GotoStatement" />
<rule ref="rulesets/design.xml/DepthOfInheritance" />
<rule ref="rulesets/design.xml/CouplingBetweenObjects" />
<rule ref="rulesets/design.xml/NumberOfChildren" />
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/controversial.xml" />
</ruleset>

Why This Works

When you use a comma-separated list in a single <exclude> tag in PHPMD 2.6.0, the parser doesn’t correctly split the rule names. This leaves the original ShortMethod rule from the naming.xml ruleset still active, and when you try to define it again with custom properties, it creates a conflict that triggers the fatal error about a null Rule interface.

By splitting the excludes into separate tags, you properly disable the default ShortMethod rule, allowing your custom-configured version to load correctly. This setup will now:

  • Enforce a 3-character minimum for method names
  • Exempt the ln method from this check
  • Keep your adjusted LongVariable rule intact

内容的提问来源于stack exchange,提问作者Mark Baker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:32:16