modxcms/revolution

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

Summary

Maintainability
F
1 wk
Test Coverage

Function getResource has a Cognitive Complexity of 96 (exceeds 5 allowed). Consider refactoring.
Open

    public function getResource($method, $identifier, array $options = array()) {
        $resource = null;
        if ($method == 'alias') {
            $resourceId = $this->modx->findResource($identifier);
        } else {
Severity: Minor
Found in core/model/modx/modrequest.class.php - About 1 day to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

File modrequest.class.php has 494 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: Minor
Found in core/model/modx/modrequest.class.php - About 7 hrs to fix

    Function getParameters has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getParameters($keys = array(), $type = 'GET') {
            $value = null;
            if (!is_string($type) || !in_array($type, array('GET', 'POST', 'COOKIE', 'REQUEST'))) {
                $type = 'GET';
            }
    Severity: Minor
    Found in core/model/modx/modrequest.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

    Function _cleanResourceIdentifier has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

        public function _cleanResourceIdentifier($identifier) {
            if (empty ($identifier)) {
                if ($this->modx->getOption('base_url', null, MODX_BASE_URL) !== strtok($_SERVER["REQUEST_URI"],'?')) {
                    $this->modx->sendRedirect($this->modx->getOption('site_url', null, MODX_SITE_URL), array('responseCode' => $_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently'));
                }
    Severity: Minor
    Found in core/model/modx/modrequest.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 getResource has 100 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function getResource($method, $identifier, array $options = array()) {
            $resource = null;
            if ($method == 'alias') {
                $resourceId = $this->modx->findResource($identifier);
            } else {
    Severity: Major
    Found in core/model/modx/modrequest.class.php - About 4 hrs to fix

      Function handleRequest has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
      Open

          public function handleRequest() {
              $this->loadErrorHandler();
      
              // If enabled, send the X-Powered-By header to identify this site as running MODX, per discussion in #12882
              if ($this->modx->getOption('send_poweredby_header', null, true)) {
      Severity: Minor
      Found in core/model/modx/modrequest.class.php - About 3 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Function checkPublishStatus has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

          public function checkPublishStatus() {
              $partKey = $this->modx->getOption('cache_auto_publish_key', null, 'auto_publish');
              $partHandler = $this->modx->getOption('cache_auto_publish_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER));
              $partOptions = array(xPDO::OPT_CACHE_KEY => $partKey, xPDO::OPT_CACHE_HANDLER => $partHandler);
      
      
      Severity: Minor
      Found in core/model/modx/modrequest.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 handleRequest has 57 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function handleRequest() {
              $this->loadErrorHandler();
      
              // If enabled, send the X-Powered-By header to identify this site as running MODX, per discussion in #12882
              if ($this->modx->getOption('send_poweredby_header', null, true)) {
      Severity: Major
      Found in core/model/modx/modrequest.class.php - About 2 hrs to fix

        Method _cleanResourceIdentifier has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function _cleanResourceIdentifier($identifier) {
                if (empty ($identifier)) {
                    if ($this->modx->getOption('base_url', null, MODX_BASE_URL) !== strtok($_SERVER["REQUEST_URI"],'?')) {
                        $this->modx->sendRedirect($this->modx->getOption('site_url', null, MODX_SITE_URL), array('responseCode' => $_SERVER['SERVER_PROTOCOL'] . ' 301 Moved Permanently'));
                    }
        Severity: Major
        Found in core/model/modx/modrequest.class.php - About 2 hrs to fix

          Method getAllActionIDs has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getAllActionIDs($namespace = '') {
                  $c = array();
                  if (!empty($namespace)) $c['namespace'] = $namespace;
                  $actions = $this->modx->getCollection('modAction',$c);
          
          
          Severity: Minor
          Found in core/model/modx/modrequest.class.php - About 1 hr to fix

            Method getClientIp has 37 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function getClientIp() {
                    $ip = '';
                    $ipAll = array(); // networks IP
                    $ipSus = array(); // suspected IP
            
            
            Severity: Minor
            Found in core/model/modx/modrequest.class.php - About 1 hr to fix

              Method getParameters has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getParameters($keys = array(), $type = 'GET') {
                      $value = null;
                      if (!is_string($type) || !in_array($type, array('GET', 'POST', 'COOKIE', 'REQUEST'))) {
                          $type = 'GET';
                      }
              Severity: Minor
              Found in core/model/modx/modrequest.class.php - About 1 hr to fix

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

                    public function checkPublishStatus() {
                        $partKey = $this->modx->getOption('cache_auto_publish_key', null, 'auto_publish');
                        $partHandler = $this->modx->getOption('cache_auto_publish_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER));
                        $partOptions = array(xPDO::OPT_CACHE_KEY => $partKey, xPDO::OPT_CACHE_HANDLER => $partHandler);
                
                
                Severity: Minor
                Found in core/model/modx/modrequest.class.php - About 1 hr to fix

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

                      public function getHeaders($ucKeys = false) {
                          if (!isset($this->headers)) {
                              $headers = array ();
                              foreach ($_SERVER as $name => $value) {
                                  if (substr(strtoupper($name), 0, 5) == 'HTTP_') {
                  Severity: Minor
                  Found in core/model/modx/modrequest.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

                  Avoid deeply nested control flow statements.
                  Open

                                          if (!$isForward || ($isForward && !$this->modx->getOption('allow_forward_across_contexts', $options, false))) {
                                              if (!$this->modx->getCount('modContextResource', array($this->modx->context->get('key'), $resourceId))) {
                                                  return null;
                                              }
                                          }
                  Severity: Major
                  Found in core/model/modx/modrequest.class.php - About 45 mins to fix

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

                        public function registerLogging(array $options = array()) {
                            if (isset($options['register']) && isset($options['topic'])) {
                                if ($this->modx->getService('registry','registry.modRegistry')) {
                                    $register_class = isset($options['register_class']) ? $options['register_class'] : 'registry.modFileRegister';
                                    $register = $this->modx->registry->getRegister($options['register'], $register_class);
                    Severity: Minor
                    Found in core/model/modx/modrequest.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 getClientIp has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getClientIp() {
                            $ip = '';
                            $ipAll = array(); // networks IP
                            $ipSus = array(); // suspected IP
                    
                    
                    Severity: Minor
                    Found in core/model/modx/modrequest.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 getResourceMethod has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getResourceMethod() {
                            $method = '';
                            $hasId = isset($_REQUEST[$this->modx->getOption('request_param_id',null,'id')]);
                            $hasAlias = isset($_REQUEST[$this->modx->getOption('request_param_alias',null,'q')]);
                            if ($hasId || $hasAlias) {
                    Severity: Minor
                    Found in core/model/modx/modrequest.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 getAllActionIDs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function getAllActionIDs($namespace = '') {
                            $c = array();
                            if (!empty($namespace)) $c['namespace'] = $namespace;
                            $actions = $this->modx->getCollection('modAction',$c);
                    
                    
                    Severity: Minor
                    Found in core/model/modx/modrequest.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 4 locations. Consider refactoring.
                    Open

                            $cachedResource = $this->modx->cacheManager->get($cacheKey, array(
                                xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_resource_key', null, 'resource'),
                                xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_resource_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)),
                                xPDO::OPT_CACHE_FORMAT => (integer) $this->modx->getOption('cache_resource_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)),
                            ));
                    Severity: Major
                    Found in core/model/modx/modrequest.class.php and 3 other locations - About 2 hrs to fix
                    core/model/modx/modlexicon.class.php on lines 219..223
                    core/model/modx/modmanagerrequest.class.php on lines 161..165
                    manager/controllers/default/header.php on lines 226..238

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

                    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 ($resource->get('context_key') !== $this->modx->context->get('key')) {
                                            if (!$isForward || ($isForward && !$this->modx->getOption('allow_forward_across_contexts', $options, false))) {
                                                if (!$this->modx->getCount('modContextResource', array($this->modx->context->get('key'), $resourceId))) {
                                                    return null;
                                                }
                    Severity: Minor
                    Found in core/model/modx/modrequest.class.php and 1 other location - About 1 hr to fix
                    core/model/modx/modrequest.class.php on lines 258..264

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

                    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 ($resource->get('context_key') !== $this->modx->context->get('key')) {
                                        if (!$isForward || ($isForward && !$this->modx->getOption('allow_forward_across_contexts', $options, false))) {
                                            if (!$this->modx->getCount('modContextResource', array($this->modx->context->get('key'), $resourceId))) {
                                                return null;
                                            }
                    Severity: Minor
                    Found in core/model/modx/modrequest.class.php and 1 other location - About 1 hr to fix
                    core/model/modx/modrequest.class.php on lines 230..236

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

                    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