Function process
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
public function process()
{
$moduleModel = \Vtiger_Module_Model::getInstance($this->textParser->moduleName);
$fields = $moduleModel->getFields();
$ids = $this->textParser->getParam('pdf')->getVariable('recordsId');
- 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 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process()
{
$moduleModel = \Vtiger_Module_Model::getInstance($this->textParser->moduleName);
$fields = $moduleModel->getFields();
$ids = $this->textParser->getParam('pdf')->getVariable('recordsId');
The method process() has an NPath complexity of 352. The configured NPath complexity threshold is 200. Open
public function process()
{
$moduleModel = \Vtiger_Module_Model::getInstance($this->textParser->moduleName);
$fields = $moduleModel->getFields();
$ids = $this->textParser->getParam('pdf')->getVariable('recordsId');
- 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 13. The configured cyclomatic complexity threshold is 10. Open
public function process()
{
$moduleModel = \Vtiger_Module_Model::getInstance($this->textParser->moduleName);
$fields = $moduleModel->getFields();
$ids = $this->textParser->getParam('pdf')->getVariable('recordsId');
- 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 20 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 '\Vtiger_Module_Model' in method 'process'. Open
$moduleModel = \Vtiger_Module_Model::getInstance($this->textParser->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 '\App\Fields\RangeTime' in method 'process'. Open
$content = '<strong>' . \App\Fields\RangeTime::displayElapseTime($summary['sum_time']) . '</strong>';
- 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\Language' in method 'process'. Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->get('label'), $this->textParser->moduleName) . '</th>';
- 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 'process'. Open
$recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $this->textParser->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 '\App\Language' in method 'process'. Open
$content = '<strong>' . \App\Language::translate('LBL_SUMMARY', $this->textParser->moduleName) . ':' . '</strong>';
- 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 "sum_time" 8 times. Open
foreach (['name', 'link', 'time_start', 'time_end', 'sum_time'] as $column) {
- 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.
Reference to instance property moduleName
from undeclared class \App\TextParser
Open
$recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $this->textParser->moduleName);
- Exclude checks
Reference to instance property moduleName
from undeclared class \App\TextParser
Open
$moduleModel = \Vtiger_Module_Model::getInstance($this->textParser->moduleName);
- Exclude checks
Invalid offset "sum_time"
of array type array{}
Open
$summary['sum_time'] = $summary['sum_time'] ?? 0;
- Exclude checks
Reference to instance property moduleName
from undeclared class \App\TextParser
Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->get('label'), $this->textParser->moduleName) . '</th>';
- Exclude checks
Call to method getParam
from undeclared class \App\TextParser
(Did you mean class \Tests\App\TextParser) Open
$ids = $this->textParser->getParam('pdf')->getVariable('recordsId');
- Exclude checks
Reference to instance property moduleName
from undeclared class \App\TextParser
Open
$content = '<strong>' . \App\Language::translate('LBL_SUMMARY', $this->textParser->moduleName) . ':' . '</strong>';
- Exclude checks
Identical blocks of code found in 2 locations. Consider refactoring. Open
foreach ($columns as $column) {
$style = $bodyStyle;
$columnName = $column->getName();
$content = '';
if ('sum_time' === $columnName) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 136.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class OSSTimeControl_List_Textparser extends \App\TextParser\Base
- Exclude checks
The class OSSTimeControl_List_Textparser is not named in CamelCase. Open
class OSSTimeControl_List_Textparser extends \App\TextParser\Base
{
/** @var string Class name */
public $name = 'LBL_TIME_CONTROL_LIST';
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
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
Line exceeds 120 characters; contains 148 characters Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->get('label'), $this->textParser->moduleName) . '</th>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '</tr></thead><tbody>';
- 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 ('sum_time' === $columnName) {
- 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 mixed Parser type */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html = '<table border="1" class="products-table" style="border-collapse:collapse;width:100%;"><thead><tr>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$columnName = $column->getName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$columnName = $column->getName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $html . '</tr></tfoot></table>';
- 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
$columns[$fieldModel->getName()] = $fieldModel;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$style = $bodyStyle . 'text-align:center;';
- 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
$fields = $moduleModel->getFields();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bodyStyle = 'font-size:8px;border:1px solid #ddd;padding:0px4px;';
- 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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$columns = [];
- 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 $recordId) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '<tr>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$content = '';
- Exclude checks
Line exceeds 120 characters; contains 131 characters Open
$content = '<strong>' . \App\Language::translate('LBL_SUMMARY', $this->textParser->moduleName) . ':' . '</strong>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$headerStyle = 'font-size:9px;padding:0px 4px;text-align:center;';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->get('label'), $this->textParser->moduleName) . '</th>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '</tr>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= '</tbody><tfoot><tr>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$style = $bodyStyle . 'text-align:center;';
- 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
$moduleModel = \Vtiger_Module_Model::getInstance($this->textParser->moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\is_array($ids)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($columns as $column) {
- 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
$ids = $this->textParser->getParam('pdf')->getVariable('recordsId');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = \Vtiger_Record_Model::getInstanceById($recordId, $this->textParser->moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$recordModel->isViewable()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ('sum_time' === $columnName) {
- 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
public $name = 'LBL_TIME_CONTROL_LIST';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach (['name', 'link', 'time_start', 'time_end', 'sum_time'] as $column) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModel = $fields[$column];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$style = $bodyStyle;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= "<td style=\"{$style}\">" . $content . '</td>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$summary = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$html .= "<td style=\"{$style}\">" . $recordModel->getDisplayValue($columnName, $recordId, true) . '</td>';
- 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
public function process()
- 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
$ids = [$ids];
- 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
$summary['sum_time'] += $recordModel->get($columnName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif ('name' === $columnName) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$style = $bodyStyle;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($columnName, ['time_start', 'time_end', 'due_date', 'date_start', 'sum_time'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$html .= "<td style=\"{$style}\">" . $recordModel->getDisplayValue($columnName, $recordId, true) . '</td>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$content = '<strong>' . \App\Language::translate('LBL_SUMMARY', $this->textParser->moduleName) . ':' . '</strong>';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$summary['sum_time'] = $summary['sum_time'] ?? 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$fieldModel || !$fieldModel->isActiveField()) {
- 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
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($columns as $column) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$content = '<strong>' . \App\Fields\RangeTime::displayElapseTime($summary['sum_time']) . '</strong>';
- Exclude checks
Class name "OSSTimeControl_List_Textparser" is not in camel caps format Open
class OSSTimeControl_List_Textparser extends \App\TextParser\Base
- Exclude checks