modxcms/revolution

View on GitHub
core/xpdo/om/xpdoquery.class.php

Summary

Maintainability
F
1 wk
Test Coverage

Function parseConditions has a Cognitive Complexity of 119 (exceeds 5 allowed). Consider refactoring.
Open

    public function parseConditions($conditions, $conjunction = xPDOQuery::SQL_AND) {
        $result= array ();
        $pk= $this->xpdo->getPK($this->_class);
        $pktype= $this->xpdo->getPKType($this->_class);
        $fieldMeta= $this->xpdo->getFieldMeta($this->_class, true);
Severity: Minor
Found in core/xpdo/om/xpdoquery.class.php - About 2 days 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

File xpdoquery.class.php has 671 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*
 * Copyright 2010-2015 by MODX, LLC.
 *
 * This file is part of xPDO.
Severity: Major
Found in core/xpdo/om/xpdoquery.class.php - About 1 day to fix

    Function join has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
    Open

        public function join($class, $alias= '', $type= xPDOQuery::SQL_JOIN_CROSS, $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
            if ($this->xpdo->loadClass($class)) {
                $alias= $alias ? $alias : $class;
                $target= & $this->query['from']['joins'];
                $targetIdx= count($target);
    Severity: Minor
    Found in core/xpdo/om/xpdoquery.class.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

    Function bindGraphNode has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

        public function bindGraphNode($parentClass, $parentAlias, $classAlias, $relations) {
            if ($fkMeta= $this->xpdo->getFKDefinition($parentClass, $classAlias)) {
                $class= $fkMeta['class'];
                $local= $fkMeta['local'];
                $foreign= $fkMeta['foreign'];
    Severity: Minor
    Found in core/xpdo/om/xpdoquery.class.php - About 6 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 parseConditions has 148 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function parseConditions($conditions, $conjunction = xPDOQuery::SQL_AND) {
            $result= array ();
            $pk= $this->xpdo->getPK($this->_class);
            $pktype= $this->xpdo->getPKType($this->_class);
            $fieldMeta= $this->xpdo->getFieldMeta($this->_class, true);
    Severity: Major
    Found in core/xpdo/om/xpdoquery.class.php - About 5 hrs to fix

      xPDOQuery has 34 functions (exceeds 20 allowed). Consider refactoring.
      Open

      abstract class xPDOQuery extends xPDOCriteria {
          const SQL_AND = 'AND';
          const SQL_OR = 'OR';
          const SQL_JOIN_CROSS = 'JOIN';
          const SQL_JOIN_LEFT = 'LEFT JOIN';
      Severity: Minor
      Found in core/xpdo/om/xpdoquery.class.php - About 4 hrs to fix

        Function hydrateGraphNode has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
        Open

            public function hydrateGraphNode(& $row, & $instance, $alias, $relations) {
                $relObj= null;
                if ($relationMeta= $instance->getFKDefinition($alias)) {
                    if ($row[$alias.'_'.$relationMeta['foreign']] != null) {
                        $relObj = $this->xpdo->call($relationMeta['class'], '_loadInstance', array(& $this->xpdo, $relationMeta['class'], $alias, $row));
        Severity: Minor
        Found in core/xpdo/om/xpdoquery.class.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 buildConditionalClause has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

            public function buildConditionalClause($conditions, & $conjunction = xPDOQuery::SQL_AND, $isFirst = true) {
                $clause= '';
                if (is_array($conditions)) {
                    $groups= count($conditions);
                    $currentGroup= 1;
        Severity: Minor
        Found in core/xpdo/om/xpdoquery.class.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 bindGraph has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
        Open

            public function bindGraph($graph) {
                if (is_string($graph)) {
                    $graph= $this->xpdo->fromJSON($graph);
                }
                if (is_array ($graph)) {
        Severity: Minor
        Found in core/xpdo/om/xpdoquery.class.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 set has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public function set(array $values) {
                $fieldMeta= $this->xpdo->getFieldMeta($this->_class);
                $fieldAliases= $this->xpdo->getFieldAliases($this->_class);
                foreach ($values as $key => $value) {
                    $type= null;
        Severity: Minor
        Found in core/xpdo/om/xpdoquery.class.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 join has 51 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function join($class, $alias= '', $type= xPDOQuery::SQL_JOIN_CROSS, $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
                if ($this->xpdo->loadClass($class)) {
                    $alias= $alias ? $alias : $class;
                    $target= & $this->query['from']['joins'];
                    $targetIdx= count($target);
        Severity: Major
        Found in core/xpdo/om/xpdoquery.class.php - About 2 hrs to fix

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

              public function hydrateGraph($rows, $cacheFlag = true) {
                  $instances= array ();
                  $collectionCaching = $this->xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
                  if (is_object($rows)) {
                      if ($cacheFlag && $this->xpdo->_cacheEnabled && $collectionCaching > 0) {
          Severity: Minor
          Found in core/xpdo/om/xpdoquery.class.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 bindGraphNode has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function bindGraphNode($parentClass, $parentAlias, $classAlias, $relations) {
                  if ($fkMeta= $this->xpdo->getFKDefinition($parentClass, $classAlias)) {
                      $class= $fkMeta['class'];
                      $local= $fkMeta['local'];
                      $foreign= $fkMeta['foreign'];
          Severity: Minor
          Found in core/xpdo/om/xpdoquery.class.php - About 1 hr to fix

            Method buildConditionalClause has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function buildConditionalClause($conditions, & $conjunction = xPDOQuery::SQL_AND, $isFirst = true) {
                    $clause= '';
                    if (is_array($conditions)) {
                        $groups= count($conditions);
                        $currentGroup= 1;
            Severity: Minor
            Found in core/xpdo/om/xpdoquery.class.php - About 1 hr to fix

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

                  public function select($columns= '*') {
                      if (!is_array($columns)) {
                          $columns= trim($columns);
                          if ($columns == '*' || $columns === $this->_alias . '.*' || $columns === $this->xpdo->escape($this->_alias) . '.*') {
                              $columns= $this->xpdo->getSelectColumns($this->_class, $this->_alias, $this->_alias . '_');
              Severity: Minor
              Found in core/xpdo/om/xpdoquery.class.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 isConditionalClause has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function isConditionalClause($string) {
                      $matched= false;
                      if (is_string($string)) {
                          if (!static::isValidClause($string)) {
                              throw new xPDOException("SQL injection attempt detected: {$string}");
              Severity: Minor
              Found in core/xpdo/om/xpdoquery.class.php - About 55 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

              Method join has 7 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  public function join($class, $alias= '', $type= xPDOQuery::SQL_JOIN_CROSS, $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
              Severity: Major
              Found in core/xpdo/om/xpdoquery.class.php - About 50 mins to fix

                Method leftJoin has 6 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    public function leftJoin($class, $alias= '', $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
                Severity: Minor
                Found in core/xpdo/om/xpdoquery.class.php - About 45 mins to fix

                  Method rightJoin has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                      public function rightJoin($class, $alias= '', $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
                  Severity: Minor
                  Found in core/xpdo/om/xpdoquery.class.php - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if (!empty($localCriteria)) {
                                                $conditions = array($localCriteria, $conditions);
                                            }
                    Severity: Major
                    Found in core/xpdo/om/xpdoquery.class.php - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if (is_array($fkMeta['criteria']['foreign'])) {
                                                  foreach ($fkMeta['criteria']['foreign'] as $critKey => $critVal) {
                                                      if (is_numeric($critKey)) {
                                                          $foreignCriteria[] = $critVal;
                                                      } else {
                      Severity: Major
                      Found in core/xpdo/om/xpdoquery.class.php - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if (!empty($foreignCriteria)) {
                                                    $conditions = array($foreignCriteria, $conditions);
                                                }
                        Severity: Major
                        Found in core/xpdo/om/xpdoquery.class.php - About 45 mins to fix

                          Method innerJoin has 6 arguments (exceeds 4 allowed). Consider refactoring.
                          Open

                              public function innerJoin($class, $alias= '', $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
                          Severity: Minor
                          Found in core/xpdo/om/xpdoquery.class.php - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                    if (is_array($fkMeta['criteria']['local'])) {
                                                        foreach ($fkMeta['criteria']['local'] as $critKey => $critVal) {
                                                            if (is_numeric($critKey)) {
                                                                $localCriteria[] = $critVal;
                                                            } else {
                            Severity: Major
                            Found in core/xpdo/om/xpdoquery.class.php - About 45 mins to fix

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

                                  public function condition(& $target, $conditions= '1', $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
                              Severity: Minor
                              Found in core/xpdo/om/xpdoquery.class.php - About 35 mins to fix

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

                                    public function hydrateGraphParent(& $instances, $row) {
                                        $hydrated = false;
                                        $instance = $this->xpdo->call($this->getClass(), '_loadInstance', array(& $this->xpdo, $this->getClass(), $this->getAlias(), $row));
                                        if (is_object($instance)) {
                                            $pk= $instance->getPrimaryKey();
                                Severity: Minor
                                Found in core/xpdo/om/xpdoquery.class.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 __construct has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function __construct(& $xpdo, $class, $criteria= null) {
                                        parent :: __construct($xpdo);
                                        if ($class= $this->xpdo->loadClass($class)) {
                                            $this->_class= $class;
                                            $this->_alias= $class;
                                Severity: Minor
                                Found in core/xpdo/om/xpdoquery.class.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 distinct has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    public function distinct($on = null) {
                                        if ($on === null) {
                                            if (empty($this->query['distinct']) || $this->query['distinct'] !== 'DISTINCT') {
                                                $this->query['distinct']= 'DISTINCT';
                                            } else {
                                Severity: Minor
                                Found in core/xpdo/om/xpdoquery.class.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

                                                    if (is_int($key)) {
                                                        if (is_array($val)) {
                                                            $result[]= $this->parseConditions($val, $conjunction);
                                                            continue;
                                                        } elseif ($this->isConditionalClause($val)) {
                                Severity: Major
                                Found in core/xpdo/om/xpdoquery.class.php and 1 other location - About 1 hr to fix
                                core/xpdo/om/sqlsrv/xpdoquery.class.php on lines 72..154

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

                                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