modxcms/revolution

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

Summary

Maintainability
F
1 wk
Test Coverage

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

<?php
/*
 * This file is part of MODX Revolution.
 *
 * Copyright (c) MODX, LLC. All Rights Reserved.
Severity: Major
Found in core/model/modx/modresource.class.php - About 2 days to fix

    modResource has 46 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class modResource extends modAccessibleSimpleObject implements modResourceInterface {
        /**
         * Represents the cacheable content for a resource.
         *
         * Note that this is not the raw source content, but the content that is the
    Severity: Minor
    Found in core/model/modx/modresource.class.php - About 6 hrs to fix

      Function getAliasPath has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
      Open

          public function getAliasPath($alias = '',array $fields = array()) {
              if (empty($fields)) $fields = $this->toArray();
              $workingContext = $this->xpdo->getContext($fields['context_key']);
              if (empty($fields['uri_override']) || empty($fields['uri'])) {
                  /* auto assign alias if using automatic_alias */
      Severity: Minor
      Found in core/model/modx/modresource.class.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

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

          public function duplicate(array $options = array()) {
              if (!($this->xpdo instanceof modX)) return false;
      
              /* duplicate resource */
              $prefixDuplicate = !empty($options['prefixDuplicate']) ? true : false;
      Severity: Minor
      Found in core/model/modx/modresource.class.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

      Method duplicate has 98 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function duplicate(array $options = array()) {
              if (!($this->xpdo instanceof modX)) return false;
      
              /* duplicate resource */
              $prefixDuplicate = !empty($options['prefixDuplicate']) ? true : false;
      Severity: Major
      Found in core/model/modx/modresource.class.php - About 3 hrs to fix

        Function filterPathSegment has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function filterPathSegment(&$xpdo, $segment, array $options = array()) {
                /* setup the various options */
                $iconv = function_exists('iconv');
                $mbext = function_exists('mb_strlen') && (boolean) $xpdo->getOption('use_multibyte', $options, false);
                $charset = strtoupper((string) $xpdo->getOption('modx_charset', $options, 'UTF-8'));
        Severity: Minor
        Found in core/model/modx/modresource.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

        Method filterPathSegment has 84 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function filterPathSegment(&$xpdo, $segment, array $options = array()) {
                /* setup the various options */
                $iconv = function_exists('iconv');
                $mbext = function_exists('mb_strlen') && (boolean) $xpdo->getOption('use_multibyte', $options, false);
                $charset = strtoupper((string) $xpdo->getOption('modx_charset', $options, 'UTF-8'));
        Severity: Major
        Found in core/model/modx/modresource.class.php - About 3 hrs to fix

          Method getAliasPath has 56 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getAliasPath($alias = '',array $fields = array()) {
                  if (empty($fields)) $fields = $this->toArray();
                  $workingContext = $this->xpdo->getContext($fields['context_key']);
                  if (empty($fields['uri_override']) || empty($fields['uri'])) {
                      /* auto assign alias if using automatic_alias */
          Severity: Major
          Found in core/model/modx/modresource.class.php - About 2 hrs to fix

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

                public function set($k, $v= null, $vType= '') {
                    $rt= false;
                    switch ($k) {
                        case 'alias' :
                            $v= $this->cleanAlias($v);
            Severity: Minor
            Found in core/model/modx/modresource.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 save has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

                public function save($cacheFlag= null) {
                    if ($this->isNew()) {
                        if (!$this->get('createdon')) $this->set('createdon', time());
                        if (!$this->get('createdby') && $this->xpdo instanceof modX) $this->set('createdby', $this->xpdo->getLoginUserID());
                    }
            Severity: Minor
            Found in core/model/modx/modresource.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 findPolicy has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
            Open

                public function findPolicy($context = '') {
                    $policy = array();
                    $enabled = true;
                    $context = !empty($context) ? $context : $this->xpdo->context->get('key');
                    if ($context === $this->xpdo->context->get('key')) {
            Severity: Minor
            Found in core/model/modx/modresource.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 findPolicy has 40 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function findPolicy($context = '') {
                    $policy = array();
                    $enabled = true;
                    $context = !empty($context) ? $context : $this->xpdo->context->get('key');
                    if ($context === $this->xpdo->context->get('key')) {
            Severity: Minor
            Found in core/model/modx/modresource.class.php - About 1 hr to fix

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

                  public function joinGroup($resourceGroupPk, $byName = false) {
                      if (!is_object($resourceGroupPk) && !($resourceGroupPk instanceof modResourceGroup)) {
                          if ($byName) {
                              $c = array(
                                  'name' => $resourceGroupPk,
              Severity: Minor
              Found in core/model/modx/modresource.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 getTemplateVarCollection has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function getTemplateVarCollection(modResource &$resource) {
                      $c = $resource->xpdo->newQuery('modTemplateVar');
                      $c->query['distinct'] = 'DISTINCT';
                      $c->select($resource->xpdo->getSelectColumns('modTemplateVar', 'modTemplateVar'));
                      $c->select($resource->xpdo->getSelectColumns('modTemplateVarTemplate', 'tvtpl', '', array('rank')));
              Severity: Minor
              Found in core/model/modx/modresource.class.php - About 1 hr to fix

                Method joinGroup has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function joinGroup($resourceGroupPk, $byName = false) {
                        if (!is_object($resourceGroupPk) && !($resourceGroupPk instanceof modResourceGroup)) {
                            if ($byName) {
                                $c = array(
                                    'name' => $resourceGroupPk,
                Severity: Minor
                Found in core/model/modx/modresource.class.php - About 1 hr to fix

                  Method save has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function save($cacheFlag= null) {
                          if ($this->isNew()) {
                              if (!$this->get('createdon')) $this->set('createdon', time());
                              if (!$this->get('createdby') && $this->xpdo instanceof modX) $this->set('createdby', $this->xpdo->getLoginUserID());
                          }
                  Severity: Minor
                  Found in core/model/modx/modresource.class.php - About 1 hr to fix

                    Method set has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function set($k, $v= null, $vType= '') {
                            $rt= false;
                            switch ($k) {
                                case 'alias' :
                                    $v= $this->cleanAlias($v);
                    Severity: Minor
                    Found in core/model/modx/modresource.class.php - About 1 hr to fix

                      Consider simplifying this complex logical expression.
                      Open

                              if ($this->xpdo instanceof modX && $this->xpdo->getOption('friendly_urls')) {
                                  $refreshChildURIs = ($this->get('refreshURIs') || $this->isDirty('uri') || $this->isDirty('alias') || $this->isDirty('alias_visible') || $this->isDirty('parent') || $this->isDirty('context_key'));
                                  if ($this->get('uri') == '' || (!$this->get('uri_override') && ($this->isDirty('uri_override') || $this->isDirty('content_type') || $this->isDirty('isfolder') || $refreshChildURIs))) {
                                      $this->set('uri', $this->getAliasPath($this->get('alias')));
                                  }
                      Severity: Major
                      Found in core/model/modx/modresource.class.php - About 1 hr to fix

                        Function removeLock has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function removeLock($user = 0) {
                                $removed = false;
                                if ($this->xpdo instanceof modX) {
                                    if (!$user) {
                                        $user = $this->xpdo->user->get('id');
                        Severity: Minor
                        Found in core/model/modx/modresource.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

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

                            public function isMember($groups, $matchAll = false) {
                                $isMember = false;
                                $resourceGroupNames = $this->getResourceGroupNames();
                        
                                if ($resourceGroupNames) {
                        Severity: Minor
                        Found in core/model/modx/modresource.class.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 process has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function process() {
                                if (!$this->get('cacheable') || !$this->_processed || !$this->_content) {
                                    $this->_content= '';
                                    $this->_output= '';
                                    $this->xpdo->getParser();
                        Severity: Minor
                        Found in core/model/modx/modresource.class.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

                        Consider simplifying this complex logical expression.
                        Open

                                    if ($this->get('uri') == '' || (!$this->get('uri_override') && ($this->isDirty('uri_override') || $this->isDirty('content_type') || $this->isDirty('isfolder') || $refreshChildURIs))) {
                                        $this->set('uri', $this->getAliasPath($this->get('alias')));
                                    }
                        Severity: Major
                        Found in core/model/modx/modresource.class.php - About 40 mins to fix

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

                              public static function refreshURIs(modX &$modx, $parent = 0, array $options = array()) {
                                  $resetOverrides = array_key_exists('resetOverrides', $options) ? (boolean) $options['resetOverrides'] : false;
                                  $contexts = array_key_exists('contexts', $options) ? explode(',', $options['contexts']) : null;
                                  $criteria = $modx->newQuery('modResource', array('parent' => $parent));
                                  if (!$resetOverrides) {
                          Severity: Minor
                          Found in core/model/modx/modresource.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 leaveGroup has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function leaveGroup($resourceGroupPk) {
                                  if (!is_object($resourceGroupPk) && !($resourceGroupPk instanceof modResourceGroup)) {
                                      $c = array(
                                          is_int($resourceGroupPk) ? 'id' : 'name' => $resourceGroupPk,
                                      );
                          Severity: Minor
                          Found in core/model/modx/modresource.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 addLock has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function addLock($user = 0, array $options = array()) {
                                  $locked = false;
                                  if ($this->xpdo instanceof modX) {
                                      if (!$user) {
                                          $user = $this->xpdo->user->get('id');
                          Severity: Minor
                          Found in core/model/modx/modresource.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 getLock has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              public function getLock() {
                                  $lock = 0;
                                  if ($this->xpdo instanceof modX) {
                                      if ($this->xpdo->getService('registry', 'registry.modRegistry')) {
                                          $this->xpdo->registry->addRegister('locks', 'registry.modDbRegister', array('directory' => 'locks'));
                          Severity: Minor
                          Found in core/model/modx/modresource.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

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

                              public function findPolicy($context = '') {
                                  $policy = array();
                                  $enabled = true;
                                  $context = !empty($context) ? $context : $this->xpdo->context->get('key');
                                  if ($context === $this->xpdo->context->get('key')) {
                          Severity: Major
                          Found in core/model/modx/modresource.class.php and 1 other location - About 2 days to fix
                          core/model/modx/modelement.class.php on lines 389..430

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

                          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

                              public static function listGroups(modResource &$resource, array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) {
                                  $result = array('collection' => array(), 'total' => 0);
                                  $c = $resource->xpdo->newQuery('modResourceGroup');
                                  $c->leftJoin('modResourceGroupResource', 'ResourceGroupResource', array(
                                      "ResourceGroupResource.document_group = modResourceGroup.id",
                          Severity: Major
                          Found in core/model/modx/modresource.class.php and 1 other location - About 7 hrs to fix
                          core/model/modx/sqlsrv/modresource.class.php on lines 17..33

                          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

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

                              public function isMember($groups, $matchAll = false) {
                                  $isMember = false;
                                  $resourceGroupNames = $this->getResourceGroupNames();
                          
                                  if ($resourceGroupNames) {
                          Severity: Major
                          Found in core/model/modx/modresource.class.php and 1 other location - About 3 hrs to fix
                          core/model/modx/moduser.class.php on lines 646..663

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

                          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