1

我的项目的代码气候中不断出现这样的警告:

  • 文件 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>
4

1 回答 1

0

首先你需要

<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>
于 2019-08-09T15:24:45.033 回答