Function process
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
public function process()
{
$limit = App\Config::performance('CRON_MAX_NUMBERS_RECORD_PRIVILEGES_UPDATER');
$query = (new \App\Db\Query())->select(['crmid', 'setype'])
->from('vtiger_crmentity')
- 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 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process()
{
$limit = App\Config::performance('CRON_MAX_NUMBERS_RECORD_PRIVILEGES_UPDATER');
$query = (new \App\Db\Query())->select(['crmid', 'setype'])
->from('vtiger_crmentity')
The method process() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
public function process()
{
$limit = App\Config::performance('CRON_MAX_NUMBERS_RECORD_PRIVILEGES_UPDATER');
$query = (new \App\Db\Query())->select(['crmid', 'setype'])
->from('vtiger_crmentity')
- 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 33 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
Reduce the number of returns of this function 4, down to the maximum allowed 3. Open
public function process()
- Read upRead up
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Missing class import via use statement (line '22', column '17'). Open
$query = (new \App\Db\Query())->select(['crmid', 'setype'])
- 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
Missing class import via use statement (line '38', column '17'). Open
$query = (new \App\Db\Query())->from('u_#__crmentity_search_label')->where(['userid' => null])->limit($limit);
- 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
Missing class import via use statement (line '50', column '17'). Open
$query = (new \App\Db\Query())->from('s_#__privileges_updater')->orderBy(['priority' => SORT_DESC])->limit($limit);
- 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
Missing class import via use statement (line '63', column '28'). Open
$dataReaderCrm = (new \App\Db\Query())->select(['crmid'])
- 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
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 {
$dataReaderCrm = (new \App\Db\Query())->select(['crmid'])
->from('vtiger_crmentity')
->where(['and', ['deleted' => [0, 2]], ['setype' => $row['module']], ['>', 'crmid', $crmid]])
->limit($limit)
- 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 '\App\Module' in method 'process'. Open
\App\PrivilegeUpdater::updateSearch($row['crmid'], \App\Module::getModuleName($row['tabid']));
- 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\PrivilegeUpdater' in method 'process'. Open
\App\PrivilegeUpdater::update($row['crmid'], $row['setype']);
- 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\PrivilegeUpdater' in method 'process'. Open
\App\PrivilegeUpdater::update($rowCrm['crmid'], $row['module']);
- 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\Config' in method 'process'. Open
$limit = App\Config::performance('CRON_MAX_NUMBERS_RECORD_PRIVILEGES_UPDATER');
- 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\PrivilegeUpdater' in method 'process'. Open
\App\PrivilegeUpdater::updateSearch($row['crmid'], \App\Module::getModuleName($row['tabid']));
- 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\Db' in method 'process'. Open
$db = App\Db::getInstance();
- 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\PrivilegeUpdater' in method 'process'. Open
\App\PrivilegeUpdater::update($crmid, $row['module']);
- 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 "s_#__privileges_updater" 3 times. Open
$query = (new \App\Db\Query())->from('s_#__privileges_updater')->orderBy(['priority' => SORT_DESC])->limit($limit);
- 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.
Define a constant instead of duplicating this literal "module" 7 times. Open
\App\PrivilegeUpdater::update($crmid, $row['module']);
- 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.
Define a constant instead of duplicating this literal "crmid" 12 times. Open
$query = (new \App\Db\Query())->select(['crmid', 'setype'])
- 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.
Define a constant instead of duplicating this literal "setype" 3 times. Open
$query = (new \App\Db\Query())->select(['crmid', 'setype'])
- 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 \App\Db::createCommand
Open
$affected = $db->createCommand()->update('s_#__privileges_updater', ['crmid' => $rowCrm['crmid']], [
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$query = (new \App\Db\Query())->select(['crmid', 'setype'])
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$query = (new \App\Db\Query())->from('u_#__crmentity_search_label')->where(['userid' => null])->limit($limit);
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$query = (new \App\Db\Query())->from('s_#__privileges_updater')->orderBy(['priority' => SORT_DESC])->limit($limit);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReaderCrm = (new \App\Db\Query())->select(['crmid'])
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()->delete('s_#__privileges_updater', [
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Vtiger_PrivilegesUpdater_Cron extends \App\CronHandler
- Exclude checks
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = App\Db::getInstance();
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The class Vtiger_PrivilegesUpdater_Cron is not named in CamelCase. Open
class Vtiger_PrivilegesUpdater_Cron extends \App\CronHandler
{
/** {@inheritdoc} */
public function process()
{
- 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
$query = (new \App\Db\Query())->from('u_#__crmentity_search_label')->where(['userid' => null])->limit($limit);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['vtiger_tab.presence' => 0, 'deleted' => [0, 2], 'users' => null])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
--$limit;
- 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
$query = (new \App\Db\Query())->select(['crmid', 'setype'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($rows as $row) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db = App\Db::getInstance();
- 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
$dataReaderCrm->close();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\PrivilegeUpdater::updateSearch($row['crmid'], \App\Module::getModuleName($row['tabid']));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$crmid = $rowCrm['crmid'];
- 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 ($query->batch(100) as $rows) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Line exceeds 120 characters; contains 124 characters Open
$affected = $db->createCommand()->update('s_#__privileges_updater', ['crmid' => $rowCrm['crmid']], [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\PrivilegeUpdater::update($crmid, $row['module']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'module' => $row['module'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => 1,
- 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
'crmid' => $crmid,
- 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
--$limit;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'type' => $row['type'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'crmid' => $crmid,
- 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
--$limit;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'module' => $row['module'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === $limit) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$limit = App\Config::performance('CRON_MAX_NUMBERS_RECORD_PRIVILEGES_UPDATER');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->limit($limit);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($query->batch(100) as $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
return;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->limit($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
$this->updateLastActionTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->createCommand()->query();
- 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
->from('vtiger_crmentity')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_tab', 'vtiger_tab.name = vtiger_crmentity.setype')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\PrivilegeUpdater::update($row['crmid'], $row['setype']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db->createCommand()->delete('s_#__privileges_updater', [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($query->batch(100) as $rows) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($rows as $row) {
- 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
->from('vtiger_crmentity')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
])->execute();
- 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->updateLastActionTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($rows as $row) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
--$limit;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === $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
$crmid = $row['crmid'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\PrivilegeUpdater::update($rowCrm['crmid'], $row['module']);
- 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
$query = (new \App\Db\Query())->from('s_#__privileges_updater')->orderBy(['priority' => SORT_DESC])->limit($limit);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === (int) $row['type']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$affected = $db->createCommand()->update('s_#__privileges_updater', ['crmid' => $rowCrm['crmid']], [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (0 === $limit || 0 === (int) $affected) {
- 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
if (0 === $limit) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
$query = (new \App\Db\Query())->from('s_#__privileges_updater')->orderBy(['priority' => SORT_DESC])->limit($limit);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->updateLastActionTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReaderCrm = (new \App\Db\Query())->select(['crmid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['and', ['deleted' => [0, 2]], ['setype' => $row['module']], ['>', 'crmid', $crmid]])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($rowCrm = $dataReaderCrm->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "Vtiger_PrivilegesUpdater_Cron" is not in camel caps format Open
class Vtiger_PrivilegesUpdater_Cron extends \App\CronHandler
- Exclude checks