Function save
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public static function save($key, array &$array, $value, $replace = true)
{
if ($key === '') {
$array[ $key ] = $value;
- 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 uArray has an overall complexity of 72 which is very high. The configured complexity threshold is 50. Open
class uArray
{
/**
* Проверяет, является ли массив ассоциативным
- Exclude checks
Method parseAndValidateKeys
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
private static function parseAndValidateKeys($key, array &$array, $mode = '')
{
$parseInfo = [
'keys' => [],
'lastKey' => '',
Function parseAndValidateKeys
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
private static function parseAndValidateKeys($key, array &$array, $mode = '')
{
$parseInfo = [
'keys' => [],
'lastKey' => '',
- 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
Function isAssociative
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public static function isAssociative($array, $allStrings = true)
{
if (!is_array($array) || empty($array)) {
return false;
}
- 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 save
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function save($key, array &$array, $value, $replace = true)
{
if ($key === '') {
$array[ $key ] = $value;
Function isIndexed
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function isIndexed(array $array, $consecutive = false)
{
if (empty($array)) {
return true;
}
- 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
Function get
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function get($key, array $array, $default = null, $ignoreString = true)
{
if ($key === '') {
if (!array_key_exists((string)$key, $array)) {
return $default;
- 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 false;
Avoid too many return
statements within this method. Open
return ($parseInfo['completed'] && ($parseInfo['isExists'] || $parseInfo['isString'])) ? $parseInfo['value'] : $default;
The method save() has an NPath complexity of 228. The configured NPath complexity threshold is 200. Open
public static function save($key, array &$array, $value, $replace = true)
{
if ($key === '') {
$array[ $key ] = $value;
- 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 parseAndValidateKeys() has an NPath complexity of 9720. The configured NPath complexity threshold is 200. Open
private static function parseAndValidateKeys($key, array &$array, $mode = '')
{
$parseInfo = [
'keys' => [],
'lastKey' => '',
- 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 get() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public static function get($key, array $array, $default = null, $ignoreString = true)
{
if ($key === '') {
if (!array_key_exists((string)$key, $array)) {
return $default;
- 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 save() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public static function save($key, array &$array, $value, $replace = true)
{
if ($key === '') {
$array[ $key ] = $value;
- 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 parseAndValidateKeys() has a Cyclomatic Complexity of 21. The configured cyclomatic complexity threshold is 10. Open
private static function parseAndValidateKeys($key, array &$array, $mode = '')
{
$parseInfo = [
'keys' => [],
'lastKey' => '',
- 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
Avoid using undefined variables such as '$mCurSource' which will lead to PHP notices. Open
$mCurSource[ $key ] = [];
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
The method isIndexed has a boolean flag argument $consecutive, which is a certain sign of a Single Responsibility Principle violation. Open
public static function isIndexed(array $array, $consecutive = 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
The method isAssociative has a boolean flag argument $allStrings, which is a certain sign of a Single Responsibility Principle violation. Open
public static function isAssociative($array, $allStrings = 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 get has a boolean flag argument $ignoreString, which is a certain sign of a Single Responsibility Principle violation. Open
public static function get($key, array $array, $default = null, $ignoreString = 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 save has a boolean flag argument $replace, which is a certain sign of a Single Responsibility Principle violation. Open
public static function save($key, array &$array, $value, $replace = 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
Avoid assigning values to variables in if clauses and the like (line '319', column '26'). Open
private static function parseAndValidateKeys($key, array &$array, $mode = '')
{
$parseInfo = [
'keys' => [],
'lastKey' => '',
- 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
Avoid unused local variables such as '$mCurSource'. Open
$mCurSource[ $key ] = [];
- 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
Avoid unused local variables such as '$value'. Open
foreach ($array as $key => $value) {
- 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
The class uArray is not named in CamelCase. Open
class uArray
{
/**
* Проверяет, является ли массив ассоциативным
- 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
Avoid variables with short names like $m. Configured minimum length is 3. Open
function ($m) use (&$parseInfo, &$array) {
- 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
Only one argument is allowed per line in a multi-line function call Open
}, $key);
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
$parseInfo['isBroken'] = (bool)preg_replace_callback(['/(?J:\[([\'"])(?<el>.*?)\1\]|(?<el>\]?[^\[]+)|\[(?<el>(?:[^\[\]]+|(?R))*)\])/'],
- Exclude checks
Inline control structures are not allowed Open
if (!count($array)) return null;
- Exclude checks
Line exceeds 120 characters; contains 132 characters Open
* Массив индексируем, если все ключи массива - цифры. Если `$consecutive` == true,
- Exclude checks
Inline control structures are not allowed Open
if (!count($array)) return null;
- Exclude checks
Line exceeds 120 characters; contains 145 characters Open
* то масссив является ассоциативным, если хотя бы один ключ является строкой.
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
return ($parseInfo['completed'] && ($parseInfo['isExists'] || $parseInfo['isString'])) ? $parseInfo['value'] : $default;
- Exclude checks
Class name "uArray" is not in camel caps format Open
class uArray
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
$parseInfo['isBroken'] = (bool)preg_replace_callback(['/(?J:\[([\'"])(?<el>.*?)\1\]|(?<el>\]?[^\[]+)|\[(?<el>(?:[^\[\]]+|(?R))*)\])/'],
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
}, $key);
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
if (($parseInfo['isExists'] = array_key_exists((string)$m['el'],
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 12 Open
}, $key);
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$parseInfo['currEl']) && is_array($parseInfo['currEl']))
- Exclude checks
Multi-line function call not indented correctly; expected 20 spaces but found 28 Open
$parseInfo['currEl']) && is_array($parseInfo['currEl']))
- Exclude checks