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.
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();
- 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 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)) {
- 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
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';
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();
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)) {
- 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 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')) {
- 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 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')));
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)) {
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')));
- 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 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)) {
- 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 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;
- 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 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;
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')) {
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)) {
- 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 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);
- 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 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);
- 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 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)) {
- 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 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);
- 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
Avoid too many return
statements within this method. Open
return true;
Avoid too many return
statements within this method. Open
return $result;
Avoid too many return
statements within this method. Open
return parent::beforeSet();
Avoid too many return
statements within this method. Open
return $this->modx->lexicon('permission_denied');
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)) {
- 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 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');
- 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 2 locations. Consider refactoring. Open
public function checkFriendlyAlias() {
// The user submitted alias & page title
$alias = $this->getProperty('alias');
$pageTitle = $this->getProperty('pagetitle');
$autoGenerated = false;
- 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 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
- 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
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'),
- 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 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
- 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