modxcms/revolution

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

Summary

Maintainability
F
3 days
Test Coverage

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

    public function load() {
        $topics = func_get_args(); /* allow for dynamic number of lexicons to load */

        if ($this->modx->context && $this->modx->context->get('key') == 'mgr') {
            $defaultLanguage = $this->modx->getOption('manager_language',null,$this->modx->getOption('cultureKey',null,'en'));
Severity: Minor
Found in core/model/modx/modlexicon.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 modlexicon.class.php has 290 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/modlexicon.class.php - About 2 hrs to fix

    Function getTopicList has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getTopicList($language = 'en',$namespace = 'core') {
            $corePath = $this->getNamespacePath($namespace);
            $lexPath = str_replace('//','/',$corePath.'/lexicon/'.$language.'/');
    
            $topics = array();
    Severity: Minor
    Found in core/model/modx/modlexicon.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 loadCache has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        public function loadCache($namespace = 'core', $topic = 'default', $language = '') {
            if (empty($language)) $language = $this->modx->getOption('cultureKey',null,'en');
            $key = $this->getCacheKey($namespace, $topic, $language);
            $enableCache = ($namespace != 'core' && !$this->modx->getOption('cache_noncore_lexicon_topics',null,true)) ? false : true;
    
    
    Severity: Minor
    Found in core/model/modx/modlexicon.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 getLanguageList has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getLanguageList($namespace = 'core') {
            $corePath = $this->getNamespacePath($namespace);
            $lexPath = str_replace('//','/',$corePath.'/lexicon/');
            if (!is_dir($lexPath)) {
                return array();
    Severity: Minor
    Found in core/model/modx/modlexicon.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 loadCache has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function loadCache($namespace = 'core', $topic = 'default', $language = '') {
            if (empty($language)) $language = $this->modx->getOption('cultureKey',null,'en');
            $key = $this->getCacheKey($namespace, $topic, $language);
            $enableCache = ($namespace != 'core' && !$this->modx->getOption('cache_noncore_lexicon_topics',null,true)) ? false : true;
    
    
    Severity: Minor
    Found in core/model/modx/modlexicon.class.php - About 1 hr to fix

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

          public function load() {
              $topics = func_get_args(); /* allow for dynamic number of lexicons to load */
      
              if ($this->modx->context && $this->modx->context->get('key') == 'mgr') {
                  $defaultLanguage = $this->modx->getOption('manager_language',null,$this->modx->getOption('cultureKey',null,'en'));
      Severity: Minor
      Found in core/model/modx/modlexicon.class.php - About 1 hr to fix

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

            public function set($keys, $text = '', $language = '') {
                $language = !empty($language) ? $language : $this->modx->getOption('cultureKey',null,$language);
                if (is_array($keys)) {
                    foreach ($keys as $key => $str) {
                        if ($key == '') continue;
        Severity: Minor
        Found in core/model/modx/modlexicon.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 getTopicList has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function getTopicList($language = 'en',$namespace = 'core') {
                $corePath = $this->getNamespacePath($namespace);
                $lexPath = str_replace('//','/',$corePath.'/lexicon/'.$language.'/');
        
                $topics = array();
        Severity: Minor
        Found in core/model/modx/modlexicon.class.php - About 1 hr to fix

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

              public function getLanguageList($namespace = 'core') {
                  $corePath = $this->getNamespacePath($namespace);
                  $lexPath = str_replace('//','/',$corePath.'/lexicon/');
                  if (!is_dir($lexPath)) {
                      return array();
          Severity: Minor
          Found in core/model/modx/modlexicon.class.php - About 1 hr to fix

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

                public function fetch($prefix = '',$removePrefix = false,$language = '') {
                    $language = !empty($language) ? $language : $this->modx->getOption('cultureKey',null,'en');
                    if (!empty($prefix)) {
                        $lex = array();
                        $lang = $this->_lexicon[$language];
            Severity: Minor
            Found in core/model/modx/modlexicon.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 _flatten has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                private function _flatten($array) {
                    $result = array();
                    if (is_array($array)) {
                        $iterator = new RecursiveIteratorIterator(new RecursiveArrayIterator($array));
                        foreach ($iterator as $value) {
            Severity: Minor
            Found in core/model/modx/modlexicon.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

                    $cached = $this->modx->cacheManager->get($key, array(
                        xPDO::OPT_CACHE_KEY => $this->modx->getOption('cache_lexicon_topics_key', null, 'lexicon_topics'),
                        xPDO::OPT_CACHE_HANDLER => $this->modx->getOption('cache_lexicon_topics_handler', null, $this->modx->getOption(xPDO::OPT_CACHE_HANDLER)),
                        xPDO::OPT_CACHE_FORMAT => (integer) $this->modx->getOption('cache_lexicon_topics_format', null, $this->modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)),
                    ));
            Severity: Major
            Found in core/model/modx/modlexicon.class.php and 3 other locations - About 2 hrs to fix
            core/model/modx/modmanagerrequest.class.php on lines 161..165
            core/model/modx/modrequest.class.php on lines 186..190
            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

            There are no issues that match your filters.

            Category
            Status