1+ <?xml version =" 1.0" ?>
2+
3+ <ruleset name =" Clean Code Rules"
4+ xmlns =" http://pmd.sf.net/ruleset/1.0.0"
5+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
6+ xsi : schemaLocation =" http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
7+ xsi : noNamespaceSchemaLocation =" http://pmd.sf.net/ruleset_xml_schema.xsd" >
8+
9+ <description >
10+ The Clean Code ruleset contains rules that enforce a clean code base. This includes rules from SOLID and object calisthenics.
11+ </description >
12+
13+ <rule name =" BooleanArgumentFlag"
14+ since =" 1.4.0"
15+ message =" The method {0} has a boolean flag argument {1}, which is a certain sign of a Single Responsibility Principle violation."
16+ class =" PHPMD\Rule\CleanCode\BooleanArgumentFlag"
17+ externalInfoUrl =" https://phpmd.org/rules/cleancode.html#booleanargumentflag" >
18+ <description >
19+ <![CDATA[
20+ A boolean flag argument is a reliable indicator for a violation of
21+ the Single Responsibility Principle (SRP). You can fix this problem
22+ by extracting the logic in the boolean flag into its own class
23+ or method.
24+ ]]>
25+ </description >
26+ <priority >1</priority >
27+ <properties />
28+ <example >
29+ <![CDATA[
30+ class Foo {
31+ public function bar($flag = true) {
32+ }
33+ }
34+ ]]>
35+ </example >
36+ </rule >
37+
38+ <rule name =" ElseExpression"
39+ since =" 1.4.0"
40+ message =" The method {0} uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them."
41+ class =" PHPMD\Rule\CleanCode\ElseExpression"
42+ externalInfoUrl =" https://phpmd.org/rules/cleancode.html#elseexpression" >
43+ <description >
44+ <![CDATA[
45+ An if expression with an else branch is basically not necessary. You can rewrite the
46+ conditions in a way that the else clause is not necessary and the code becomes simpler
47+ to read. To achieve this, use early return statements, though you may
48+ need to split the code it several smaller methods. For very simple assignments
49+ you could also use the ternary operations.
50+ ]]>
51+ </description >
52+ <priority >1</priority >
53+ <properties />
54+ <example >
55+ <![CDATA[
56+ class Foo
57+ {
58+ public function bar($flag)
59+ {
60+ if ($flag) {
61+ // one branch
62+ } else {
63+ // another branch
64+ }
65+ }
66+ }
67+ ]]>
68+ </example >
69+ </rule >
70+
71+ <rule name =" IfStatementAssignment"
72+ since =" 2.7.0"
73+ message =" Avoid assigning values to variables in if clauses and the like (line '{0}', column '{1}')."
74+ class =" PHPMD\Rule\CleanCode\IfStatementAssignment"
75+ externalInfoUrl =" http://phpmd.org/rules/cleancode.html#ifstatementassignment" >
76+ <description >
77+ <![CDATA[
78+ Assignments in if clauses and the like are considered a code smell.
79+ Assignments in PHP return the right operand as their result.
80+ In many cases, this is an expected behavior, but can lead
81+ to many difficult to spot bugs, especially when the right
82+ operand could result in zero, null or an empty string and the like.
83+ ]]>
84+ </description >
85+ <priority >1</priority >
86+ <properties ></properties >
87+ <example >
88+ <![CDATA[
89+ class Foo
90+ {
91+ public function bar($flag)
92+ {
93+ if ($foo = 'bar') { // possible typo
94+ // ...
95+ }
96+ if ($baz = 0) { // always false
97+ // ...
98+ }
99+ }
100+ }
101+ ]]>
102+ </example >
103+ </rule >
104+
105+ <rule name =" DuplicatedArrayKey"
106+ message =" Duplicated array key {0}, first declared at line {1}."
107+ class =" PHPMD\Rule\CleanCode\DuplicatedArrayKey"
108+ externalInfoUrl =" http://phpmd.org/rules/cleancode.html#duplicatedarraykey" >
109+ <description >
110+ <![CDATA[
111+ Defining another value for the same key in an array literal overrides the previous key/value,
112+ which makes it effectively an unused code. If it's known from the beginning that the key
113+ will have different value, there is usually no point in defining first one.
114+ ]]>
115+ </description >
116+ <priority >2</priority >
117+ <example >
118+ <![CDATA[
119+ function createArray() {
120+ return [
121+ 'non-associative 0element', // not applied
122+ 0 => 'associative 0-element', // applied
123+ false => 'associative 0-element', // applied
124+ 'foo' => 'bar', // not applied
125+ "foo" => 'baz', // applied
126+ ];
127+ }
128+ ]]>
129+ </example >
130+ </rule >
131+
132+ <rule name =" MissingImport"
133+ since =" 2.7.0"
134+ message =" Missing class import via use statement (line '{0}', column '{1}')."
135+ class =" PHPMD\Rule\CleanCode\MissingImport"
136+ externalInfoUrl =" http://phpmd.org/rules/cleancode.html#MissingImport" >
137+ <description >
138+ <![CDATA[
139+ Importing all external classes in a file through use statements makes them clearly visible.
140+ ]]>
141+ </description >
142+ <priority >1</priority >
143+ <example >
144+ <![CDATA[
145+ function make() {
146+ return new \stdClass();
147+ }
148+ ]]>
149+ </example >
150+ </rule >
151+ </ruleset >
0 commit comments