File modtemplatevar.class.php
has 885 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 processBindings
has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring. Open
public function processBindings($value= '', $resourceId= 0, $preProcess = true) {
$bdata = $this->getBindingDataFromValue($value);
if (empty($bdata['cmd'])) return $value;
$modx =& $this->xpdo;
- 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 checkForFormCustomizationRules
has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring. Open
public function checkForFormCustomizationRules($value,&$resource) {
if ($this->xpdo->request && $this->xpdo->user instanceof modUser) {
if (empty($resource)) {
$resource =& $this->xpdo->resource;
}
- 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 32 (exceeds 5 allowed). Consider refactoring. Open
public function findPolicy($context = '') {
$policy = array();
$context = !empty($context) ? $context : $this->xpdo->context->get('key');
if ($context === $this->xpdo->context->get('key')) {
$catEnabled = (boolean) $this->xpdo->getOption('access_category_enabled', null, 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 getRender
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
public function getRender($params,$value,array $paths,$method,$resourceId = 0,$type = 'text') {
if (empty($type)) $type = 'text';
if (empty($this->xpdo->resource)) {
if (!empty($resourceId)) {
$this->xpdo->resource = $this->xpdo->getObject('modResource',$resourceId);
- 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 processInheritBinding
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public function processInheritBinding($default = '',$resourceId = null) {
$output = $default; /* Default to param value if no content from parents */
$resource = null;
$resourceColumns = $this->xpdo->getSelectColumns('modResource', '', '', array('id', 'parent'));
$resourceQuery = new xPDOCriteria($this->xpdo, "SELECT {$resourceColumns} FROM {$this->xpdo->getTableName('modResource')} WHERE 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
Method processBindings
has 101 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function processBindings($value= '', $resourceId= 0, $preProcess = true) {
$bdata = $this->getBindingDataFromValue($value);
if (empty($bdata['cmd'])) return $value;
$modx =& $this->xpdo;
Method checkForFormCustomizationRules
has 95 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function checkForFormCustomizationRules($value,&$resource) {
if ($this->xpdo->request && $this->xpdo->user instanceof modUser) {
if (empty($resource)) {
$resource =& $this->xpdo->resource;
}
Function getRenderDirectories
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
public function getRenderDirectories($event,$subdir) {
$context = $this->xpdo->context->get('key');
$renderPath = $this->xpdo->getOption('processors_path').'element/tv/renders/'.$context.'/'.$subdir.'/';
$renderDirectories = array(
$renderPath,
- 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
modTemplateVar
has 26 functions (exceeds 20 allowed). Consider refactoring. Open
class modTemplateVar extends modElement {
/**
* Supported bindings for MODX
* @var array $bindings
*/
Method findPolicy
has 69 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function findPolicy($context = '') {
$policy = array();
$context = !empty($context) ? $context : $this->xpdo->context->get('key');
if ($context === $this->xpdo->context->get('key')) {
$catEnabled = (boolean) $this->xpdo->getOption('access_category_enabled', null, true);
Function renderInput
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function renderInput($resource= null, $options = array()) {
if (is_int($resource)) {
$resource = $this->xpdo->getObject('modResource',$resource);
}
if (empty($resource)) {
- 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 parseInput
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function parseInput($src, $delim= "||", $type= "string") {
if (is_object($src)) {
if ($src instanceof PDOStatement) {
$rs= $src->fetchAll(PDO::FETCH_ASSOC);
if ($type != "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 prepareOutput
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
public function prepareOutput($value, $resourceId= 0) {
/* Allow custom source types to manipulate the output URL for image/file tvs */
$mTypes = $this->xpdo->getOption('manipulatable_url_tv_output_types',null,'image,file');
$mTypes = explode(',',$mTypes);
if (!empty($value) && in_array($this->get('type'),$mTypes)) {
- 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 renderInput
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function renderInput($resource= null, $options = array()) {
if (is_int($resource)) {
$resource = $this->xpdo->getObject('modResource',$resource);
}
if (empty($resource)) {
Method getRender
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getRender($params,$value,array $paths,$method,$resourceId = 0,$type = 'text') {
if (empty($type)) $type = 'text';
if (empty($this->xpdo->resource)) {
if (!empty($resourceId)) {
$this->xpdo->resource = $this->xpdo->getObject('modResource',$resourceId);
Function setValue
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function setValue($resourceId= 0, $value= null) {
$oldValue= '';
if (intval($resourceId)) {
$templateVarResource = $this->xpdo->getObject('modTemplateVarResource',array(
'tmplvarid' => $this->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
Method getRenderDirectories
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function getRenderDirectories($event,$subdir) {
$context = $this->xpdo->context->get('key');
$renderPath = $this->xpdo->getOption('processors_path').'element/tv/renders/'.$context.'/'.$subdir.'/';
$renderDirectories = array(
$renderPath,
Method processInheritBinding
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function processInheritBinding($default = '',$resourceId = null) {
$output = $default; /* Default to param value if no content from parents */
$resource = null;
$resourceColumns = $this->xpdo->getSelectColumns('modResource', '', '', array('id', 'parent'));
$resourceQuery = new xPDOCriteria($this->xpdo, "SELECT {$resourceColumns} FROM {$this->xpdo->getTableName('modResource')} WHERE id = ?");
Function render
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function render($value,array $params = array()) {
if (!empty($params)) {
foreach ($params as $k => $v) {
if ($v === 'true') {
$params[$k] = 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 getValue
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function getValue($resourceId= 0) {
$value= null;
$resourceId = intval($resourceId);
if ($resourceId) {
if (is_object($this->xpdo->resource) && $resourceId === (integer) $this->xpdo->resourceIdentifier && is_array($this->xpdo->resource->get($this->get('name')))) {
- 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 10 (exceeds 5 allowed). Consider refactoring. Open
public function process($properties= null, $content= null) {
parent :: process($properties, $content);
if (!$this->_processed) {
$this->_content= $this->renderOutput($this->xpdo->resourceIdentifier);
- 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 process
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process($properties= null, $content= null) {
parent :: process($properties, $content);
if (!$this->_processed) {
$this->_content= $this->renderOutput($this->xpdo->resourceIdentifier);
Function getDisplayParams
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public function getDisplayParams() {
$settings = array();
$params = $this->get('display_params');
$ps = explode('&',$params);
foreach ($ps as $p) {
- 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 renderOutput
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function renderOutput($resourceId= 0) {
$value= $this->getValue($resourceId);
/* process any TV commands in value */
$value= $this->processBindings($value, $resourceId);
- 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 getRender
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
public function getRender($params,$value,array $paths,$method,$resourceId = 0,$type = 'text') {
Avoid deeply nested control flow statements. Open
if (!$isAbsolute) {
$value = $source->prepareOutputUrl($value);
}
Function checkResourceGroupAccess
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function checkResourceGroupAccess($user = null,$context = '') {
$context = !empty($context) ? $context : '';
$c = $this->xpdo->newQuery('modResourceGroup');
$c->innerJoin('modTemplateVarResourceGroup','TemplateVarResourceGroups',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 save
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function save($cacheFlag = null) {
$isNew = $this->isNew();
if ($this->xpdo instanceof modX) {
$this->xpdo->invokeEvent('OnTemplateVarBeforeSave',array(
'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD,
- 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 hasTemplate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function hasTemplate($templatePk) {
if (!is_int($templatePk) && !is_object($templatePk)) {
$template = $this->xpdo->getObject('modTemplate',array('templatename' => $templatePk));
if (empty($template) || !is_object($template) || !($template instanceof modTemplate)) {
$this->xpdo->log(modX::LOG_LEVEL_ERROR,'modTemplateVar::hasTemplate - No template: '.$templatePk);
- 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 remove
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function remove(array $ancestors= array ()) {
if ($this->xpdo instanceof modX) {
$this->xpdo->invokeEvent('OnTemplateVarBeforeRemove',array(
'templateVar' => &$this,
'cacheFlag' => 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 processFileBinding
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function processFileBinding($file) {
if (file_exists($file) && @ $handle= fopen($file,'r')) {
$buffer= "";
while (!feof($handle)) {
$buffer .= fgets($handle, 4096);
- 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
if ($rgEnabled) {
$accessTable = $this->xpdo->getTableName('modAccessResourceGroup');
$resourceGroupTable = $this->xpdo->getTableName('modTemplateVarResourceGroup');
$sql = "SELECT Acl.target, Acl.principal, Acl.authority, Acl.policy, Policy.data FROM {$accessTable} Acl " .
"LEFT JOIN {$policyTable} Policy ON Policy.id = Acl.policy " .
- 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 233.
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 ($catEnabled) {
$accessTable = $this->xpdo->getTableName('modAccessCategory');
$categoryClosureTable = $this->xpdo->getTableName('modCategoryClosure');
$sql = "SELECT Acl.target, Acl.principal, Acl.authority, Acl.policy, Policy.data FROM {$accessTable} Acl " .
"LEFT JOIN {$policyTable} Policy ON Policy.id = Acl.policy " .
- 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 233.
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 3 locations. Consider refactoring. Open
public function save($cacheFlag = null) {
$isNew = $this->isNew();
if ($this->xpdo instanceof modX) {
$this->xpdo->invokeEvent('OnTemplateVarBeforeSave',array(
'mode' => $isNew ? modSystemEvent::MODE_NEW : modSystemEvent::MODE_UPD,
- 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 227.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (is_string($this->_output) && !empty ($this->_output)) {
/* turn the processed properties into placeholders */
$scope = $this->xpdo->toPlaceholders($this->_properties, '', '.', true);
/* collect element tags in the content and process them */
- 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 189.
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 (!is_int($templatePk) && !is_object($templatePk)) {
$template = $this->xpdo->getObject('modTemplate',array('templatename' => $templatePk));
if (empty($template) || !is_object($template) || !($template instanceof modTemplate)) {
$this->xpdo->log(modX::LOG_LEVEL_ERROR,'modTemplateVar::hasTemplate - No template: '.$templatePk);
return 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 119.
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