我创建了一个包含以下内容的文件 phpmd.rules.xml:
<?xml version="1.0"?>
<ruleset name="No controversial but superglobals"
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">
<description> Rulesets without controversial rules but including the check for superglobals </description>
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml" />
<rule ref="rulesets/unusedcode.xml" />
<rule ref="rulesets/controversial.xml/Superglobals" />
</ruleset>
要使用这些规则,您可以使用以下命令(phpmd 使用 composer 在您的项目中本地安装):
vendor/bin/phpmd src/ text phpmd.xml
更多细节可以在http://phpmd.org/documentation/creating-a-ruleset.html找到