无法通过codeclimate更改phpmd上的ExcessiveMethodLength

时间:2018-09-08 01:31:23

标签: php phpmd code-climate

对于我的项目,这样的警告会不断出现在Code Climate中:

  • 文件YummySearchComponent.php具有360行代码(超过250行) 允许)。考虑重构。
  • 方法getYummyHelperData具有43行代码(允许超过25行)。考虑重构。

我尝试更改配置,但是似乎没有任何效果。 Github项目在这里:https://github.com/cnizzardini/cakephp-yummy

奇怪的是,像ShortVariable这样的默认值是3,但我却能够更改为1。我在做什么错了?

.codeclimate.yml

---
engines:
  duplication:
    enabled: true
    config:
      languages:
      - php
  eslint:
    enabled: true
  fixme:
    enabled: true
  phpmd:
    enabled: true
    config:
      file_extensions: "php"
      rulesets: "unusedcode,codesize,naming,phpmd.xml"
ratings:
  paths:
  - "**.inc"
  - "**.ctp"
  - "**.module"
  - "**.php"
exclude_paths:
- config/
- tests/
- webroot/

phpmd.xml

<?xml version="1.0"?>
<ruleset name="PHPMD rule set for my project" 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>Custom rules for checking my project</description>

    <rule ref="rulesets/cleancode.xml">
        <exclude name="ElseExpression"/>
    </rule>

    <rule ref="rulesets/codesize.xml">
        <exclude name="TooManyPublicMethods"/>
    </rule>

    <rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
        <properties>
            <property name="ignore-whitespace" value="true" />
            <property name="minimum" value="100" />
        </properties>
    </rule>

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

    <rule ref="rulesets/namingrules.xml/ShortVariable">
        <properties>
            <property name="minimum" value="1" />
        </properties>
    </rule>
</ruleset>

1 个答案:

答案 0 :(得分:-1)

首先需要

<exclude name="ExcessiveMethodLength"/>
<exclude name="ExcessiveClassLength"/>
<?xml version="1.0"?>
<ruleset name="PHPMD rule set for my project" 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>Custom rules for checking my project</description>

    <rule ref="rulesets/cleancode.xml">
        <exclude name="ElseExpression"/>
    </rule>

    <rule ref="rulesets/codesize.xml">
        <exclude name="TooManyPublicMethods"/>
        <exclude name="ExcessiveMethodLength"/>
        <exclude name="ExcessiveClassLength"/>
    </rule>

    <rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
        <properties>
            <property name="ignore-whitespace" value="true" />
            <property name="minimum" value="100" />
        </properties>
    </rule>

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

    <rule ref="rulesets/namingrules.xml/ShortVariable">
        <properties>
            <property name="minimum" value="1" />
        </properties>
    </rule>
</ruleset>