Function doTask
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
public function doTask($rawRecordModel)
{
$recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());
$recordModel->setData($rawRecordModel->getData());
$recordModel->ext = $rawRecordModel->ext;
- 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 doTask
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doTask($rawRecordModel)
{
$recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());
$recordModel->setData($rawRecordModel->getData());
$recordModel->ext = $rawRecordModel->ext;
The method doTask() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
public function doTask($rawRecordModel)
{
$recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());
$recordModel->setData($rawRecordModel->getData());
$recordModel->ext = $rawRecordModel->ext;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 29 to the 15 allowed. Open
public function doTask($rawRecordModel)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Missing class import via use statement (line '50', column '27'). Open
$exprEvaluater = new VTFieldExpressionEvaluater($expression);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '48', column '43'). Open
$parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '48', column '20'). Open
$parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '48', column '71'). Open
$parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if (preg_match('/([^:]+):boolean$/', $fieldValue, $match)) {
$fieldValue = $match[1];
if ('true' == $fieldValue) {
$fieldValue = '1';
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\Vtiger_Record_Model' in method 'doTask'. Open
$recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$fieldValue = '0';
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\App\Json' in method 'doTask'. Open
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'App\Purifier' in method 'doTask'. Open
$recordModel->set($fieldName, App\Purifier::decodeHtml($fieldValue));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Reference to undeclared property \VTUpdateFieldsTask->field_value_mapping
(Did you mean $fieldValueMapping) Open
if (!empty($this->field_value_mapping)) {
- Exclude checks
Reference to undeclared property \VTUpdateFieldsTask->field_value_mapping
(Did you mean $fieldValueMapping) Open
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class VTUpdateFieldsTask extends VTTask
- Exclude checks
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 13 and the first side effect is on line 11. Open
<?php
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return ['field_value_mapping'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($fieldValueMapping) && \count($fieldValueMapping) > 0) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fieldValueMapping as $fieldInfo) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldValueType = $fieldInfo['valuetype'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('fieldname' === $fieldValueType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('true' == $fieldValue) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->setData($rawRecordModel->getData());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->isNew = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldValue = trim($fieldInfo['value']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldValue = $exprEvaluater->evaluate($recordModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function doTask($rawRecordModel)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldValue = $match[1];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set($fieldName, App\Purifier::decodeHtml($fieldValue));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldName = $fieldInfo['fieldname'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldValue = '0';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->setHandlerExceptions(['disableHandlerClasses' => ['Vtiger_Workflow_Handler']]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function getFieldNames()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
require_once 'modules/com_vtiger_workflow/expression_engine/include.php';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($recordModel->getPreviousValue()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Execute task.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('expression' === $fieldValueType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (array_keys($recordModel->getPreviousValue()) as $fieldName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->ext = $rawRecordModel->ext;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldValueMapping = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!isset($moduleFields[$fieldName]) || !$moduleFields[$fieldName]->isActiveField()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$exprEvaluater = new VTFieldExpressionEvaluater($expression);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Vtiger_Record_Model $rawRecordModel
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $executeImmediately = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldValue = $recordModel->get($fieldValue);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleFields = $recordModel->getModule()->getFields();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($this->field_value_mapping)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$expression = $parser->expression();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldValue = '1';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rawRecordModel->set($fieldName, $recordModel->get($fieldName));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (preg_match('/([^:]+):boolean$/', $fieldValue, $match)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks