baacode/json-browser

View on GitHub
src/Util.php

Summary

Maintainability
A
0 mins
Test Coverage

Function cast has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Wontfix

    public static function cast(int $asType, $value)
    {
        // get the value type
        $type = self::typeMask($value);

Severity: Minor
Found in src/Util.php - About 5 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 cast has 72 lines of code (exceeds 25 allowed). Consider refactoring.
Wontfix

    public static function cast(int $asType, $value)
    {
        // get the value type
        $type = self::typeMask($value);

Severity: Major
Found in src/Util.php - About 2 hrs to fix

    Function typeMask has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Invalid

        public static function typeMask($value, bool $onlyOne = false) : int
        {
            if (is_null($value)) {
                return JsonBrowser::TYPE_NULL;
            }
    Severity: Minor
    Found in src/Util.php - About 1 hr 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 typeMask has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Invalid

        public static function typeMask($value, bool $onlyOne = false) : int
        {
            if (is_null($value)) {
                return JsonBrowser::TYPE_NULL;
            }
    Severity: Minor
    Found in src/Util.php - About 1 hr to fix

      Function compareObjects has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Wontfix

          private static function compareObjects(\StdClass $valueOne, \StdClass $valueTwo)
          {
              foreach ($valueOne as $pName => $pValue) {
                  if (!property_exists($valueTwo, $pName) || !self::compare($valueOne->$pName, $valueTwo->$pName)) {
                      return false;
      Severity: Minor
      Found in src/Util.php - About 35 mins 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

      Avoid too many return statements within this method.
      Invalid

                      return preg_split('//u', $value, null, \PREG_SPLIT_NO_EMPTY);
      Severity: Major
      Found in src/Util.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Invalid

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

          Avoid too many return statements within this method.
          Invalid

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

            Avoid too many return statements within this method.
            Wontfix

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

              Avoid too many return statements within this method.
              Invalid

                              return new \stdClass();
              Severity: Major
              Found in src/Util.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Wontfix

                            return JsonBrowser::TYPE_ARRAY;
                Severity: Major
                Found in src/Util.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Invalid

                                  return (object) preg_split('//u', $value, null, \PREG_SPLIT_NO_EMPTY);
                  Severity: Major
                  Found in src/Util.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Invalid

                                    return (bool) strlen($value);
                    Severity: Major
                    Found in src/Util.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Wontfix

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

                        Avoid too many return statements within this method.
                        Invalid

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

                          Avoid too many return statements within this method.
                          Invalid

                                          return $value != 0;
                          Severity: Major
                          Found in src/Util.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Wontfix

                                        return JsonBrowser::TYPE_OBJECT;
                            Severity: Major
                            Found in src/Util.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Invalid

                                              return (object) ['value' => $value];
                              Severity: Major
                              Found in src/Util.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Invalid

                                                return [$value];
                                Severity: Major
                                Found in src/Util.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Invalid

                                                  return (object) ['value' => $value];
                                  Severity: Major
                                  Found in src/Util.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Invalid

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

                                      Avoid too many return statements within this method.
                                      Invalid

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

                                        Avoid too many return statements within this method.
                                        Invalid

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

                                          Avoid too many return statements within this method.
                                          Invalid

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

                                            Avoid too many return statements within this method.
                                            Invalid

                                                            return [$value];
                                            Severity: Major
                                            Found in src/Util.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Invalid

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

                                                Avoid too many return statements within this method.
                                                Invalid

                                                                return (bool) count((array)$value);
                                                Severity: Major
                                                Found in src/Util.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Wontfix

                                                                  return count((array)$value);
                                                  Severity: Major
                                                  Found in src/Util.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Invalid

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

                                                      Function compare has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                                      Wontfix

                                                          public static function compare($valueOne, $valueTwo) : bool
                                                          {
                                                      
                                                              // fast-path for type-equal (or instance-equal) values
                                                              if ($valueOne === $valueTwo) {
                                                      Severity: Minor
                                                      Found in src/Util.php - About 25 mins 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

                                                      There are no issues that match your filters.

                                                      Category
                                                      Status