Method doTask
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
[$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);
$relationFieldModel = $recordModel->getModule()->getFieldByName($referenceField);
$ids = [];
Function doTask
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
[$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);
$relationFieldModel = $recordModel->getModule()->getFieldByName($referenceField);
$ids = [];
- 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
Missing class import via use statement (line '39', column '27'). Open
$queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());
- 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 assigning values to variables in if clauses and the like (line '34', column '7'). Open
public function doTask($recordModel)
{
[$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);
$relationFieldModel = $recordModel->getModule()->getFieldByName($referenceField);
$ids = [];
- 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 (\App\Record::isExists($id, $moduleName)) {
- 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
$relatedModel = \Vtiger_Record_Model::getInstanceById($id, $moduleName);
- 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
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());
- Exclude checks
Reference to undeclared property \SumFieldFromDependent->targetField
Open
[$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);
- Exclude checks
Reference to undeclared property \SumFieldFromDependent->conditions
Open
$queryGenerator->setConditions($this->conditions);
- Exclude checks
Call to method setConditions
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setConditions($this->conditions);
- Exclude checks
Call to method createQuery
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$query = $queryGenerator->createQuery();
- Exclude checks
Reference to undeclared property \SumFieldFromDependent->sourceField
Open
$sourceFieldModel = $recordModel->getModule()->getFieldByName($this->sourceField);
- Exclude checks
Reference to undeclared property \SumFieldFromDependent->sourceField
Open
$queryGenerator->setField($this->sourceField);
- Exclude checks
Reference to undeclared property \SumFieldFromDependent->conditions
Open
if (!empty($this->conditions)) {
- Exclude checks
Call to method setField
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator->setField($this->sourceField);
- Exclude checks
Reference to instance property permissions
from undeclared class \App\QueryGenerator
Open
$queryGenerator->permissions = false;
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class SumFieldFromDependent 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
Spaces must be used to indent lines; tabs are not allowed Open
return ['targetField', 'sourceField', 'conditions'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$ids[] = $recordModel->get($referenceField);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setConditions($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
/**
- 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
$query = $queryGenerator->createQuery();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedModel = \Vtiger_Record_Model::getInstanceById($id, $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = new \App\QueryGenerator($recordModel->getModuleName());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedModel->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$ids[] = $oldId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->permissions = 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\App\Record::isExists($id, $moduleName)) {
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($ids as $id) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedModel->set($fieldName, $columnSumValue ?? 0);
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
$columnSumValue = $query->sum($sourceFieldModel->getTableName() . '.' . $sourceFieldModel->getColumnName());
- 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
$relationFieldModel = $recordModel->getModule()->getFieldByName($referenceField);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query->andWhere([$relationFieldModel->getTableName() . '.' . $relationFieldModel->getColumnName() => $id, 'vtiger_crmentity.deleted' => 0]);
- Exclude checks
Line exceeds 120 characters; contains 157 characters Open
$query->andWhere([$relationFieldModel->getTableName() . '.' . $relationFieldModel->getColumnName() => $id, 'vtiger_crmentity.deleted' => 0]);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[$referenceField, $moduleName, $fieldName] = explode('::', $this->targetField);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setField($this->sourceField);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$sourceFieldModel = $recordModel->getModule()->getFieldByName($this->sourceField);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($oldId = $recordModel->getPreviousValue($referenceField)) {
- 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
$columnSumValue = $query->sum($sourceFieldModel->getTableName() . '.' . $sourceFieldModel->getColumnName());
- 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->conditions)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$recordModel->isEmpty($referenceField)) {
- 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
$ids = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks