mi-schi/phpmd-symfony2

This package is abandoned and no longer maintained. The author suggests using the https://github.com/mi-schi/phpmd-extension package instead.

Extended mess detection rules from phpmd for Symfony applications.

2.1.1 2016-05-10 06:24 UTC

README

Use phpmd-extension instead.

phpmd-symfony2

Software License Build Status Build Status Code Coverage Scrutinizer Code Quality Dependency Status Latest Stable Version Total Downloads SensioLabsInsight

Features

Extends phpmd with rules for Symfony2. Also add extra rules from clean code.

Installation

Composer is used for installation. Add the following lines to your composer.json file:

"require-dev": {
    "mi-schi/phpmd-symfony2": "^2.0"
}

Usage

Create a phpmd.xml file and import the basic rules from phpmd. The example below contains some useful changes. Afterwards you can extend the configuration with rules from this repository.

Basic Rules

<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>

Add extra rules

    <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" />

You can also customize the rules with own properties or use only specific rules. Just take a look in the xml files. It works as the basic ruleset logic.

ToDos

  • Rule against Train Wreck (getFoo()->getBar()->getMuh()->getMeh())
  • Rule for high cohesion (member variables are used by a lot of methods)
  • Rule that a service should never call a controller
  • Try to avoid "return $this->doSomething() && !$this->doOtherthings()"