<?xml version="1.0"?>

<ruleset name="Clean Code 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>
The Clean Code ruleset contains rules that enforce a clean code base. This includes rules from SOLID and object calisthenics.
    </description>

    <rule name="BooleanArgumentFlag"
          since="1.4.0"
          message="The method {0} has a boolean flag argument {1}, which is a certain sign of a Single Responsibility Principle violation."
          class="PHPMD\Rule\CleanCode\BooleanArgumentFlag"
          externalInfoUrl="https://phpmd.org/rules/cleancode.html#booleanargumentflag">
        <description>
            <![CDATA[
A boolean flag argument is a reliable indicator for a violation of
the Single Responsibility Principle (SRP). You can fix this problem
by extracting the logic in the boolean flag into its own class
or method.
            ]]>
        </description>
        <priority>1</priority>
        <properties />
        <example>
            <![CDATA[
class Foo {
    public function bar($flag = true) {
    }
}
            ]]>
        </example>
    </rule>

    <rule name="ElseExpression"
          since="1.4.0"
          message="The method {0} uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them."
          class="PHPMD\Rule\CleanCode\ElseExpression"
          externalInfoUrl="https://phpmd.org/rules/cleancode.html#elseexpression">
        <description>
            <![CDATA[
An if expression with an else branch is basically not necessary. You can rewrite the
conditions in a way that the else clause is not necessary and the code becomes simpler
to read.  To achieve this, use early return statements, though you may
need to split the code it several smaller methods. For very simple assignments
you could also use the ternary operations.
            ]]>
        </description>
        <priority>1</priority>
        <properties/>
        <example>
            <![CDATA[
class Foo
{
    public function bar($flag)
    {
        if ($flag) {
            // one branch
        } else {
            // another branch
        }
    }
}
            ]]>
        </example>
    </rule>

    <rule name="IfStatementAssignment"
          since="2.7.0"
          message="Avoid assigning values to variables in if clauses and the like (line '{0}', column '{1}')."
          class="PHPMD\Rule\CleanCode\IfStatementAssignment"
          externalInfoUrl="http://phpmd.org/rules/cleancode.html#ifstatementassignment">
        <description>
            <![CDATA[
Assignments in if clauses and the like are considered a code smell.
Assignments in PHP return the right operand as their result.
In many cases, this is an expected behavior, but can lead
to many difficult to spot bugs, especially when the right
operand could result in zero, null or an empty string and the like.
            ]]>
        </description>
        <priority>1</priority>
        <properties></properties>
        <example>
            <![CDATA[
class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}
            ]]>
        </example>
    </rule>

    <rule name="StaticAccess"
          since="1.4.0"
          message="Avoid using static access to class '{0}' in method '{1}'."
          class="PHPMD\Rule\CleanCode\StaticAccess"
          externalInfoUrl="https://phpmd.org/rules/cleancode.html#staticaccess">
        <description>
            <![CDATA[
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid
using static access at all costs and instead inject dependencies through the constructor. The only
case when static access is acceptable is when used for factory methods.
            ]]>
        </description>
        <priority>1</priority>
        <properties>
            <property name="exceptions" description="Comma-separated class name list of exceptions" value=""/>
        </properties>
        <example>
            <![CDATA[
class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}
            ]]>
        </example>
    </rule>

    <rule name="DuplicatedArrayKey"
          message="Duplicated array key {0}, first declared at line {1}."
          class="PHPMD\Rule\CleanCode\DuplicatedArrayKey"
          externalInfoUrl="http://phpmd.org/rules/cleancode.html#duplicatedarraykey">
        <description>
            <![CDATA[
Defining another value for the same key in an array literal overrides the previous key/value,
which makes it effectively an unused code. If it's known from the beginning that the key
will have different value, there is usually no point in defining first one.
            ]]>
        </description>
        <priority>2</priority>
        <example>
            <![CDATA[
function createArray() {
    return [
        'non-associative 0element', // not applied
        0 => 'associative 0-element', // applied
        false => 'associative 0-element', // applied
        'foo' => 'bar', // not applied
        "foo" => 'baz', // applied
    ];
}
            ]]>
        </example>
    </rule>

    <rule name="MissingImport"
          since="2.7.0"
          message="Missing class import via use statement (line '{0}', column '{1}')."
          class="PHPMD\Rule\CleanCode\MissingImport"
          externalInfoUrl="http://phpmd.org/rules/cleancode.html#MissingImport">
        <description>
            <![CDATA[
Importing all external classes in a file through use statements makes them clearly visible.
            ]]>
        </description>
        <priority>1</priority>
        <example>
            <![CDATA[
function make() {
    return new \stdClass();
}
            ]]>
        </example>
    </rule>

    <rule name="UndefinedVariable"
          since="2.8.0"
          message="Avoid using undefined variables such as '{0}' which will lead to PHP notices."
          class="PHPMD\Rule\CleanCode\UndefinedVariable"
          externalInfoUrl="">
        <description>
            Detects when a variable is used that has not been defined before.
        </description>
        <priority>3</priority>
        <example>
            <![CDATA[
class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}
]]>
        </example>
    </rule>

</ruleset>
