modxcms/revolution

View on GitHub
core/model/modx/modaccessibleobject.class.php

Summary

Maintainability
F
1 wk
Test Coverage

Function checkPolicy has a Cognitive Complexity of 125 (exceeds 5 allowed). Consider refactoring.
Open

    public function checkPolicy($criteria, $targets = null, modUser $user = null) {
        if(!$user){
            $user = & $this->xpdo->user;
        }
        if ($criteria && $this->xpdo instanceof modX && $this->xpdo->getSessionState() == modX::SESSION_STATE_INITIALIZED) {
Severity: Minor
Found in core/model/modx/modaccessibleobject.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

Function load has a Cognitive Complexity of 49 (exceeds 5 allowed). Consider refactoring.
Open

    public static function load(xPDO & $xpdo, $className, $criteria, $cacheFlag= true) {
        $instance= null;
        $fromCache= false;
        if ($className= $xpdo->loadClass($className)) {
            if (!is_object($criteria)) {
Severity: Minor
Found in core/model/modx/modaccessibleobject.class.php - About 7 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 _loadCollectionInstance has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    public static function _loadCollectionInstance(xPDO & $xpdo, array & $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag=true) {
        $loaded = false;
        if ($obj= modAccessibleObject :: _loadInstance($xpdo, $className, $criteria, $row)) {
            if (($cacheKey= $obj->getPrimaryKey()) && !$obj->isLazy()) {
                if (is_array($cacheKey)) {
Severity: Minor
Found in core/model/modx/modaccessibleobject.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 loadCollection has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    public static function loadCollection(xPDO & $xpdo, $className, $criteria= null, $cacheFlag= true) {
        $objCollection= array ();
        $fromCache = false;
        if (!$className= $xpdo->loadClass($className)) return $objCollection;
        $rows= false;
Severity: Minor
Found in core/model/modx/modaccessibleobject.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 checkPolicy has 51 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function checkPolicy($criteria, $targets = null, modUser $user = null) {
        if(!$user){
            $user = & $this->xpdo->user;
        }
        if ($criteria && $this->xpdo instanceof modX && $this->xpdo->getSessionState() == modX::SESSION_STATE_INITIALIZED) {
Severity: Major
Found in core/model/modx/modaccessibleobject.class.php - About 2 hrs to fix

    Method load has 41 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function load(xPDO & $xpdo, $className, $criteria, $cacheFlag= true) {
            $instance= null;
            $fromCache= false;
            if ($className= $xpdo->loadClass($className)) {
                if (!is_object($criteria)) {
    Severity: Minor
    Found in core/model/modx/modaccessibleobject.class.php - About 1 hr to fix

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

          public static function loadCollection(xPDO & $xpdo, $className, $criteria= null, $cacheFlag= true) {
              $objCollection= array ();
              $fromCache = false;
              if (!$className= $xpdo->loadClass($className)) return $objCollection;
              $rows= false;
      Severity: Minor
      Found in core/model/modx/modaccessibleobject.class.php - About 1 hr to fix

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

            public static function _loadCollectionInstance(xPDO & $xpdo, array & $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag=true) {
        Severity: Major
        Found in core/model/modx/modaccessibleobject.class.php - About 50 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                                  if ($applicablePolicy['principal'] == $principalId) {
                                                      if ($principalAuthority <= $applicablePolicy['authority']) {
                                                          if (!$applicablePolicy['policy']) {
                                                              return true;
                                                          }
          Severity: Major
          Found in core/model/modx/modaccessibleobject.class.php - About 45 mins to fix

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

                public static function _loadInstance(& $xpdo, $className, $criteria, $row) {
                    /** @var modAccessibleObject $instance */
                    $instance = xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row);
                    if ($instance instanceof modAccessibleObject && !$instance->checkPolicy('load')) {
                        if ($xpdo instanceof modX) {
            Severity: Minor
            Found in core/model/modx/modaccessibleobject.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

            Avoid too many return statements within this method.
            Open

                    return true;
            Severity: Major
            Found in core/model/modx/modaccessibleobject.class.php - About 30 mins to fix

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

                              if (!is_array($row)) {
                                  if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fetched empty result set from statement: " . print_r($criteria->sql, true) . " with bindings: " . print_r($criteria->bindings, true));
                              } else {
                                  $instance= modAccessibleObject :: _loadInstance($xpdo, $className, $criteria, $row);
                                  if (is_object($instance)) {
              Severity: Major
              Found in core/model/modx/modaccessibleobject.class.php and 1 other location - About 1 day to fix
              core/xpdo/om/xpdoobject.class.php on lines 431..445

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

              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

                  public static function _loadCollectionInstance(xPDO & $xpdo, array & $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag=true) {
                      $loaded = false;
                      if ($obj= modAccessibleObject :: _loadInstance($xpdo, $className, $criteria, $row)) {
                          if (($cacheKey= $obj->getPrimaryKey()) && !$obj->isLazy()) {
                              if (is_array($cacheKey)) {
              Severity: Major
              Found in core/model/modx/modaccessibleobject.class.php and 1 other location - About 1 day to fix
              core/xpdo/om/xpdoobject.class.php on lines 368..394

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

              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

                      if (is_array ($rows)) {
                          foreach ($rows as $row) {
                              modAccessibleObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
                          }
                      } elseif (is_object($rows)) {
              Severity: Major
              Found in core/model/modx/modaccessibleobject.class.php and 1 other location - About 4 hrs to fix
              core/xpdo/om/xpdoobject.class.php on lines 487..498

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

              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