src/LJSON.php

Summary

Maintainability
F
5 days
Test Coverage
A
100%

The method evaly() contains an eval expression.
Open

        return eval('return ' . $string . ';');
Severity: Minor
Found in src/LJSON.php by phpmd

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 = '';

Severity: Minor
Found in src/LJSON.php - About 1 day to fix

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 = '';

Severity: Major
Found in src/LJSON.php - About 1 day to fix

File LJSON.php has 372 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
namespace LJSON;

/**
 * Class LJSON
Severity: Minor
Found in src/LJSON.php - About 4 hrs to fix

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
Severity: Minor
Found in src/LJSON.php by phpmd

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)
Severity: Minor
Found in src/LJSON.php - About 3 hrs to fix

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)
Severity: Major
Found in src/LJSON.php - About 2 hrs to fix

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);
Severity: Major
Found in src/LJSON.php - About 1 hr to fix

Avoid deeply nested control flow statements.
Open

                        if (strlen($use) > 0) {
                            $use = 'use(' . $use . ')';
                        }
Severity: Major
Found in src/LJSON.php - About 45 mins to fix

Method parseValue has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    protected static function parseValue($json, &$pos, $assoc = false, $variables = [], $options = 0)
Severity: Minor
Found in src/LJSON.php - About 35 mins to fix

Avoid too many return statements within this method.
Open

                    return $parameter1 / $parameter2;
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return '"' . str_replace('"', '\"', $result) . '"';
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return '[]';
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                    return $result;
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return '';
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return rtrim($result, ',') . '}';
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return $result;
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return '[' . implode(',', $value) . ']';
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return $value->getParameterResult();
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                    return $parameter1 * $parameter2;
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return "false";
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return $result;
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return '';
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return $result;
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return '[' . implode(',', $elements) . ']';
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return '';
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return null;
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

        return static::withLib($stdLibrary, $function);
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

            return "(" . implode(',', array_keys($params)) . ") => (" . $value . ")";
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                        return 'function(' . implode(',', $parameters) . ')' . $use . '{return ' . $body . ';}';
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                    return $result;
Severity: Major
Found in src/LJSON.php - About 30 mins to fix

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 = '';

Severity: Minor
Found in src/LJSON.php by phpmd

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)
Severity: Minor
Found in src/LJSON.php by phpmd

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 = '';

Severity: Minor
Found in src/LJSON.php by phpmd

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)
Severity: Minor
Found in src/LJSON.php by phpmd

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 = '';

Severity: Minor
Found in src/LJSON.php by phpmd

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);
Severity: Minor
Found in src/LJSON.php by phpmd

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);
Severity: Minor
Found in src/LJSON.php by phpmd

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);
            }
Severity: Minor
Found in src/LJSON.php by phpmd

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

There are no issues that match your filters.

Category
Status