Function doTask
has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
$fieldValueMapping = [];
if (!empty($this->field_value_mapping)) {
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
- 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 61 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
$fieldValueMapping = [];
if (!empty($this->field_value_mapping)) {
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
Function setDataFromRequest
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function setDataFromRequest(App\Request $request)
{
foreach ($this->getFieldNames() as $fieldName) {
if ($request->has($fieldName)) {
switch ($fieldName) {
- 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 updateRecords
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
private function updateRecords($recordModel, $relatedData, $fieldValue)
{
$relatedModuleName = $relatedData[0];
$relatedFieldName = $relatedData[1];
$targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);
- 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 updateRecords
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function updateRecords($recordModel, $relatedData, $fieldValue)
{
$relatedModuleName = $relatedData[0];
$relatedFieldName = $relatedData[1];
$targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);
The method doTask() has an NPath complexity of 432. The configured NPath complexity threshold is 200. Open
public function doTask($recordModel)
{
$fieldValueMapping = [];
if (!empty($this->field_value_mapping)) {
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method doTask() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10. Open
public function doTask($recordModel)
{
$fieldValueMapping = [];
if (!empty($this->field_value_mapping)) {
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
- 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 53 to the 15 allowed. Open
public function doTask($recordModel)
- 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 '46', column '44'). 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 '28'). 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 '46', column '21'). 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 '46', column '72'). 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
Avoid using static access to class '\App\Json' in method 'setDataFromRequest'. Open
$value = \App\Json::encode($data);
- 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 'Vtiger_Record_Model' in method 'doTask'. Open
$relRecordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedData[1]);
- 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\Condition' in method 'doTask'. Open
if (($condition = $conditions[$fieldInfo['fieldname']] ?? []) && !\App\Condition::checkConditions($condition, $relRecordModel)) {
- 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\Json' in method 'doTask'. Open
$conditions = \App\Json::decode($this->conditions) ?: [];
- 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\Log' in method 'doTask'. Open
\App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
- 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 assigning values to variables in if clauses and the like (line '111', column '50'). Open
private function updateRecords($recordModel, $relatedData, $fieldValue)
{
$relatedModuleName = $relatedData[0];
$relatedFieldName = $relatedData[1];
$targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid using static access to class '\App\Record' in method 'doTask'. Open
if ($recordId && \App\Record::isExists($recordId)) {
- 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 {
\App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
}
- 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_RelationListView_Model' in method 'updateRecords'. Open
$targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);
- 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\Json' in method 'updateRecords'. Open
if (!\App\Json::isEmpty($this->conditions) && ($conditions = \App\Json::decode($this->conditions)[implode('::', $relatedData)] ?? [])) {
- 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\Log' in method 'updateRecords'. Open
\App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
- 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\Json' in method 'setDataFromRequest'. Open
$values = \App\Json::decode($request->getRaw($fieldName));
- 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\Log' in method 'doTask'. Open
\App\Log::warning('Record not found: ' . $recordId);
- 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
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 {
$recordId = $recordModel->get($relatedData[0]);
if ($recordId && \App\Record::isExists($recordId)) {
$relRecordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedData[1]);
if (($condition = $conditions[$fieldInfo['fieldname']] ?? []) && !\App\Condition::checkConditions($condition, $relRecordModel)) {
- 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
The method updateRecords uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
\App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
}
- 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\Condition' in method 'setDataFromRequest'. Open
$condition = \App\Condition::getConditionsFromRequest($condition);
- 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 setDataFromRequest uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$value = $request->getRaw($fieldName);
}
- 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
if (!\App\Json::isEmpty($this->conditions)) {
- 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 {
\App\Log::warning('Record not found: ' . $recordId);
}
- 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 'updateRecords'. Open
}
- 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 assigning values to variables in if clauses and the like (line '71', column '12'). Open
public function doTask($recordModel)
{
$fieldValueMapping = [];
if (!empty($this->field_value_mapping)) {
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
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\Json' in method 'setDataFromRequest'. Open
$value = \App\Json::encode($values);
- 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 'Vtiger_Record_Model' in method 'updateRecords'. Open
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedModuleName);
- 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
Define a constant instead of duplicating this literal "fieldname" 3 times. Open
case 'fieldname':
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Avoid unused parameters such as '$recordModel'. Open
public function getContents($recordModel)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
Call to method warning
from undeclared class \App\Log
Open
\App\Log::warning('Record not found: ' . $recordId);
- Exclude checks
Call to method setConditions
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setConditions($conditions);
- Exclude checks
Call to method clearFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$dataReader = $queryGenerator->clearFields()->setFields(['id'])->createQuery()->select(['vtiger_crmentity.crmid'])
- Exclude checks
Assigning true
to property but \VTUpdateRelatedFieldTask->contents
is \Vtiger_Record_Model
Open
$this->contents = true;
- Exclude checks
Call to method warning
from undeclared class \App\Log
Open
\App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
- Exclude checks
Reference to undeclared property \VTUpdateRelatedFieldTask->conditions
Open
$conditions = \App\Json::decode($this->conditions) ?: [];
- Exclude checks
Reference to undeclared property \VTUpdateRelatedFieldTask->conditions
(Did you mean $condition) Open
$this->{$fieldName} = $value;
- Exclude checks
Reference to undeclared property \VTUpdateRelatedFieldTask->field_value_mapping
(Did you mean $fieldValueMapping) Open
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
- Exclude checks
Call to method warning
from undeclared class \App\Log
Open
\App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
- Exclude checks
Declaration of function getContents(\Vtiger_Record_Model $recordModel) : bool
should be compatible with function getContents(\Vtiger_Record_Model $recordModel) : \Vtiger_Record_Model
defined in /code/modules/com_vtiger_workflow/VTTask.php:63
Open
public function getContents($recordModel)
- Exclude checks
Reference to undeclared property \VTUpdateRelatedFieldTask->field_value_mapping
(Did you mean $fieldValueMapping) Open
if (!empty($this->field_value_mapping)) {
- Exclude checks
Reference to undeclared property \VTUpdateRelatedFieldTask->conditions
Open
if (!\App\Json::isEmpty($this->conditions) && ($conditions = \App\Json::decode($this->conditions)[implode('::', $relatedData)] ?? [])) {
- Exclude checks
Reference to undeclared property \VTUpdateRelatedFieldTask->conditions
Open
if (!\App\Json::isEmpty($this->conditions)) {
- Exclude checks
Returning type \Vtiger_Record_Model
but getContents()
is declared to return bool
Open
return $this->contents;
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class VTUpdateRelatedFieldTask 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 12 and the first side effect is on line 10. Open
<?php
- Exclude checks
The 'getContents()' method which returns a boolean should be named 'is...()' or 'has...()' Open
public function getContents($recordModel)
{
$this->contents = true;
return $this->contents;
- Read upRead up
- Exclude checks
BooleanGetMethodName
Since: 0.2
Looks for methods named 'getX()' with 'boolean' as the return type. The convention is to name these methods 'isX()' or 'hasX()'.
Example
class Foo {
/**
* @return boolean
*/
public function getFoo() {} // bad
/**
* @return bool
*/
public function isFoo(); // ok
/**
* @return boolean
*/
public function getFoo($bar); // ok, unless checkParameterizedMethods=true
}
Source https://phpmd.org/rules/naming.html#booleangetmethodname
Spaces must be used to indent lines; tabs are not allowed Open
public $executeImmediately = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return ['field_value_mapping', 'conditions'];
- 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
if (!empty($this->field_value_mapping)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$conditions = \App\Json::decode($this->conditions) ?: [];
- 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
} else {
- 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
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = $targetModel->getRelationQuery(true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = $request->getArray($fieldName, \App\Purifier::TEXT);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'fieldname':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($fieldValue) || 0 == $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
if ($recordId && \App\Record::isExists($recordId)) {
- 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
$dataReader = $queryGenerator->clearFields()->setFields(['id'])->createQuery()->select(['vtiger_crmentity.crmid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($recordId = $dataReader->readColumn(0)) {
- 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
$value = \App\Json::encode($values);
- 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
* Execute task.
- 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
$fieldValueMapping = \App\Json::decode($this->field_value_mapping);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\App\Json::isEmpty($this->conditions)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($fieldInfo['valuetype']) {
- 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
$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
if (2 === \count($relatedData)) {
- Exclude checks
Line exceeds 120 characters; contains 153 characters Open
if (($condition = $conditions[$fieldInfo['fieldname']] ?? []) && !\App\Condition::checkConditions($condition, $relRecordModel)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relRecordModel->setHandlerExceptions(['disableHandlerClasses' => ['Vtiger_Workflow_Handler']]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function updateRecords($recordModel, $relatedData, $fieldValue)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$targetModel = Vtiger_RelationListView_Model::getInstance($recordModel, $relatedModuleName);
- 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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = \App\Json::encode($data);
- 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
}
- 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
return $this->contents;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Sets data from request.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param App\Request $request
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($request->has($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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'expression':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->updateRecords($recordModel, $relatedData, $fieldValue);
- 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
$relRecordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedData[1]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel->getUITypeModel()->validate($fieldValue);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relRecordModel->set($relatedData[2], $fieldValue);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== $relRecordModel->getPreviousValue($relatedData[2])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function to get contents of this task.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Vtiger_Record_Model $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
$fieldValue = $recordModel->get($fieldValue);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
default:
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
- 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
$queryGenerator->setConditions($conditions);
- 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
default:
- 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
$fieldValue = $match[1];
- 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
$fieldModel = $relRecordModel->getField($relatedData[2]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::warning('Record not found: ' . $recordId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fieldModel->isEditable()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
$parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));
- 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
}
- 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
->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel = $recordModel->getField($relatedFieldName);
- 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
foreach ($this->getFieldNames() as $fieldName) {
- 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
$fieldValue = $exprEvaluater->evaluate($recordModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('true' == $fieldValue) {
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
$relRecordModel->setHandlerExceptions(['disableHandlerClasses' => ['Vtiger_Workflow_Handler']]);
- 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
{
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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 = '0';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (($condition = $conditions[$fieldInfo['fieldname']] ?? []) && !\App\Condition::checkConditions($condition, $relRecordModel)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($fieldModel->isEditable()) {
- 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
* @param string[] $relatedData
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedModuleName = $relatedData[0];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedFieldName = $relatedData[1];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$dataReader = $queryGenerator->clearFields()->setFields(['id'])->createQuery()->select(['vtiger_crmentity.crmid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false !== $recordModel->getPreviousValue($relatedFieldName)) {
- 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
\App\Log::warning('No permissions to edit field: ' . $fieldModel->getName());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function setDataFromRequest(App\Request $request)
- 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
$recordId = $recordModel->get($relatedData[0]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relRecordModel->save();
- 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
case '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
* @param string $fieldValue
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Vtiger_Record_Model::getInstanceById($recordId, $relatedModuleName);
- 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
$condition = \App\Condition::getConditionsFromRequest($condition);
- 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($recordModel)
- 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
$expression = $parser->expression();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\App\Json::isEmpty($this->conditions) && ($conditions = \App\Json::decode($this->conditions)[implode('::', $relatedData)] ?? [])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->contents = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
switch ($fieldName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
case 'conditions':
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($data as &$condition) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$values = \App\Json::decode($request->getRaw($fieldName));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\is_array($values)) {
- 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
$value = $request->getRaw($fieldName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->{$fieldName} = $value;
- 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
if (!$targetModel || !$targetModel->getRelationModel()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Vtiger_Record_Model $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
public function getContents($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
if (!empty($fieldValueMapping)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Update related records by releted module.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param Vtiger_Record_Model $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
$recordModel->save();
- 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
$fieldValueMapping = [];
- 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
break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedData = explode('::', $fieldInfo['fieldname']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
if (!\App\Json::isEmpty($this->conditions) && ($conditions = \App\Json::decode($this->conditions)[implode('::', $relatedData)] ?? [])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel->getUITypeModel()->validate($fieldValue);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->set($relatedFieldName, $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
* @return bool contents
- 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