mi-schi / phpmd-symfony2
2.1.1
2016-05-10 06:24 UTC
Requires
- phpmd/phpmd: >=2.3.0
Requires (Dev)
- mockery/mockery: @stable
- phpunit/phpunit: ^4.7
- symfony/process: ^2.7
README
phpmd-symfony2
特性
扩展 phpmd 以支持 Symfony2 的规则。还添加了来自 clean code 的额外规则。
- 清洁代码
- Symfony2
- 测试
安装
使用 Composer 进行安装。将以下行添加到您的 composer.json
文件中
"require-dev": {
"mi-schi/phpmd-symfony2": "^2.0"
}
使用方法
创建一个 phpmd.xml
文件并导入 phpmd 的基本规则。以下示例包含一些有用的更改。之后,您可以使用此存储库中的规则扩展配置。
基本规则
<ruleset name="basic-rules" 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>mess detection</description> <rule ref="rulesets/cleancode.xml" /> <rule ref="rulesets/codesize.xml"> <exclude name="ExcessiveParameterList" /> <exclude name="ExcessiveMethodLength" /> <exclude name="ExcessiveClassLength" /> <exclude name="CyclomaticComplexity" /> </rule> <rule ref="rulesets/codesize.xml/ExcessiveParameterList"> <properties> <property name="minimum" value="4" /> </properties> </rule> <rule ref="rulesets/codesize.xml/ExcessiveMethodLength"> <properties> <property name="minimum" value="31" /> <property name="ignore-whitespace" value="true" /> </properties> </rule> <rule ref="rulesets/codesize.xml/ExcessiveClassLength"> <properties> <property name="minimum" value="301" /> <property name="ignore-whitespace" value="true" /> </properties> </rule> <rule ref="rulesets/codesize.xml/CyclomaticComplexity"> <properties> <property name="reportLevel" value="6" /> <property name="showClassesComplexity" value="true" /> <property name="showMethodsComplexity" value="true" /> </properties> </rule> <rule ref="rulesets/controversial.xml" /> <rule ref="rulesets/design.xml" /> <rule ref="rulesets/naming.xml"> <exclude name="ShortVariable" /> <exclude name="LongVariable" /> </rule> <rule ref="rulesets/naming.xml/ShortVariable"> <properties> <property name="minimum" value="2" /> </properties> </rule> <rule ref="rulesets/naming.xml/LongVariable"> <properties> <property name="maximum" value="30" /> </properties> </rule> <rule ref="rulesets/unusedcode.xml" /> </ruleset>
添加额外规则
<rule ref="../../../../../mi-schi/phpmd-symfony2/Rulesets/cleancode.xml" /> <rule ref="../../../../../mi-schi/phpmd-symfony2/Rulesets/symfony2.xml" /> <rule ref="../../../../../mi-schi/phpmd-symfony2/Rulesets/test.xml" />
您还可以使用自己的属性自定义规则或仅使用特定规则。只需查看 xml 文件即可。它的工作原理与基本规则集逻辑相同。
待办事项
- 针对 Train Wreck (getFoo()->getBar()->getMuh()->getMeh()) 的规则
- 高内聚度规则(成员变量被许多方法使用)
- 服务不应调用控制器的规则
- 尝试避免 "return $this->doSomething() && !$this->doOtherthings()"