Method process
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process(): string
{
$relatedModuleName = 'Documents';
if (!$this->textParser->recordModel
|| !\App\Privilege::isPermitted($relatedModuleName)
Function process
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function process(): string
{
$relatedModuleName = 'Documents';
if (!$this->textParser->recordModel
|| !\App\Privilege::isPermitted($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
The method process() has an NPath complexity of 4864. The configured NPath complexity threshold is 200. Open
public function process(): string
{
$relatedModuleName = 'Documents';
if (!$this->textParser->recordModel
|| !\App\Privilege::isPermitted($relatedModuleName)
- 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 19. The configured cyclomatic complexity threshold is 10. Open
public function process(): string
{
$relatedModuleName = 'Documents';
if (!$this->textParser->recordModel
|| !\App\Privilege::isPermitted($relatedModuleName)
- 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 19 to the 15 allowed. Open
public function process(): string
- 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 assigning values to variables in if clauses and the like (line '70', column '10'). Open
public function process(): string
{
$relatedModuleName = 'Documents';
if (!$this->textParser->recordModel
|| !\App\Privilege::isPermitted($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\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 '\Vtiger_RelationListView_Model' in method 'process'. Open
|| !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->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 assigning values to variables in if clauses and the like (line '71', column '10'). Open
public function process(): string
{
$relatedModuleName = 'Documents';
if (!$this->textParser->recordModel
|| !\App\Privilege::isPermitted($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 assigning values to variables in if clauses and the like (line '39', column '9'). Open
public function process(): string
{
$relatedModuleName = 'Documents';
if (!$this->textParser->recordModel
|| !\App\Privilege::isPermitted($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 assigning values to variables in if clauses and the like (line '52', column '10'). Open
public function process(): string
{
$relatedModuleName = 'Documents';
if (!$this->textParser->recordModel
|| !\App\Privilege::isPermitted($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\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
Define a constant instead of duplicating this literal "filename" 3 times. Open
$fields = $fields ?: ['notes_title', 'filename'];
- 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.
Call to undeclared method \Vtiger_Record_Model::getFileDetails
Open
&& ($info = $relatedRecordModel->getFileDetails())
- Exclude checks
Reference to instance property recordModel
from undeclared class \App\TextParser
Open
if (!$this->textParser->recordModel
- 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 getParam
from undeclared class \App\TextParser
(Did you mean class \Tests\App\TextParser) Open
$pdf = $attachFiles ? $this->textParser->getParam('pdf') : null;
- Exclude checks
Call to undeclared method \Vtiger_Record_Model::checkFileIntegrity
Open
if ($pdf && $relatedRecordModel->checkFileIntegrity()
- Exclude checks
Reference to instance property recordModel
from undeclared class \App\TextParser
Open
|| !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $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
/** @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
/** @var string Class name */
- Exclude checks
Line exceeds 120 characters; contains 133 characters Open
|| !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $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
public $default = '$(custom : RelatedAttachments|__FIELD_NAMES__|__CONDITIONS__|__ATTACH_FILES__)$';
- 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
|| !\App\Privilege::isPermitted($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
*/
- 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
if ($pdf && $relatedRecordModel->checkFileIntegrity()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
&& ($filePath = $info['path'] . $info['attachmentsid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function process(): string
- 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
return '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!($fieldModel = $relationListView->getRelatedModuleModel()->getFieldByName($field)) || !$fieldModel->isActiveField()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($relationListView->getAllEntries() as $relatedRecordModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row[] = 'filename' === $fieldName ? "({$value})" : $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
$counter = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
&& !isset($pdf->attachFiles[$filePath])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relatedModuleName = 'Documents';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rows[] = "{$counter}. " . implode(', ', $row);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (trim($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
$pdf->attachFiles[$filePath] = ['name' => $info['name'], 'path' => $filePath];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Process.
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
if (!($fieldModel = $relationListView->getRelatedModuleModel()->getFieldByName($field)) || !$fieldModel->isActiveField()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$rows = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $relatedRecordModel->getDisplayValue($fieldName, false, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
&& ($info = $relatedRecordModel->getFileDetails())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $name = 'LBL_RELATED_ATTACHMENTS';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
|| !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields = array_filter(explode(',', trim($fields)));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$relationListView->setFields(array_unique(array_merge($fields, ['notes_title', 'filename', 'filelocationtype'])));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fields as $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
foreach ($fields as $key => $field) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return empty($rows) ? '' : implode('<br>', $rows);
- 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
[$fields, $conditions, $attachFiles] = array_pad($this->params, 3, '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdf = $attachFiles ? $this->textParser->getParam('pdf') : null;
- 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
$fields = $fields ?: ['notes_title', 'filename'];
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$relationListView->setFields(array_unique(array_merge($fields, ['notes_title', 'filename', 'filelocationtype'])));
- 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
unset($fields[$key]);
- 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 = trim($value);
- 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 $type = 'pdf';
- 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
++$counter;
- Exclude checks