Function doTask
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
$referenceFields = $recordModel->getModule()->getFieldsByReference();
$referenceIds = [];
foreach ($referenceFields as $fieldModel) {
- 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 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function doTask($recordModel)
{
$referenceFields = $recordModel->getModule()->getFieldsByReference();
$referenceIds = [];
foreach ($referenceFields as $fieldModel) {
The method doTask() has an NPath complexity of 204. The configured NPath complexity threshold is 200. Open
public function doTask($recordModel)
{
$referenceFields = $recordModel->getModule()->getFieldsByReference();
$referenceIds = [];
foreach ($referenceFields as $fieldModel) {
- 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 14. The configured cyclomatic complexity threshold is 10. Open
public function doTask($recordModel)
{
$referenceFields = $recordModel->getModule()->getFieldsByReference();
$referenceIds = [];
foreach ($referenceFields as $fieldModel) {
- 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 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 '51', column '10'). Open
(new \OSSTimeControl_TimeCounting_Model($metaData['setype'], $referenceId, $referenceIds[$referenceId]))->recalculateTimeControl();
- 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\ModuleHierarchy' in method 'doTask'. Open
$modulesHierarchy = array_keys(App\ModuleHierarchy::getModulesHierarchy());
- 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 'vtlib\Functions' in method 'doTask'. Open
$metasData = vtlib\Functions::getCRMRecordMetadata(array_keys($referenceIds));
- 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 'getContents'. Open
$this->contents = \App\Json::encode($delta);
- 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
$delta = \App\Json::decode($this->getContents($recordModel));
- 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 '29', column '8'). Open
public function doTask($recordModel)
{
$referenceFields = $recordModel->getModule()->getFieldsByReference();
$referenceIds = [];
foreach ($referenceFields as $fieldModel) {
- 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
Assigning string
to property but \VTUpdateWorkTime->contents
is \Vtiger_Record_Model
Open
$this->contents = \App\Json::encode($delta);
- Exclude checks
Declaration of function getContents(\Vtiger_Record_Model $recordModel) : string
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
Returning type \Vtiger_Record_Model
but getContents()
is declared to return string
Open
return $this->contents;
- Exclude checks
Avoid excessively long variable names like $workflowIdsAlreadyDone. Keep variable name length under 20. Open
public static $workflowIdsAlreadyDone = [];
- 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
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class VTUpdateWorkTime extends VTTask
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$referenceIds = array_diff_key($referenceIds, array_flip(static::$workflowIdsAlreadyDone));
- 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
public function getFieldNames()
- 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 Vtiger_Record_Model $recordModel
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$referenceIds = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$referenceIds[$value] = $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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string 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
return [];
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
$delta = array_intersect_key($recordModel->getPreviousValue(), $recordModel->getModule()->getFieldsByReference());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$this->contents && \is_object($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
$this->contents = \App\Json::encode($delta);
- 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 static $workflowIdsAlreadyDone = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($values) && !\is_array($values)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\is_array($values) && $values['currentValue']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 147 characters Open
(new \OSSTimeControl_TimeCounting_Model($metaData['setype'], $referenceId, $referenceIds[$referenceId]))->recalculateTimeControl();
- 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
public function getContents($recordModel)
- 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
if (\is_array($delta)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($delta as $fieldName => $values) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$referenceIds[$values] = $fieldName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$referenceIds[$values['oldValue']] = $fieldName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$referenceIds[$values['currentValue']] = $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
$referenceFields = $recordModel->getModule()->getFieldsByReference();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modulesHierarchy = array_keys(App\ModuleHierarchy::getModulesHierarchy());
- 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
*
- 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 ($referenceFields as $fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} elseif (\is_array($values) && $values['oldValue']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === ((int) $metaData['deleted']) && \in_array($metaData['setype'], $modulesHierarchy)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
static::$workflowIdsAlreadyDone[] = $referenceId;
- 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
$delta = array_intersect_key($recordModel->getPreviousValue(), $recordModel->getModule()->getFieldsByReference());
- Exclude checks
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
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($metasData as $referenceId => $metaData) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
(new \OSSTimeControl_TimeCounting_Model($metaData['setype'], $referenceId, $referenceIds[$referenceId]))->recalculateTimeControl();
- 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 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
$delta = \App\Json::decode($this->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
$metasData = vtlib\Functions::getCRMRecordMetadata(array_keys($referenceIds));
- 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
if ($value = $recordModel->get($fieldModel->getName())) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks