forked from SegarBox/segar-backend-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.phpmd.cleancode.xml
200 lines (190 loc) · 6.65 KB
/
.phpmd.cleancode.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?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="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="ErrorControlOperator"
message="Remove error control operator '@' on line {0}."
class="PHPMD\Rule\CleanCode\ErrorControlOperator"
externalInfoUrl="http://phpmd.org/rules/cleancode.html#errorcontroloperator">
<description>
<![CDATA[
Error suppression should be avoided if possible as it doesn't just suppress the error, that
you are trying to stop, but will also suppress errors that you didn't predict would ever occur.
Consider changing error_reporting() level and/or setting up your own error handler.
]]>
</description>
<priority>1</priority>
<example>
<![CDATA[
function foo($filePath) {
$file = @fopen($filPath); // hides exceptions
$key = @$array[$notExistingKey]; // assigns null to $key
}
]]>
</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>
<properties>
<property name="ignore-global" value="false" description="Ignore classes in the global namespace" />
</properties>
<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="https://phpmd.org/rules/cleancode.html#undefinedvariable">
<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>