strata-mvc/strata

View on GitHub
src/Utility/Hash.php

Summary

Maintainability
F
1 wk
Test Coverage

File Hash.php has 679 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
Severity: Major
Found in src/Utility/Hash.php - About 1 day to fix

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

        protected static function _matches(array $data, $selector)
        {
            preg_match_all(
                '/(\[ (?P<attr>[^=><!]+?) (\s* (?P<op>[><!]?[=]|[><]) \s* (?P<val>(?:\/.*?\/ | [^\]]+)) )? \])/x',
                $selector,
    Severity: Minor
    Found in src/Utility/Hash.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

    Hash has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Hash
    {
    
        /**
     * Get a single value specified by $path out of $data.
    Severity: Minor
    Found in src/Utility/Hash.php - About 3 hrs to fix

      Function _simpleOp has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          protected static function _simpleOp($op, $data, $path, $values = null)
          {
              $_list =& $data;
      
              $count = count($path);
      Severity: Minor
      Found in src/Utility/Hash.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

      Function combine has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function combine(array $data, $keyPath, $valuePath = null, $groupPath = null)
          {
              if (empty($data)) {
                  return array();
              }
      Severity: Minor
      Found in src/Utility/Hash.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

      Function extract has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function extract(array $data, $path)
          {
              if (empty($path)) {
                  return $data;
              }
      Severity: Minor
      Found in src/Utility/Hash.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

      Consider simplifying this complex logical expression.
      Open

                  if ($op === '=' && $val && $val[0] === '/') {
                      if (!preg_match($val, $prop)) {
                          return false;
                      }
                  } elseif (($op === '=' && $prop != $val)
      Severity: Critical
      Found in src/Utility/Hash.php - About 3 hrs to fix

        Function expand has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function expand($data, $separator = '.')
            {
                $result = array();
        
                $stack = array();
        Severity: Minor
        Found in src/Utility/Hash.php - About 2 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

        Function sort has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function sort(array $data, $path, $dir = 'asc', $type = 'regular')
            {
                if (empty($data)) {
                    return array();
                }
        Severity: Minor
        Found in src/Utility/Hash.php - About 2 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

        Function nest has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function nest(array $data, $options = array())
            {
                if (!$data) {
                    return $data;
                }
        Severity: Minor
        Found in src/Utility/Hash.php - About 2 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 nest has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function nest(array $data, $options = array())
            {
                if (!$data) {
                    return $data;
                }
        Severity: Major
        Found in src/Utility/Hash.php - About 2 hrs to fix

          Method sort has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public static function sort(array $data, $path, $dir = 'asc', $type = 'regular')
              {
                  if (empty($data)) {
                      return array();
                  }
          Severity: Major
          Found in src/Utility/Hash.php - About 2 hrs to fix

            Method combine has 49 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public static function combine(array $data, $keyPath, $valuePath = null, $groupPath = null)
                {
                    if (empty($data)) {
                        return array();
                    }
            Severity: Minor
            Found in src/Utility/Hash.php - About 1 hr to fix

              Function remove has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function remove(array $data, $path)
                  {
                      if (strpos($path, '[') === false) {
                          $tokens = explode('.', $path);
                      } else {
              Severity: Minor
              Found in src/Utility/Hash.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

              Function normalize has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function normalize(array $data, $assoc = true)
                  {
                      $keys = array_keys($data);
                      $count = count($keys);
                      $numeric = true;
              Severity: Minor
              Found in src/Utility/Hash.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

              Function insert has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function insert(array $data, $path, $values = null)
                  {
                      if (strpos($path, '[') === false) {
                          $tokens = explode('.', $path);
                      } else {
              Severity: Minor
              Found in src/Utility/Hash.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

              Function contains has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function contains(array $data, array $needle)
                  {
                      if (empty($data) || empty($needle)) {
                          return false;
                      }
              Severity: Minor
              Found in src/Utility/Hash.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

              Function merge has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function merge(array $data, $merge)
                  {
                      $args = array_slice(func_get_args(), 1);
                      $return = $data;
              
              
              Severity: Minor
              Found in src/Utility/Hash.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 _matches has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected static function _matches(array $data, $selector)
                  {
                      preg_match_all(
                          '/(\[ (?P<attr>[^=><!]+?) (\s* (?P<op>[><!]?[=]|[><]) \s* (?P<val>(?:\/.*?\/ | [^\]]+)) )? \])/x',
                          $selector,
              Severity: Minor
              Found in src/Utility/Hash.php - About 1 hr to fix

                Function get has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                Open

                    public static function get(array $data, $path, $default = null)
                    {
                        if (empty($data) || $path === '' || $path === null) {
                            return $default;
                        }
                Severity: Minor
                Found in src/Utility/Hash.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 extract has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public static function extract(array $data, $path)
                    {
                        if (empty($path)) {
                            return $data;
                        }
                Severity: Minor
                Found in src/Utility/Hash.php - About 1 hr to fix

                  Method expand has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public static function expand($data, $separator = '.')
                      {
                          $result = array();
                  
                          $stack = array();
                  Severity: Minor
                  Found in src/Utility/Hash.php - About 1 hr to fix

                    Method _simpleOp has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        protected static function _simpleOp($op, $data, $path, $values = null)
                        {
                            $_list =& $data;
                    
                            $count = count($path);
                    Severity: Minor
                    Found in src/Utility/Hash.php - About 1 hr to fix

                      Function flatten has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                      Open

                          public static function flatten(array $data, $separator = '.')
                          {
                              $result = array();
                              $stack = array();
                              $path = null;
                      Severity: Minor
                      Found in src/Utility/Hash.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 remove has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public static function remove(array $data, $path)
                          {
                              if (strpos($path, '[') === false) {
                                  $tokens = explode('.', $path);
                              } else {
                      Severity: Minor
                      Found in src/Utility/Hash.php - About 1 hr to fix

                        Function format has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public static function format(array $data, array $paths, $format)
                            {
                                $extracted = array();
                                $count = count($paths);
                        
                        
                        Severity: Minor
                        Found in src/Utility/Hash.php - About 45 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

                        Function maxDimensions has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public static function maxDimensions(array $data)
                            {
                                $depth = array();
                                if (is_array($data) && reset($data) !== false) {
                                    foreach ($data as $value) {
                        Severity: Minor
                        Found in src/Utility/Hash.php - About 45 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

                        Function _squash has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            protected static function _squash($data, $key = null)
                            {
                                $stack = array();
                                foreach ($data as $k => $r) {
                                    $id = $k;
                        Severity: Minor
                        Found in src/Utility/Hash.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

                        Function mergeDiff has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public static function mergeDiff(array $data, $compare)
                            {
                                if (empty($data) && !empty($compare)) {
                                    return $compare;
                                }
                        Severity: Minor
                        Found in src/Utility/Hash.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.
                        Open

                                return array_combine($keys, $vals);
                        Severity: Major
                        Found in src/Utility/Hash.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return true;
                          Severity: Major
                          Found in src/Utility/Hash.php - About 30 mins to fix

                            Function dimensions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                            Open

                                public static function dimensions(array $data)
                                {
                                    if (empty($data)) {
                                        return 0;
                                    }
                            Severity: Minor
                            Found in src/Utility/Hash.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

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

                                        while (!empty($stack)) {
                                            foreach ($stack as $curKey => &$curMerge) {
                                                foreach ($curMerge[0] as $key => &$val) {
                                                    if (!empty($curMerge[1][$key]) && (array)$curMerge[1][$key] === $curMerge[1][$key] && (array)$val === $val) {
                                                        $stack[] = array(&$val, &$curMerge[1][$key]);
                            Severity: Major
                            Found in src/Utility/Hash.php and 1 other location - About 4 hrs to fix
                            src/Utility/Hash.php on lines 717..731

                            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 170.

                            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

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

                                    while (!empty($stack)) {
                                        foreach ($stack as $curKey => &$curMerge) {
                                            foreach ($curMerge[0] as $key => &$val) {
                                                if (!empty($curMerge[1][$key]) && (array)$curMerge[1][$key] === $curMerge[1][$key] && (array)$val === $val) {
                                                    $stack[] = array(&$val, &$curMerge[1][$key]);
                            Severity: Major
                            Found in src/Utility/Hash.php and 1 other location - About 4 hrs to fix
                            src/Utility/Hash.php on lines 674..688

                            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 170.

                            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