modxcms/revolution

View on GitHub
core/xpdo/json/JSON.php

Summary

Maintainability
F
1 wk
Test Coverage

Function decode has a Cognitive Complexity of 88 (exceeds 5 allowed). Consider refactoring.
Open

    function decode($str)
    {
        $str = $this->reduce_string($str);

        switch (strtolower($str)) {
Severity: Minor
Found in core/xpdo/json/JSON.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 decode has 171 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    function decode($str)
    {
        $str = $this->reduce_string($str);

        switch (strtolower($str)) {
Severity: Major
Found in core/xpdo/json/JSON.php - About 6 hrs to fix

    File JSON.php has 394 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * Converts to and from JSON format.
     *
     * JSON (JavaScript Object Notation) is a lightweight data-interchange
    Severity: Minor
    Found in core/xpdo/json/JSON.php - About 5 hrs to fix

      Method encode has 121 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function encode($var)
          {
              switch (gettype($var)) {
                  case 'boolean':
                      return $var ? 'true' : 'false';
      Severity: Major
      Found in core/xpdo/json/JSON.php - About 4 hrs to fix

        Function encode has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
        Open

            function encode($var)
            {
                switch (gettype($var)) {
                    case 'boolean':
                        return $var ? 'true' : 'false';
        Severity: Minor
        Found in core/xpdo/json/JSON.php - About 4 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

        Consider simplifying this complex logical expression.
        Open

                                if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
                                    // found a comma that is not inside a string, array, etc.,
                                    // OR we've reached the end of the character list
                                    $slice = substr($chrs, $top['where'], ($c - $top['where']));
                                    array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
        Severity: Critical
        Found in core/xpdo/json/JSON.php - About 3 hrs to fix

          Avoid deeply nested control flow statements.
          Open

                                          if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
                                             ($delim == "'" && $substr_chrs_c_2 != '\\"')) {
                                              $utf8 .= $chrs{++$c};
                                          }
          Severity: Major
          Found in core/xpdo/json/JSON.php - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                        if (reset($stk) == SERVICES_JSON_IN_ARR) {
                                            // we are in an array, so just push an element onto the stack
                                            array_push($arr, $this->decode($slice));
            
                                        } elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
            Severity: Major
            Found in core/xpdo/json/JSON.php - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                          for ($i = $top['where']; $i <= $c; ++$i)
                                              $chrs = substr_replace($chrs, ' ', $i, 1);
              Severity: Major
              Found in core/xpdo/json/JSON.php - About 45 mins to fix

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

                        function Services_JSON_Error($message = 'unknown error', $code = null,
                                                     $mode = null, $options = null, $userinfo = null)
                Severity: Minor
                Found in core/xpdo/json/JSON.php - About 35 mins to fix

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

                          function Services_JSON_Error($message = 'unknown error', $code = null,
                                                       $mode = null, $options = null, $userinfo = null)
                  Severity: Minor
                  Found in core/xpdo/json/JSON.php - About 35 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return '';
                    Severity: Major
                    Found in core/xpdo/json/JSON.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                                  return $arr;
                      Severity: Major
                      Found in core/xpdo/json/JSON.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                            return '{' . join(',', $properties) . '}';
                        Severity: Major
                        Found in core/xpdo/json/JSON.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                              return $utf8;
                          Severity: Major
                          Found in core/xpdo/json/JSON.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                                    return $property;
                            Severity: Major
                            Found in core/xpdo/json/JSON.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return '"'.$ascii.'"';
                              Severity: Major
                              Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return '';
                                Severity: Major
                                Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                              return $obj;
                                  Severity: Major
                                  Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                            return $element;
                                    Severity: Major
                                    Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                      return '{' . join(',', $properties) . '}';
                                      Severity: Major
                                      Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                                return $obj;
                                        Severity: Major
                                        Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                          return '[' . join(',', $elements) . ']';
                                          Severity: Major
                                          Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                            return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
                                                                ? 'null'
                                                                : new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
                                            Severity: Major
                                            Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                                          return $property;
                                              Severity: Major
                                              Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                        return $arr;
                                                Severity: Major
                                                Found in core/xpdo/json/JSON.php - About 30 mins to fix

                                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                                  Open

                                                              case 'string':
                                                                  // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
                                                                  $ascii = '';
                                                                  $strlen_var = strlen($var);
                                                  
                                                  
                                                  Severity: Major
                                                  Found in core/xpdo/json/JSON.php and 1 other location - About 4 days to fix
                                                  manager/min/lib/FirePHP.php on lines 1158..1261

                                                  Duplicated Code

                                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                  Tuning

                                                  This issue has a mass of 867.

                                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                  Refactorings

                                                  Further Reading

                                                  Similar blocks of code found in 2 locations. Consider refactoring.
                                                  Open

                                                      function utf82utf16($utf8)
                                                      {
                                                          // oh please oh please oh please oh please oh please
                                                          if(function_exists('mb_convert_encoding')) {
                                                              return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
                                                  Severity: Major
                                                  Found in core/xpdo/json/JSON.php and 1 other location - About 7 hrs to fix
                                                  manager/min/lib/FirePHP.php on lines 1091..1122

                                                  Duplicated Code

                                                  Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                                  Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                                  When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                                  Tuning

                                                  This issue has a mass of 244.

                                                  We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                                  The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                                  If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                                  See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                                  Refactorings

                                                  Further Reading

                                                  There are no issues that match your filters.

                                                  Category
                                                  Status