The method setOptions() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function setOptions($optionsConfig)
{
$optionsConfig = (array)$optionsConfig;
$padding = str_repeat(' ', self::optionPadding);
- 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 tidyArray has a boolean flag argument $tidyString, which is a certain sign of a Single Responsibility Principle violation. Open
public function tidyArray($array, $tidyString = true)
- 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
The method alignLines uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// the information on the left is longer than the padding size
$firstLine = $addon;
}
- 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 unused local variables such as '$callback'. Open
$callback = create_function('$string', "return '$padding' . \$string;");
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Console_GetoptPlus_Help
- Exclude checks
The class Console_GetoptPlus_Help is not named in CamelCase. Open
class Console_GetoptPlus_Help
{
/**
* The option name padding within the option descrition
*/
- 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
Class constants must be uppercase; expected USAGE but found usage Open
const usage = 'Usage: ';
- Exclude checks
Class constants must be uppercase; expected OPTIONPADDING but found optionPadding Open
const optionPadding = 30;
- Exclude checks
Class constants must be uppercase; expected OPTIONS but found options Open
const options = 'Options:';
- Exclude checks
Class constants must be uppercase; expected PARAMETERS but found parameters Open
const parameters = 'Parameters:';
- Exclude checks
Constant usage should be defined in uppercase Open
const usage = 'Usage: ';
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Constant optionPadding should be defined in uppercase Open
const optionPadding = 30;
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Constant parameters should be defined in uppercase Open
const parameters = 'Parameters:';
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Constant options should be defined in uppercase Open
const options = 'Options:';
- Read upRead up
- Exclude checks
ConstantNamingConventions
Since: 0.2
Class/Interface constant names should always be defined in uppercase.
Example
class Foo {
const MY_NUM = 0; // ok
const myTest = ""; // fail
}
Source https://phpmd.org/rules/naming.html#constantnamingconventions
Line exceeds 120 characters; contains 190 characters Open
empty($option['type']) or 'mandatory' == $option['type'] and $value = '<' . array_shift($desc) . '>' or 'optional' == $option['type'] and $value = '[' . array_shift($desc) . ']';
- Exclude checks
Class name "Console_GetoptPlus_Help" is not in camel caps format Open
class Console_GetoptPlus_Help
- Exclude checks