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'));
- Read upRead up
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.
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();
- Read upRead up
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;
- Read upRead up
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();
- Read upRead up
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;
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'));
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;
- Read upRead up
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();
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();
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];
- Read upRead up
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) {
- Read upRead up
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)),
));
- Read upRead up
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76