Function process
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function process()
{
$data = [];
[$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
if (is_numeric($relationId)) {
- 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 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process()
{
$data = [];
[$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
if (is_numeric($relationId)) {
The method process() has an NPath complexity of 1152. The configured NPath complexity threshold is 200. Open
public function process()
{
$data = [];
[$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
if (is_numeric($relationId)) {
- 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 process() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function process()
{
$data = [];
[$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
if (is_numeric($relationId)) {
- 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 17 to the 15 allowed. Open
public function process()
- 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
Avoid using static access to class '\App\Privilege' in method 'process'. Open
|| !\App\Privilege::isPermitted($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 'process'. Open
$relationListView->set('search_rel_params', \App\Json::decode($relConditions));
- 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\Relation' in method 'process'. Open
$relationId = \App\Relation::getRelationId($this->textParser->moduleName, $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 'process'. Open
$transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($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\Relation' in method 'process'. 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 '45', column '9'). Open
public function process()
{
$data = [];
[$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
if (is_numeric($relationId)) {
- 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
The method process uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$relatedModuleName = $relationId;
$relationId = \App\Relation::getRelationId($this->textParser->moduleName, $relatedModuleName);
}
- 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 'process'. Open
|| !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))
- 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 instance property recordModel
from undeclared class \App\TextParser
Open
if (!$this->textParser->recordModel
- Exclude checks
Reference to instance property recordModel
from undeclared class \App\TextParser
Open
if ($id === $this->textParser->recordModel->getId()) {
- Exclude checks
Argument 1 (relationId)
is ''
but \App\Relation::getById()
takes int
defined at /code/app/Relation.php:76
Open
$relatedModuleName = \App\Relation::getById($relationId)['related_modulename'] ?? '';
- Exclude checks
Argument 3 (relationId)
is ?''|?int
but \Vtiger_RelationListView_Model::getInstance()
takes bool|false|int
defined at /code/modules/Vtiger/models/RelationListView.php:142
Open
|| !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))
- Exclude checks
Reference to instance property recordModel
from undeclared class \App\TextParser
Open
|| !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))
- Exclude checks
Call to method parseBaseSearchParamsToCondition
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($conditions));
- Exclude checks
Call to method setLimit
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$relationListView->getQueryGenerator()->setLimit((int) $limit);
- Exclude checks
Reference to instance property moduleName
from undeclared class \App\TextParser
Open
$relationId = \App\Relation::getRelationId($this->textParser->moduleName, $relatedModuleName);
- Exclude checks
Avoid excessively long variable names like $transformedSearchParams. Keep variable name length under 20. Open
$transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($conditions));
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Spaces must be used to indent lines; tabs are not allowed Open
$data = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView->set('orderby', $orderBy);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $name = 'LBL_RECORDS_LIST_DATA_TEMPLATE';
- Exclude checks
Line exceeds 120 characters; contains 177 characters Open
public $default = "YFParser('\$(custom : RelatedRecordsData|__RELATION_MODULE_OR_RELATION_ID__|__FIELDS__|__CONDITIONS__|__LIMIT__|__ORDER_BY__|__RELATION_CONDITION__)\$')";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedModuleName = $relationId;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
$transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($conditions));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($limit)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($relConditions) {
- 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
$relationId = \App\Relation::getRelationId($this->textParser->moduleName, $relatedModuleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 146 characters Open
|| !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields = explode(',', $fields);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (is_numeric($relationId)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$this->textParser->recordModel
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView->set('search_rel_params', \App\Json::decode($relConditions));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($orderBy) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data[$id][$fieldModel->getName()] = $fieldModel->getDisplayValue($relatedRecordModel->get($fieldModel->getName()), $id, $relatedRecordModel, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($conditions) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView->set('search_params', $transformedSearchParams);
- 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 ($fieldsModel as $fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $data;
- 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
$fieldsModel = array_intersect_key($relationListView->getHeaders(), array_flip($fields));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($relationListView->getAllEntries() as $id => $relatedRecordModel) {
- 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 ($fieldModel->get('fromOutsideList') || $fieldModel->isViewable()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Process.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var mixed Parser type */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($conditions));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedModuleName = \App\Relation::getById($relationId)['related_modulename'] ?? '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView->setFields($fields);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 168 characters Open
$data[$id][$fieldModel->getName()] = $fieldModel->getDisplayValue($relatedRecordModel->get($fieldModel->getName()), $id, $relatedRecordModel, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Class name */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Default template */
- 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
$relationListView->getQueryGenerator()->setLimit((int) $limit);
- 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
[$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
- 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
|| !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $data;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($id === $this->textParser->recordModel->getId()) {
- 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 $type = 'pdf';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
|| !\App\Privilege::isPermitted($relatedModuleName)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $default = "YFParser('\$(custom : RelatedRecordsData|__RELATION_MODULE_OR_RELATION_ID__|__FIELDS__|__CONDITIONS__|__LIMIT__|__ORDER_BY__|__RELATION_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
}
- Exclude checks