@@ -129,6 +129,28 @@ function createArray() {
129129 </example >
130130 </rule >
131131
132+ <rule name =" ErrorControlOperator"
133+ message =" Remove error control operator '@' on line {0}."
134+ class =" PHPMD\Rule\CleanCode\ErrorControlOperator"
135+ externalInfoUrl =" http://phpmd.org/rules/cleancode.html#errorcontroloperator" >
136+ <description >
137+ <![CDATA[
138+ Error suppression should be avoided if possible as it doesn't just suppress the error, that
139+ you are trying to stop, but will also suppress errors that you didn't predict would ever occur.
140+ Consider changing error_reporting() level and/or setting up your own error handler.
141+ ]]>
142+ </description >
143+ <priority >1</priority >
144+ <example >
145+ <![CDATA[
146+ function foo($filePath) {
147+ $file = @fopen($filPath); // hides exceptions
148+ $key = @$array[$notExistingKey]; // assigns null to $key
149+ }
150+ ]]>
151+ </example >
152+ </rule >
153+
132154 <rule name =" MissingImport"
133155 since =" 2.7.0"
134156 message =" Missing class import via use statement (line '{0}', column '{1}')."
@@ -140,6 +162,9 @@ Importing all external classes in a file through use statements makes them clear
140162 ]]>
141163 </description >
142164 <priority >1</priority >
165+ <properties >
166+ <property name =" ignore-global" value =" false" description =" Ignore classes in the global namespace" />
167+ </properties >
143168 <example >
144169 <![CDATA[
145170function make() {
@@ -148,4 +173,28 @@ function make() {
148173 ]]>
149174 </example >
150175 </rule >
151- </ruleset >
176+
177+ <rule name =" UndefinedVariable"
178+ since =" 2.8.0"
179+ message =" Avoid using undefined variables such as '{0}' which will lead to PHP notices."
180+ class =" PHPMD\Rule\CleanCode\UndefinedVariable"
181+ externalInfoUrl =" https://phpmd.org/rules/cleancode.html#undefinedvariable" >
182+ <description >
183+ Detects when a variable is used that has not been defined before.
184+ </description >
185+ <priority >3</priority >
186+ <example >
187+ <![CDATA[
188+ class Foo
189+ {
190+ private function bar()
191+ {
192+ // $message is undefined
193+ echo $message;
194+ }
195+ }
196+ ]]>
197+ </example >
198+ </rule >
199+
200+ </ruleset >
0 commit comments