Function process
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
public function process()
{
$dbCommand = App\Db::getInstance()->createCommand();
$scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
$dataReader = (new App\Db\Query())->select([
- 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 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function process()
{
$dbCommand = App\Db::getInstance()->createCommand();
$scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
$dataReader = (new App\Db\Query())->select([
The method process() has an NPath complexity of 770. The configured NPath complexity threshold is 200. Open
public function process()
{
$dbCommand = App\Db::getInstance()->createCommand();
$scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
$dataReader = (new App\Db\Query())->select([
- 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 15. The configured cyclomatic complexity threshold is 10. Open
public function process()
{
$dbCommand = App\Db::getInstance()->createCommand();
$scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
$dataReader = (new App\Db\Query())->select([
- 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 29 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
Missing class import via use statement (line '34', column '22'). Open
$dataReader = (new App\Db\Query())->from('s_#__mail_relation_updater')->createCommand()->query();
- 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 '22', column '22'). Open
$dataReader = (new App\Db\Query())->select([
- 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 '72', column '28'). Open
$dataReaderMail = (new App\Db\Query())->select(['vtiger_ossmailview.*', 'roundcube_users.actions'])
- 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\Module' in method 'process'. Open
$moduleName = \App\Module::getModuleName($relationRow['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 'Vtiger_Record_Model' in method 'process'. Open
$recordModel = Vtiger_Record_Model::getInstanceById($relationRow['crmid'], $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 'Vtiger_Record_Model' in method 'process'. Open
$scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
- 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 "vtiger_ossmailview" 3 times. Open
])->from('vtiger_ossmailview')
- 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 "email" 3 times. Open
$bind = 'email';
- 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" 5 times. Open
$dbCommand->delete('vtiger_ossmailview_relation', ['crmid' => $relationRow['crmid']])->execute();
- 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.
Avoid unused local variables such as '$fieldModel'. Open
foreach ($fieldModels as $fieldName => $fieldModel) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Call to undeclared method \App\Db::createCommand
Open
$dbCommand = App\Db::getInstance()->createCommand();
- Exclude checks
Call to undeclared method \Vtiger_Record_Model::bindMail
Open
$scannerModel->bindMail($row);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReaderMail = (new App\Db\Query())->select(['vtiger_ossmailview.*', 'roundcube_users.actions'])
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$dataReader = (new App\Db\Query())->from('s_#__mail_relation_updater')->createCommand()->query();
- Exclude checks
Call to undeclared method \Vtiger_Record_Model::bindMail
Open
$scannerModel->bindMail($row);
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new App\Db\Query())->select([
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class OSSMailScanner_Bind_Cron extends \App\CronHandler
- Exclude checks
The class OSSMailScanner_Bind_Cron is not named in CamelCase. Open
class OSSMailScanner_Bind_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
public function process()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbCommand->update('vtiger_ossmailview', ['verify' => 0], ['ossmailviewid' => $row['ossmailviewid']])->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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($fieldModels as $fieldName => $fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$scannerModel->bindMail($row);
- 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
$dbCommand = App\Db::getInstance()->createCommand();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_ossmailview.*',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('roundcube_users', 'roundcube_users.user_id = vtiger_ossmailview.rc_user')->where(['vtiger_ossmailview.verify' => 1])
- Exclude checks
Line exceeds 120 characters; contains 125 characters Open
$dbCommand->update('vtiger_ossmailview', ['verify' => 0], ['ossmailviewid' => $row['ossmailviewid']])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader->close();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bindByEmail = ['Leads', 'Accounts', 'Partners', 'Vendors', 'Competition', 'Contacts', 'OSSEmployees'];
- 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
$dataReader = (new App\Db\Query())->select([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bindByPrefix = ['Campaigns', 'HelpDesk', 'Project', 'SSalesProcesses'];
- 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 ('prefix' == $bind) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where[] = ['to_email' => $email];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbCommand->delete('s_#__mail_relation_updater', ['crmid' => $relationRow['crmid']])->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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where[] = ['bcc_email' => $email];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader->close();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = (new App\Db\Query())->from('s_#__mail_relation_updater')->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where[] = ['cc_email' => $email];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where($where)->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'roundcube_users.actions',
- 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
$bind = 'email';
- 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
->innerJoin('roundcube_users', 'roundcube_users.user_id = vtiger_ossmailview.rc_user')
- Exclude checks
Line exceeds 120 characters; contains 141 characters Open
->innerJoin('roundcube_users', 'roundcube_users.user_id = vtiger_ossmailview.rc_user')->where(['vtiger_ossmailview.verify' => 1])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($relationRow = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbCommand->delete('vtiger_ossmailview_relation', ['crmid' => $relationRow['crmid']])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bind = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fieldModels = $recordModel->getModule()->getFieldsByType('email');
- 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
while ($row = $dataReaderMail->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
break;
- 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
$moduleName = \App\Module::getModuleName($relationRow['tabid']);
- 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
$dataReaderMail = (new App\Db\Query())->select(['vtiger_ossmailview.*', 'roundcube_users.actions'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReaderMail->close();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($this->checkTimeout()) {
- 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 (!empty($where) && $where !== ['or']) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$scannerModel->bindMail($row);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Vtiger_Record_Model::getInstanceById($relationRow['crmid'], $moduleName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($recordNumber)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where = ['like', 'vtiger_ossmailview.subject', "[{$recordNumber}]"];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$where[] = ['from_email' => $email];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('vtiger_ossmailview')
- 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 (\in_array($moduleName, $bindByEmail)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$recordModel->isEmpty($fieldName)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$email = $recordModel->get($fieldName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$bind = 'prefix';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (false === $bind) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordNumber = $recordModel->getRecordNumber();
- 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
$where = ['or'];
- 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 (\in_array($moduleName, $bindByPrefix)) {
- 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
} elseif ('email' == $bind) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
])->from('vtiger_ossmailview')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Class name "OSSMailScanner_Bind_Cron" is not in camel caps format Open
class OSSMailScanner_Bind_Cron extends \App\CronHandler
- Exclude checks