The method Ajde_Exception_Handler::trace() calls the typical debug function var_dump() which is mostly only used during development. Open
var_dump($item['args']);
- Read upRead up
- Exclude checks
DevelopmentCodeFragment
Since: 2.3.0
Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.
Example
class SuspectCode {
public function doSomething(array $items)
{
foreach ($items as $i => $item) {
// …
if ('qafoo' == $item) var_dump($i);
// …
}
}
}
Source https://phpmd.org/rules/design.html#developmentcodefragment
The method Ajde_Exception_Handler::trace() calls the typical debug function var_dump() which is mostly only used during development. Open
var_dump($dump[0]);
- Read upRead up
- Exclude checks
DevelopmentCodeFragment
Since: 2.3.0
Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.
Example
class SuspectCode {
public function doSomething(array $items)
{
foreach ($items as $i => $item) {
// …
if ('qafoo' == $item) var_dump($i);
// …
}
}
}
Source https://phpmd.org/rules/design.html#developmentcodefragment
trace accesses the super-global variable $_SERVER. Open
public static function trace($exception, $output = self::EXCEPTION_TRACE_HTML)
{
$simpleJsonTrace = false;
if ($simpleJsonTrace && Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') {
$output = self::EXCEPTION_TRACE_LOG;
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
Method trace
has 110 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function trace($exception, $output = self::EXCEPTION_TRACE_HTML)
{
$simpleJsonTrace = false;
if ($simpleJsonTrace && Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') {
$output = self::EXCEPTION_TRACE_LOG;
Function trace
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
public static function trace($exception, $output = self::EXCEPTION_TRACE_HTML)
{
$simpleJsonTrace = false;
if ($simpleJsonTrace && Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') {
$output = self::EXCEPTION_TRACE_LOG;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The class Ajde_Exception_Handler has an overall complexity of 78 which is very high. The configured complexity threshold is 50. Open
class Ajde_Exception_Handler extends Ajde_Object_Static
{
const EXCEPTION_TRACE_HTML = 1;
const EXCEPTION_TRACE_ONLY = 3;
const EXCEPTION_TRACE_LOG = 2;
- Exclude checks
File Handler.php
has 280 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
class Ajde_Exception_Handler extends Ajde_Object_Static
{
const EXCEPTION_TRACE_HTML = 1;
Method embedScript
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected static function embedScript($filename = null, $line = null, $arguments = null, $expand = false)
{
$lineOffset = 5;
$file = '';
Function embedScript
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
protected static function embedScript($filename = null, $line = null, $arguments = null, $expand = false)
{
$lineOffset = 5;
$file = '';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method getErrorType
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getErrorType($type)
{
switch ($type) {
case 1:
return 'E_ERROR';
Function handler
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function handler($exception)
{
try {
if (config('app.debug') === true) {
if (!((get_class($exception) == 'Ajde_Exception' || is_subclass_of($exception, 'Ajde_Exception')) && !$exception->traceOnOutput())
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return 'E_DEPRECATED';
Avoid too many return
statements within this method. Open
return 'E_CORE_ERROR';
Avoid too many return
statements within this method. Open
return 'E_USER_ERROR';
Avoid too many return
statements within this method. Open
return Ajde_Log::CHANNEL_EXCEPTION;
Avoid too many return
statements within this method. Open
return 'E_USER_DEPRECATED';
Avoid too many return
statements within this method. Open
return 'E_COMPILE_WARNING';
Avoid too many return
statements within this method. Open
return 'E_USER_WARNING';
Avoid too many return
statements within this method. Open
return 'E_USER_NOTICE';
Avoid too many return
statements within this method. Open
return 'E_COMPILE_ERROR';
Avoid too many return
statements within this method. Open
return 'E_STRICT';
Avoid too many return
statements within this method. Open
return 'E_CORE_WARNING';
Avoid too many return
statements within this method. Open
return 'E_RECOVERABLE_ERROR';
Avoid too many return
statements within this method. Open
return Ajde_Log::LEVEL_ERROR;
Avoid too many return
statements within this method. Open
return 'E_ALL';
The method trace() has an NPath complexity of 16360. The configured NPath complexity threshold is 200. Open
public static function trace($exception, $output = self::EXCEPTION_TRACE_HTML)
{
$simpleJsonTrace = false;
if ($simpleJsonTrace && Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') {
$output = self::EXCEPTION_TRACE_LOG;
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method trace() has 124 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public static function trace($exception, $output = self::EXCEPTION_TRACE_HTML)
{
$simpleJsonTrace = false;
if ($simpleJsonTrace && Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') {
$output = self::EXCEPTION_TRACE_LOG;
- Exclude checks
The method getErrorType() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
public static function getErrorType($type)
{
switch ($type) {
case 1:
return 'E_ERROR';
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method trace() has a Cyclomatic Complexity of 28. The configured cyclomatic complexity threshold is 10. Open
public static function trace($exception, $output = self::EXCEPTION_TRACE_HTML)
{
$simpleJsonTrace = false;
if ($simpleJsonTrace && Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') {
$output = self::EXCEPTION_TRACE_LOG;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The method embedScript has a boolean flag argument $expand, which is a certain sign of a Single Responsibility Principle violation. Open
protected static function embedScript($filename = null, $line = null, $arguments = null, $expand = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
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.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '32', column '23'). Open
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class 'Ajde_Exception_Log' in method 'handler'. Open
Ajde_Exception_Log::logException($exception);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
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.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method handler uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
Ajde_Exception_Log::logException($exception);
Ajde_Http_Response::redirectServerError();
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
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.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'Ajde_Http_Response' in method 'handler'. Open
Ajde_Http_Response::redirectServerError();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
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.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'Kint' in method 'trace'. Open
Kint::dump($dump[0]);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
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.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method getExceptionChannelMap uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return Ajde_Log::CHANNEL_EXCEPTION;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
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.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method embedScript uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$file .= $lineNumber.' '.($lines[$i]);
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
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.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid assigning values to variables in if clauses and the like (line '130', column '25'). Open
public static function trace($exception, $output = self::EXCEPTION_TRACE_HTML)
{
$simpleJsonTrace = false;
if ($simpleJsonTrace && Ajde::app()->hasDocument() && Ajde::app()->getDocument()->getFormat() == 'json') {
$output = self::EXCEPTION_TRACE_LOG;
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
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.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method getTypeDescription uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$type = 'PHP exception '.$exception->getCode();
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
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.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'Ajde_Http_Response' in method 'handler'. Open
Ajde_Http_Response::redirectServerError();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
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.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'Ajde_Exception_Log' in method 'handler'. Open
Ajde_Exception_Log::logException($exception);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
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.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'Ajde_Core_Documentation' in method 'trace'. Open
Ajde_Core_Documentation::getUrl($exception->getCode()),
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
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.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method trace uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
echo '<pre>';
var_dump($dump[0]);
echo '</pre>';
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
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.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method handler uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
Ajde_Exception_Log::logException($exception);
Ajde_Http_Response::redirectServerError();
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
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.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'Ajde_Exception_Log' in method 'handler'. Open
Ajde_Exception_Log::logException($exception);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
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.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method trace uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$collapsed = '<div id="details">'.$exceptionDump.$exceptionMessage.$traceMessage.'</div>';
$header = '<header><h1><img src="'.config('app.rootUrl').MEDIA_DIR.'ajde-small.png">Something went wrong</h1><a href="javascript:history.go(-1);">Go back</a> <a href="#details">Show details</a></header>';
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
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.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method getExceptionLevelMap uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return Ajde_Log::LEVEL_ERROR;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
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.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'Ajde_Dump' in method 'trace'. Open
if ($dumps = Ajde_Dump::getAll()) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
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.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method handler() contains an exit expression. Open
die('An uncatched exception occured within the error handler, see the server error_log for details');
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid using count() function in for loops. Open
for ($i = max(0, $line - $lineOffset - 1); $i < min($line + $lineOffset, count($lines)); $i++) {
$lineNumber = str_repeat(' ', 4 - strlen($i + 1)).($i + 1);
if ($i == $line - 1) {
$file .= '{{{}}}'.$lineNumber.' '.($lines[$i]).'{{{/}}}';
} else {
- Read upRead up
- Exclude checks
CountInLoopExpression
Since: 2.7.0
Using count/sizeof in loops expressions is considered bad practice and is a potential source of many bugs, especially when the loop manipulates an array, as count happens on each iteration.
Example
class Foo {
public function bar()
{
$array = array();
for ($i = 0; count($array); $i++) {
// ...
}
}
}
Source https://phpmd.org/rules/design.html#countinloopexpression
TODO found Open
// TODO: only possible in PHP >= 5.3 ?
- Exclude checks
Avoid excessively long variable names like $exceptionDocumentation. Keep variable name length under 20. Open
$exceptionDocumentation = '';
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $firstApplicationFileExpanded. Keep variable name length under 20. Open
public static $firstApplicationFileExpanded = false;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid variables with short names like $id. Configured minimum length is 3. Open
$id = md5(microtime().$filename.$line);
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The class Ajde_Exception_Handler is not named in CamelCase. Open
class Ajde_Exception_Handler extends Ajde_Object_Static
{
const EXCEPTION_TRACE_HTML = 1;
const EXCEPTION_TRACE_ONLY = 3;
const EXCEPTION_TRACE_LOG = 2;
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
The method __bootstrap is not named in camelCase. Open
public static function __bootstrap()
{
// making xdebug.overload_var_dump = 1 work
if (config('app.debug')) {
ini_set('html_errors', 1);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}