Function process
has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring. Open
public function process()
{
\App\Log::trace('Start SendReminder');
$dataReader = (new \App\Db\Query())->select([
'vtiger_crmentity.smownerid',
- 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()
{
\App\Log::trace('Start SendReminder');
$dataReader = (new \App\Db\Query())->select([
'vtiger_crmentity.smownerid',
The method process() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public function process()
{
\App\Log::trace('Start SendReminder');
$dataReader = (new \App\Db\Query())->select([
'vtiger_crmentity.smownerid',
- 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 25 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 '19', 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 '50', column '17'). Open
$date = new DateTimeField("$dateStart $timeStart");
- 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 '36', column '30'). Open
$reminderFrequency = (new \App\Db\Query())->select(['frequency'])->from('vtiger_cron_task')->where(['name' => 'LBL_SEND_REMINDER'])->scalar();
- 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 '43', column '17'). Open
$date = new DateTimeField(null);
- 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 'Vtiger_Record_Model' in method 'process'. Open
$recordModel = Vtiger_Record_Model::getCleanInstance('Calendar');
- 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 'DateTimeField' in method 'process'. Open
$dBFomatedDate = DateTimeField::convertToDBFormat($userFormatedString);
- 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 'DateTimeField' in method 'process'. Open
$dBFomatedDate = DateTimeField::convertToDBFormat($userFormatedString);
- 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
if (App\Config::module('Calendar', 'SEND_REMINDER_INVITATION')) {
- 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\Mailer' in method 'process'. Open
\App\Mailer::sendFromTemplate([
'template' => 'ActivityReminderNotificationTask',
'moduleName' => 'Calendar',
'recordId' => $activityId,
'to' => $toEmail,
- 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\Mailer' in method 'process'. Open
\App\Mailer::sendFromTemplate([
'template' => 'ActivityReminderNotificationInvitation',
'moduleName' => 'Calendar',
'recordId' => $activityId,
'to' => $invitation['email'],
- 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\Log' in method 'process'. Open
\App\Log::trace('End Send SendReminder');
- 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\Log' in method 'process'. Open
\App\Log::trace('Start Send SendReminder');
- 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\Log' in method 'process'. Open
\App\Log::trace('Start SendReminder');
- 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\Email' in method 'process'. Open
$toEmail = App\Fields\Email::getUserMail($row['smownerid']);
- 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 "Calendar" 4 times. Open
$recordModel = Vtiger_Record_Model::getCleanInstance('Calendar');
- 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
$dbCommand = App\Db::getInstance()->createCommand();
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('Start SendReminder');
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$dataReader = (new \App\Db\Query())->select([
- Exclude checks
Argument 1 (value)
is string
but \DateTimeField::__construct()
takes \type
defined at /code/include/fields/DateTimeField.php:31
Open
$date = new DateTimeField("$dateStart $timeStart");
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('Start Send SendReminder');
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$reminderFrequency = (new \App\Db\Query())->select(['frequency'])->from('vtiger_cron_task')->where(['name' => 'LBL_SEND_REMINDER'])->scalar();
- Exclude checks
Argument 1 (value)
is null
but \DateTimeField::__construct()
takes \type
defined at /code/include/fields/DateTimeField.php:31
Open
$date = new DateTimeField(null);
- Exclude checks
Call to method trace
from undeclared class \App\Log
Open
\App\Log::trace('End Send SendReminder');
- Exclude checks
Call to undeclared method \Vtiger_Record_Model::getInvities
Open
$invitees = $recordModel->getInvities();
- Exclude checks
Avoid excessively long variable names like $differenceOfActivityTimeAndCurrentTime. Keep variable name length under 20. Open
$differenceOfActivityTimeAndCurrentTime = ($activityTime - $currTime);
- 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 Calendar_SendReminder_Cron extends \App\CronHandler
- Exclude checks
The class Calendar_SendReminder_Cron is not named in CamelCase. Open
class Calendar_SendReminder_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
'vtiger_activity.time_start',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['vtiger_activity.status' => 'PLL_PLANNED'],
- 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
/** {@inheritdoc} */
- 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\Log::trace('Start SendReminder');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_activity.date_start',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$reminderTime = $row['reminder_time'] * 60;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel->setId($activityId);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'to' => $toEmail,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbCommand->update('vtiger_activity_reminder', ['reminder_sent' => 1], ['activity_id' => $activityId])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'moduleName' => 'Calendar',
- 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
['vtiger_activity_reminder.reminder_sent' => 0],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($dataReader->count()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$timeStart = $row['time_start'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$invitees = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$invitees = $recordModel->getInvities();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'recordId' => $activityId,
- 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
])->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$differenceOfActivityTimeAndCurrentTime = ($activityTime - $currTime);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'moduleName' => 'Calendar',
- 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
])->from('vtiger_activity')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
//code included for recurring events by jaguar ends
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$toEmail = App\Fields\Email::getUserMail($row['smownerid']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_activity.activitytype',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dBFomatedDate = DateTimeField::convertToDBFormat($userFormatedString);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$activityTime = strtotime("$dBFomatedDate $timeFormatedString");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['>=', 'vtiger_activity.date_start', date('Y-m-d')],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$date = new DateTimeField("$dateStart $timeStart");
- 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
'vtiger_crmentity.smownerid',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['and',
- Exclude checks
Line exceeds 120 characters; contains 154 characters Open
$reminderFrequency = (new \App\Db\Query())->select(['frequency'])->from('vtiger_cron_task')->where(['name' => 'LBL_SEND_REMINDER'])->scalar();
- 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
$dateStart = $row['date_start'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dBFomatedDate = DateTimeField::convertToDBFormat($userFormatedString);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$timeFormatedString = $date->getDisplayTime();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'template' => 'ActivityReminderNotificationInvitation',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_activity.activityid',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'vtiger_activity_reminder.reminder_time'
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$date = new DateTimeField(null);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (($differenceOfActivityTimeAndCurrentTime > 0) && (($differenceOfActivityTimeAndCurrentTime <= $reminderTime) || ($differenceOfActivityTimeAndCurrentTime <= $reminderFrequency))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'recordId' => $activityId,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$reminderFrequency = (new \App\Db\Query())->select(['frequency'])->from('vtiger_cron_task')->where(['name' => 'LBL_SEND_REMINDER'])->scalar();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$activityId = $row['activityid'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$userFormatedString = $date->getDisplayDate();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($invitees as &$invitation) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Mailer::sendFromTemplate([
- 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
$userFormatedString = $date->getDisplayDate();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Log::trace('Start Send SendReminder');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (App\Config::module('Calendar', 'SEND_REMINDER_INVITATION')) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'template' => 'ActivityReminderNotificationTask',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$timeFormatedString = $date->getDisplayTime();
- Exclude checks
Line exceeds 120 characters; contains 199 characters Open
if (($differenceOfActivityTimeAndCurrentTime > 0) && (($differenceOfActivityTimeAndCurrentTime <= $reminderTime) || ($differenceOfActivityTimeAndCurrentTime <= $reminderFrequency))) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Mailer::sendFromTemplate([
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_crmentity', 'vtiger_crmentity.crmid=vtiger_activity.activityid')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
//To fetch reminder frequency from cron tasks
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordModel = Vtiger_Record_Model::getCleanInstance('Calendar');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->innerJoin('vtiger_activity_reminder', 'vtiger_activity.activityid = vtiger_activity_reminder.activity_id')
- 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
$currTime = strtotime("$dBFomatedDate $timeFormatedString");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($toEmail)) {
- Exclude checks
Line exceeds 120 characters; contains 138 characters Open
$dbCommand->update('vtiger_activity_reminder', ['reminder_sent' => 1], ['activity_id' => $activityId])->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
if (!empty($invitation['email'])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'to' => $invitation['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
}
- 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
\App\Log::trace('End Send SendReminder');
- Exclude checks
Class name "Calendar_SendReminder_Cron" is not in camel caps format Open
class Calendar_SendReminder_Cron extends \App\CronHandler
- Exclude checks