gpt4 book ai didi

php - 如何忽略PHPMD中特定目录的特定规则

转载 作者:行者123 更新时间:2023-12-04 09:31:52 24 4
gpt4 key购买 nike

命令

phpmd app,config,routes text phpmd.xml
我在 Laravel 项目上使用 phpmd,有一条规则叫 CouplingBetweenObjects在design.xml下,我想忽略app/Http/Controllers目录下的所有文件到这个规则,phpmd只提供 --exclude选项将使目录通过 所有 规则,是否可以通过 XML 文件或命令行忽略特定目录的规则
phpmd.xml
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Netask 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">
<description>Netask code style rule set
</description>
<rule ref="rulesets/codesize.xml/CyclomaticComplexity"/>
<rule ref="rulesets/codesize.xml/NPathComplexity"/>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount">
<properties>
<property name="minimum" value="30"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/TooManyFields">
<properties>
<property name="maxfields" value="20"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/TooManyMethods"/>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
<properties>
<property name="maximum" value="30"/>
</properties>
</rule>
<rule ref="rulesets/controversial.xml"/>
<rule ref="rulesets/design.xml"/>
<rule ref="rulesets/naming.xml/ShortVariable"/>
<rule ref="rulesets/naming.xml/LongVariable">
<properties>
<property name="maximum" value="30"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName">
<properties>
<property name="minimum" value="2"/>
</properties>
</rule>
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass"/>
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField" />
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable" />

<exclude-pattern>app/Console/Kernel.php</exclude-pattern>
<exclude-pattern>app/Services/Service.php</exclude-pattern>
<exclude-pattern>tests/TestCase.php</exclude-pattern>
</ruleset>

最佳答案

我建议以稍微不同的方式查看它,即您想忽略特定文件中的特定 PHPMD 规则,PHPMD 通过注释中的注释支持该规则。
例如

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
https://phpmd.org/documentation/suppress-warnings.html
我认为这是使用 PHPMD 的惯用方式。如果这是不可能的,您可以为运行 phpmd 的新命令添加别名。两次(在命令之间使用 ||)并在第二个规则集 xml 中排除不需要的规则。

关于php - 如何忽略PHPMD中特定目录的特定规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62806765/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com