modxcms/revolution

View on GitHub
core/model/modx/processors/resource/update.class.php

Summary

Maintainability
F
1 wk
Test Coverage

File update.class.php has 604 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/processors/resource/update.class.php - About 1 day to fix

    Function saveTemplateVariables has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
    Open

        public function saveTemplateVariables() {
            $tvs = $this->getProperty('tvs',null);
            if (!empty($tvs)) {
                $tmplvars = array();
    
    
    Severity: Minor
    Found in core/model/modx/processors/resource/update.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 setResourceGroups has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
    Open

        public function setResourceGroups() {
            $resourceGroups = $this->getProperty('resource_groups',null);
            if ($resourceGroups !== null) {
                $resourceGroups = is_array($resourceGroups) ? $resourceGroups : $this->modx->fromJSON($resourceGroups);
                if (is_array($resourceGroups)) {
    Severity: Minor
    Found in core/model/modx/processors/resource/update.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

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

    class modResourceUpdateProcessor extends modObjectUpdateProcessor {
        public $classKey = 'modResource';
        public $languageTopics = array('resource');
        public $permission = 'save_document';
        public $objectType = 'resource';
    Severity: Minor
    Found in core/model/modx/processors/resource/update.class.php - About 3 hrs to fix

      Method saveTemplateVariables has 73 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function saveTemplateVariables() {
              $tvs = $this->getProperty('tvs',null);
              if (!empty($tvs)) {
                  $tmplvars = array();
      
      
      Severity: Major
      Found in core/model/modx/processors/resource/update.class.php - About 2 hrs to fix

        Function addLock has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            public function addLock() {
                $locked = $this->object->addLock();
                if ($locked !== true) {
                    $stealLock = $this->getProperty('steal_lock',false);
                    if (!empty($stealLock)) {
        Severity: Minor
        Found in core/model/modx/processors/resource/update.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 checkDeletedStatus has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public function checkDeletedStatus() {
                $deleted = $this->getProperty('deleted',null);
                if ($deleted !== null && $deleted != $this->object->get('deleted')) {
                    if ($this->object->get('deleted')) { /* undelete */
                        if (!$this->modx->hasPermission('undelete_document')) {
        Severity: Minor
        Found in core/model/modx/processors/resource/update.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 beforeSet has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function beforeSet() {
                $locked = $this->addLock();
                if ($locked !== true) {
                    if ($this->lockedUser) {
                        return $this->modx->lexicon('resource_locked_by', array('id' => $this->object->get('id'), 'user' => $this->lockedUser->get('username')));
        Severity: Minor
        Found in core/model/modx/processors/resource/update.class.php - About 1 hr to fix

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

              public function setResourceGroups() {
                  $resourceGroups = $this->getProperty('resource_groups',null);
                  if ($resourceGroups !== null) {
                      $resourceGroups = is_array($resourceGroups) ? $resourceGroups : $this->modx->fromJSON($resourceGroups);
                      if (is_array($resourceGroups)) {
          Severity: Minor
          Found in core/model/modx/processors/resource/update.class.php - About 1 hr to fix

            Function beforeSet has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                public function beforeSet() {
                    $locked = $this->addLock();
                    if ($locked !== true) {
                        if ($this->lockedUser) {
                            return $this->modx->lexicon('resource_locked_by', array('id' => $this->object->get('id'), 'user' => $this->lockedUser->get('username')));
            Severity: Minor
            Found in core/model/modx/processors/resource/update.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 handleParent has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                public function handleParent() {
                    $parent = $this->getProperty('parent',null);
                    if ($parent !== null) {
                        /* handle if parent is a context */
                        if (!is_numeric($parent)) {
            Severity: Minor
            Found in core/model/modx/processors/resource/update.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 checkFriendlyAlias has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                public function checkFriendlyAlias() {
                    // The user submitted alias & page title
                    $alias = $this->getProperty('alias');
                    $pageTitle = $this->getProperty('pagetitle');
                    $autoGenerated = false;
            Severity: Minor
            Found in core/model/modx/processors/resource/update.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 checkFriendlyAlias has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function checkFriendlyAlias() {
                    // The user submitted alias & page title
                    $alias = $this->getProperty('alias');
                    $pageTitle = $this->getProperty('pagetitle');
                    $autoGenerated = false;
            Severity: Minor
            Found in core/model/modx/processors/resource/update.class.php - About 1 hr to fix

              Method checkDeletedStatus has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function checkDeletedStatus() {
                      $deleted = $this->getProperty('deleted',null);
                      if ($deleted !== null && $deleted != $this->object->get('deleted')) {
                          if ($this->object->get('deleted')) { /* undelete */
                              if (!$this->modx->hasPermission('undelete_document')) {
              Severity: Minor
              Found in core/model/modx/processors/resource/update.class.php - About 1 hr to fix

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

                    public function setPublishDate() {
                        $now = time();
                        $publishDate = $this->getProperty('pub_date',null);
                        if ($publishDate !== null) {
                            if (empty($publishDate)) {
                Severity: Minor
                Found in core/model/modx/processors/resource/update.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 checkPublishedOn has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function checkPublishedOn() {
                        $published = $this->getProperty('published',null);
                        if ($published !== null && $published != $this->object->get('published')) {
                            if (empty($published)) { /* if unpublishing */
                                $this->setProperty('publishedon',0);
                Severity: Minor
                Found in core/model/modx/processors/resource/update.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 checkWebLinkTarget has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function checkWebLinkTarget() {
                        $target = $this->getProperty('content', null);
                
                        $matches = array();
                        $countFoundTags = $this->modx->getParser()->collectElementTags($target, $matches);
                Severity: Minor
                Found in core/model/modx/processors/resource/update.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 setUnPublishDate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function setUnPublishDate() {
                        $now = time();
                        $unPublishDate = $this->getProperty('unpub_date',null);
                        if ($unPublishDate !== null) {
                            if (empty($unPublishDate)) {
                Severity: Minor
                Found in core/model/modx/processors/resource/update.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 checkParentContext has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function checkParentContext() {
                        $parent = $this->getProperty('parent',null);
                        if ($this->object->get('parent') != $parent) {
                            $this->oldParent = $this->modx->getObject('modResource',array('id' => $this->object->get('parent')));
                            $this->newParent = $this->modx->getObject('modResource', $parent);
                Severity: Minor
                Found in core/model/modx/processors/resource/update.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/processors/resource/update.class.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return $result;
                  Severity: Major
                  Found in core/model/modx/processors/resource/update.class.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return parent::beforeSet();
                    Severity: Major
                    Found in core/model/modx/processors/resource/update.class.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return $this->modx->lexicon('permission_denied');
                      Severity: Major
                      Found in core/model/modx/processors/resource/update.class.php - About 30 mins to fix

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

                            public function fixParents() {
                                $autoIsFolder = $this->modx->getOption('auto_isfolder', null, true);
                                if (!$autoIsFolder) return;
                        
                                if (!empty($this->oldParent)) {
                        Severity: Minor
                        Found in core/model/modx/processors/resource/update.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

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

                            public function checkForUnPublishOnSiteStart() {
                                $passed = true;
                                $published = $this->getProperty('published',null);
                                $publishDate = $this->getProperty('pub_date');
                                $unPublishDate = $this->getProperty('unpub_date');
                        Severity: Minor
                        Found in core/model/modx/processors/resource/update.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 checkFriendlyAlias() {
                                // The user submitted alias & page title
                                $alias = $this->getProperty('alias');
                                $pageTitle = $this->getProperty('pagetitle');
                                $autoGenerated = false;
                        Severity: Major
                        Found in core/model/modx/processors/resource/update.class.php and 1 other location - About 1 day to fix
                        core/model/modx/processors/resource/create.class.php on lines 400..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 347.

                        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

                                            if ($resourceGroupAccess['access']) {
                                                /** @var modResourceGroupResource $resourceGroupResource */
                                                $resourceGroupResource = $this->modx->getObject('modResourceGroupResource',array(
                                                    'document_group' => $resourceGroupAccess['id'],
                                                    'document' => $this->object->get('id'),
                        Severity: Major
                        Found in core/model/modx/processors/resource/update.class.php and 1 other location - About 2 hrs to fix
                        core/model/modx/processors/resource/create.class.php on lines 590..624

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

                        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