modxcms/revolution

View on GitHub
core/model/modx/rest/modrestcontroller.class.php

Summary

Maintainability
F
3 days
Test Coverage

modRestController has 49 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class modRestController {
    /** @var modX $modx The modX instance */
    public $modx;
    /** @var array $config An array of configuration properties, passed from modRestService */
    public $config = array();
Severity: Minor
Found in core/model/modx/rest/modrestcontroller.class.php - About 6 hrs to fix

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

    <?php
    /*
     * This file is part of the MODX Revolution package.
     *
     * Copyright (c) MODX, LLC
    Severity: Minor
    Found in core/model/modx/rest/modrestcontroller.class.php - About 5 hrs to fix

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

          public function put() {
              $id = $this->getProperty($this->primaryKeyField,false);
              if (empty($id)) {
                  return $this->failure($this->modx->lexicon('rest.err_field_ns',array(
                      'field' => $this->primaryKeyField,
      Severity: Minor
      Found in core/model/modx/rest/modrestcontroller.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 put has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function put() {
              $id = $this->getProperty($this->primaryKeyField,false);
              if (empty($id)) {
                  return $this->failure($this->modx->lexicon('rest.err_field_ns',array(
                      'field' => $this->primaryKeyField,
      Severity: Minor
      Found in core/model/modx/rest/modrestcontroller.class.php - About 1 hr to fix

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

            public function post() {
                $properties = $this->getProperties();
        
                if (!empty($this->postRequiredFields)) {
                    if (!$this->checkRequiredFields($this->postRequiredFields)) {
        Severity: Minor
        Found in core/model/modx/rest/modrestcontroller.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 delete has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function delete() {
                $id = $this->getProperty($this->primaryKeyField,false);
                if (empty($id)) {
                    return $this->failure($this->modx->lexicon('rest.err_field_ns',array(
                        'field' => $this->primaryKeyField,
        Severity: Minor
        Found in core/model/modx/rest/modrestcontroller.class.php - About 1 hr to fix

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

              public function post() {
                  $properties = $this->getProperties();
          
                  if (!empty($this->postRequiredFields)) {
                      if (!$this->checkRequiredFields($this->postRequiredFields)) {
          Severity: Minor
          Found in core/model/modx/rest/modrestcontroller.class.php - About 1 hr to fix

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

                public function checkRequiredFields(array $fields = array(),$setFieldError = true) {
                    $missing = array();
                    foreach ($fields as $field) {
                        $value = $this->getProperty($field);
            
            
            Severity: Minor
            Found in core/model/modx/rest/modrestcontroller.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 setDefault has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function setDefault($k,$v,$useNotEmpty = false) {
                    $isSet = false;
                    if ($useNotEmpty) {
                        if (!empty($this->properties[$k])) $isSet = true;
                    } else if (array_key_exists($k,$this->properties)) {
            Severity: Minor
            Found in core/model/modx/rest/modrestcontroller.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 setObjectFields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function setObjectFields(&$object,array $values = array()) {
                    foreach ($values as $key => $value) {
                        if (is_array($value)) {
                            foreach ($value as $k => $v) {
                                $object->{$key[$k]} = $v;
            Severity: Minor
            Found in core/model/modx/rest/modrestcontroller.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 checkRequiredRelatedObjects has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function checkRequiredRelatedObjects(array $pairs = array()) {
                    $passed = true;
                    foreach ($pairs as $field => $classKey) {
                        if (!empty($classKey) && !empty($field)) {
                            $relatedObject = $this->modx->getObject($classKey,$this->getProperty($field));
            Severity: Minor
            Found in core/model/modx/rest/modrestcontroller.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 delete has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                public function delete() {
                    $id = $this->getProperty($this->primaryKeyField,false);
                    if (empty($id)) {
                        return $this->failure($this->modx->lexicon('rest.err_field_ns',array(
                            'field' => $this->primaryKeyField,
            Severity: Minor
            Found in core/model/modx/rest/modrestcontroller.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 $this->success('',$objectArray);
            Severity: Major
            Found in core/model/modx/rest/modrestcontroller.class.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return $this->failure();
              Severity: Major
              Found in core/model/modx/rest/modrestcontroller.class.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return $this->failure($this->modx->lexicon('rest.err_class_save',array(
                                    'class_key' => $this->classKey,
                                )));
                Severity: Major
                Found in core/model/modx/rest/modrestcontroller.class.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                  return $this->failure($this->modx->lexicon('rest.err_class_save',array(
                                      'class_key' => $this->classKey,
                                  )));
                  Severity: Major
                  Found in core/model/modx/rest/modrestcontroller.class.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return $this->success('',$objectArray);
                    Severity: Major
                    Found in core/model/modx/rest/modrestcontroller.class.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return $this->failure($this->modx->lexicon('rest.err_class_remove',array(
                                      'class_key' => $this->classKey,
                                  )));
                      Severity: Major
                      Found in core/model/modx/rest/modrestcontroller.class.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $this->failure($beforePut === false ? $this->errorMessage : $beforePut);
                        Severity: Major
                        Found in core/model/modx/rest/modrestcontroller.class.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return $this->success('',$objectArray);
                          Severity: Major
                          Found in core/model/modx/rest/modrestcontroller.class.php - About 30 mins to fix

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

                                protected function addSearchQuery(xPDOQuery $c) {
                                    $search = $this->getProperty($this->getOption('propertySearch','search'),false);
                                    if (!empty($search) && !empty($this->searchFields)) {
                                        $searchQuery = array();
                                        $i = 0;
                            Severity: Minor
                            Found in core/model/modx/rest/modrestcontroller.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

                            There are no issues that match your filters.

                            Category
                            Status