The method evaly() contains an eval expression. Open
return eval('return ' . $string . ';');
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
EvalExpression
Since: 0.2
An eval-expression is untestable, a security risk and bad practice. Therefore it should be avoided. Consider to replace the eval-expression with regular code.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
eval('$param = 23;');
}
}
}
Source https://phpmd.org/rules/design.html#evalexpression
Function parseValue
has a Cognitive Complexity of 83 (exceeds 5 allowed). Consider refactoring. Open
protected static function parseValue($json, &$pos, $assoc = false, $variables = [], $options = 0)
{
$length = strlen($json);
$result = '';
- Read upRead up
- Create a ticketCreate a ticket
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 parseValue
has 211 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected static function parseValue($json, &$pos, $assoc = false, $variables = [], $options = 0)
{
$length = strlen($json);
$result = '';
- Create a ticketCreate a ticket
File LJSON.php
has 372 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
namespace LJSON;
/**
* Class LJSON
- Create a ticketCreate a ticket
The class LJSON has an overall complexity of 134 which is very high. The configured complexity threshold is 50. Open
class LJSON
{
const RETURN_UNDEFINED_AS_SPECIAL_CLASS = 1073741824; // 2^30
/**
* @var bool
- Create a ticketCreate a ticket
- Exclude checks
Function stringify
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public static function stringify($value, $parameterCount = 0)
{
if (is_null($value) || is_bool($value)
|| is_int($value) || is_float($value) || is_double($value) || is_numeric($value)
|| is_string($value)
- Read upRead up
- Create a ticketCreate a ticket
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 stringify
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function stringify($value, $parameterCount = 0)
{
if (is_null($value) || is_bool($value)
|| is_int($value) || is_float($value) || is_double($value) || is_numeric($value)
|| is_string($value)
- Create a ticketCreate a ticket
Consider simplifying this complex logical expression. Open
if (is_null($value) || is_bool($value)
|| is_int($value) || is_float($value) || is_double($value) || is_numeric($value)
|| is_string($value)
) {
return json_encode($value);
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if (strlen($use) > 0) {
$use = 'use(' . $use . ')';
}
- Create a ticketCreate a ticket
Method parseValue
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
protected static function parseValue($json, &$pos, $assoc = false, $variables = [], $options = 0)
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $parameter1 / $parameter2;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return '"' . str_replace('"', '\"', $result) . '"';
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return '[]';
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $result;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return rtrim($result, ',') . '}';
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $result;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return '[' . implode(',', $value) . ']';
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $value->getParameterResult();
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $parameter1 * $parameter2;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return "false";
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $result;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $result;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return '[' . implode(',', $elements) . ']';
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return null;
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return static::withLib($stdLibrary, $function);
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return "(" . implode(',', array_keys($params)) . ") => (" . $value . ")";
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return 'function(' . implode(',', $parameters) . ')' . $use . '{return ' . $body . ';}';
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return $result;
- Create a ticketCreate a ticket
The method parseValue() has an NPath complexity of 3551727674880. The configured NPath complexity threshold is 200. Open
protected static function parseValue($json, &$pos, $assoc = false, $variables = [], $options = 0)
{
$length = strlen($json);
$result = '';
- Read upRead up
- Create a ticketCreate a ticket
- 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 stringify() has an NPath complexity of 33696. The configured NPath complexity threshold is 200. Open
public static function stringify($value, $parameterCount = 0)
{
if (is_null($value) || is_bool($value)
|| is_int($value) || is_float($value) || is_double($value) || is_numeric($value)
|| is_string($value)
- Read upRead up
- Create a ticketCreate a ticket
- 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 parseValue() has 236 lines of code. Current threshold is set to 100. Avoid really long methods. Open
protected static function parseValue($json, &$pos, $assoc = false, $variables = [], $options = 0)
{
$length = strlen($json);
$result = '';
- Create a ticketCreate a ticket
- Exclude checks
The method stringify() has a Cyclomatic Complexity of 23. The configured cyclomatic complexity threshold is 10. Open
public static function stringify($value, $parameterCount = 0)
{
if (is_null($value) || is_bool($value)
|| is_int($value) || is_float($value) || is_double($value) || is_numeric($value)
|| is_string($value)
- Read upRead up
- Create a ticketCreate a ticket
- 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 parseValue() has a Cyclomatic Complexity of 87. The configured cyclomatic complexity threshold is 10. Open
protected static function parseValue($json, &$pos, $assoc = false, $variables = [], $options = 0)
{
$length = strlen($json);
$result = '';
- Read upRead up
- Create a ticketCreate a ticket
- 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
Missing class import via use statement (line '213', column '19'). Open
throw new \Exception('Could not get Parsed', 1445505229);
- Read upRead up
- Create a ticketCreate a ticket
- 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
Missing class import via use statement (line '87', column '31'). Open
$reflection = new \ReflectionFunction($value);
- Read upRead up
- Create a ticketCreate a ticket
- 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 LJSON\count() function in for loops. Open
for ($i = 0; $i < count($reflection->getParameters()); $i++) {
$paramName = "v" . ($i + $parameterCount);
$params[$paramName] = new Parameter($paramName);
}
- Read upRead up
- Create a ticketCreate a ticket
- 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++) {
// ...
}
}
}