File modresource.class.php
has 832 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/*
* This file is part of MODX Revolution.
*
* Copyright (c) MODX, LLC. All Rights Reserved.
modResource
has 46 functions (exceeds 20 allowed). Consider refactoring. Open
class modResource extends modAccessibleSimpleObject implements modResourceInterface {
/**
* Represents the cacheable content for a resource.
*
* Note that this is not the raw source content, but the content that is the
Function getAliasPath
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
public function getAliasPath($alias = '',array $fields = array()) {
if (empty($fields)) $fields = $this->toArray();
$workingContext = $this->xpdo->getContext($fields['context_key']);
if (empty($fields['uri_override']) || empty($fields['uri'])) {
/* auto assign alias if using automatic_alias */
- 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 duplicate
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public function duplicate(array $options = array()) {
if (!($this->xpdo instanceof modX)) return false;
/* duplicate resource */
$prefixDuplicate = !empty($options['prefixDuplicate']) ? true : 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 duplicate
has 98 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function duplicate(array $options = array()) {
if (!($this->xpdo instanceof modX)) return false;
/* duplicate resource */
$prefixDuplicate = !empty($options['prefixDuplicate']) ? true : false;
Function filterPathSegment
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public static function filterPathSegment(&$xpdo, $segment, array $options = array()) {
/* setup the various options */
$iconv = function_exists('iconv');
$mbext = function_exists('mb_strlen') && (boolean) $xpdo->getOption('use_multibyte', $options, false);
$charset = strtoupper((string) $xpdo->getOption('modx_charset', $options, 'UTF-8'));
- 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 filterPathSegment
has 84 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function filterPathSegment(&$xpdo, $segment, array $options = array()) {
/* setup the various options */
$iconv = function_exists('iconv');
$mbext = function_exists('mb_strlen') && (boolean) $xpdo->getOption('use_multibyte', $options, false);
$charset = strtoupper((string) $xpdo->getOption('modx_charset', $options, 'UTF-8'));
Method getAliasPath
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getAliasPath($alias = '',array $fields = array()) {
if (empty($fields)) $fields = $this->toArray();
$workingContext = $this->xpdo->getContext($fields['context_key']);
if (empty($fields['uri_override']) || empty($fields['uri'])) {
/* auto assign alias if using automatic_alias */
Function set
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function set($k, $v= null, $vType= '') {
$rt= false;
switch ($k) {
case 'alias' :
$v= $this->cleanAlias($v);
- 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 save
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public function save($cacheFlag= null) {
if ($this->isNew()) {
if (!$this->get('createdon')) $this->set('createdon', time());
if (!$this->get('createdby') && $this->xpdo instanceof modX) $this->set('createdby', $this->xpdo->getLoginUserID());
}
- 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 findPolicy
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
public function findPolicy($context = '') {
$policy = array();
$enabled = true;
$context = !empty($context) ? $context : $this->xpdo->context->get('key');
if ($context === $this->xpdo->context->get('key')) {
- 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 findPolicy
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function findPolicy($context = '') {
$policy = array();
$enabled = true;
$context = !empty($context) ? $context : $this->xpdo->context->get('key');
if ($context === $this->xpdo->context->get('key')) {
Function joinGroup
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function joinGroup($resourceGroupPk, $byName = false) {
if (!is_object($resourceGroupPk) && !($resourceGroupPk instanceof modResourceGroup)) {
if ($byName) {
$c = array(
'name' => $resourceGroupPk,
- 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 getTemplateVarCollection
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getTemplateVarCollection(modResource &$resource) {
$c = $resource->xpdo->newQuery('modTemplateVar');
$c->query['distinct'] = 'DISTINCT';
$c->select($resource->xpdo->getSelectColumns('modTemplateVar', 'modTemplateVar'));
$c->select($resource->xpdo->getSelectColumns('modTemplateVarTemplate', 'tvtpl', '', array('rank')));
Method joinGroup
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function joinGroup($resourceGroupPk, $byName = false) {
if (!is_object($resourceGroupPk) && !($resourceGroupPk instanceof modResourceGroup)) {
if ($byName) {
$c = array(
'name' => $resourceGroupPk,
Method save
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function save($cacheFlag= null) {
if ($this->isNew()) {
if (!$this->get('createdon')) $this->set('createdon', time());
if (!$this->get('createdby') && $this->xpdo instanceof modX) $this->set('createdby', $this->xpdo->getLoginUserID());
}
Method set
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function set($k, $v= null, $vType= '') {
$rt= false;
switch ($k) {
case 'alias' :
$v= $this->cleanAlias($v);
Consider simplifying this complex logical expression. Open
if ($this->xpdo instanceof modX && $this->xpdo->getOption('friendly_urls')) {
$refreshChildURIs = ($this->get('refreshURIs') || $this->isDirty('uri') || $this->isDirty('alias') || $this->isDirty('alias_visible') || $this->isDirty('parent') || $this->isDirty('context_key'));
if ($this->get('uri') == '' || (!$this->get('uri_override') && ($this->isDirty('uri_override') || $this->isDirty('content_type') || $this->isDirty('isfolder') || $refreshChildURIs))) {
$this->set('uri', $this->getAliasPath($this->get('alias')));
}
Function removeLock
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function removeLock($user = 0) {
$removed = false;
if ($this->xpdo instanceof modX) {
if (!$user) {
$user = $this->xpdo->user->get('id');
- 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 isMember
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function isMember($groups, $matchAll = false) {
$isMember = false;
$resourceGroupNames = $this->getResourceGroupNames();
if ($resourceGroupNames) {
- 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 process
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function process() {
if (!$this->get('cacheable') || !$this->_processed || !$this->_content) {
$this->_content= '';
$this->_output= '';
$this->xpdo->getParser();
- 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
Consider simplifying this complex logical expression. Open
if ($this->get('uri') == '' || (!$this->get('uri_override') && ($this->isDirty('uri_override') || $this->isDirty('content_type') || $this->isDirty('isfolder') || $refreshChildURIs))) {
$this->set('uri', $this->getAliasPath($this->get('alias')));
}
Function refreshURIs
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function refreshURIs(modX &$modx, $parent = 0, array $options = array()) {
$resetOverrides = array_key_exists('resetOverrides', $options) ? (boolean) $options['resetOverrides'] : false;
$contexts = array_key_exists('contexts', $options) ? explode(',', $options['contexts']) : null;
$criteria = $modx->newQuery('modResource', array('parent' => $parent));
if (!$resetOverrides) {
- 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 leaveGroup
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function leaveGroup($resourceGroupPk) {
if (!is_object($resourceGroupPk) && !($resourceGroupPk instanceof modResourceGroup)) {
$c = array(
is_int($resourceGroupPk) ? 'id' : 'name' => $resourceGroupPk,
);
- 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 addLock
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function addLock($user = 0, array $options = array()) {
$locked = false;
if ($this->xpdo instanceof modX) {
if (!$user) {
$user = $this->xpdo->user->get('id');
- 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 getLock
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function getLock() {
$lock = 0;
if ($this->xpdo instanceof modX) {
if ($this->xpdo->getService('registry', 'registry.modRegistry')) {
$this->xpdo->registry->addRegister('locks', 'registry.modDbRegister', array('directory' => 'locks'));
- 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 findPolicy($context = '') {
$policy = array();
$enabled = true;
$context = !empty($context) ? $context : $this->xpdo->context->get('key');
if ($context === $this->xpdo->context->get('key')) {
- 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 447.
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
public static function listGroups(modResource &$resource, array $sort = array('id' => 'ASC'), $limit = 0, $offset = 0) {
$result = array('collection' => array(), 'total' => 0);
$c = $resource->xpdo->newQuery('modResourceGroup');
$c->leftJoin('modResourceGroupResource', 'ResourceGroupResource', array(
"ResourceGroupResource.document_group = modResourceGroup.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 244.
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
public function isMember($groups, $matchAll = false) {
$isMember = false;
$resourceGroupNames = $this->getResourceGroupNames();
if ($resourceGroupNames) {
- 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 146.
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