Function executeScheduled
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function executeScheduled($row)
{
$currentTime = time();
$timestampEndDate = empty($row['last_execution']) ? $currentTime : strtotime($row['last_execution'] . ' +' . $row['frequency'] . 'min');
if ($currentTime >= $timestampEndDate) {
- 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
Missing class import via use statement (line '24', column '17'). Open
$query = (new \App\Db\Query())->from('u_#__watchdog_schedule');
- 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 'markSentNotificationsAsRead'. Open
$noticeRecordModel = \Vtiger_Record_Model::getInstanceById($notification->get('notificationid'), 'Notification');
- 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 'Notification_Module_Model' in method 'existNotifications'. Open
return Notification_Module_Model::getEmailSendEntries($userId, $modules, $startDate, $endDate);
- 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\Privilege' in method 'executeScheduled'. Open
if (\App\Privilege::isPermitted(self::MODULE_NAME, 'ReceivingMailNotifications', false, $row['userid']) && $notificationsToSend) {
- 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 'executeScheduled'. Open
if ($ifEmailSend && \App\Config::module('Notification', 'AUTO_MARK_NOTIFICATIONS_READ_AFTER_EMAIL_SEND')) {
- 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 'executeScheduled'. Open
$ifEmailSend = \App\Mailer::sendFromTemplate([
'moduleName' => 'Notification',
'template' => 'SendNotificationsViaMail',
'to' => \App\User::getUserModel($row['userid'])->getDetail('email1'),
'startDate' => $row['last_execution'],
- 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_Watchdog_Model' in method 'existNotifications'. Open
$scheduleData = Vtiger_Watchdog_Model::getWatchingModulesSchedule($userId, true);
- 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 "last_execution" 5 times. Open
$timestampEndDate = empty($row['last_execution']) ? $currentTime : strtotime($row['last_execution'] . ' +' . $row['frequency'] . 'min');
- 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 "Notification" 4 times. Open
const MODULE_NAME = 'Notification';
- 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 "userid" 6 times. Open
$notificationsToSend = $this->existNotifications($row['userid'], $row['last_execution'], $endDate);
- 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 method getUserModel
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
'to' => \App\User::getUserModel($row['userid'])->getDetail('email1'),
- Exclude checks
Argument 1 (currentTime)
is int
but \Notification_Notifications_Cron::getEndDate()
takes string
defined at /code/modules/Notification/crons/Notifications.php:91
Open
$endDate = $this->getEndDate($currentTime, $timestampEndDate, $row['frequency']);
- Exclude checks
Call to undeclared method \Vtiger_Record_Model::setMarked
Open
$noticeRecordModel->setMarked();
- Exclude checks
Argument 2 (timestampEndDate)
is false|int
but \Notification_Notifications_Cron::getEndDate()
takes string
defined at /code/modules/Notification/crons/Notifications.php:91
Open
$endDate = $this->getEndDate($currentTime, $timestampEndDate, $row['frequency']);
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$query = (new \App\Db\Query())->from('u_#__watchdog_schedule');
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance()->createCommand()
- Exclude checks
Each class must be in a namespace of at least one level (a top-level vendor name) Open
class Notification_Notifications_Cron extends \App\CronHandler
- Exclude checks
The class Notification_Notifications_Cron is not named in CamelCase. Open
class Notification_Notifications_Cron extends \App\CronHandler
{
const MODULE_NAME = 'Notification';
/** {@inheritdoc} */
- 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
const MODULE_NAME = 'Notification';
- 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
$dataReader = $query->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\App\Privilege::isPermitted(self::MODULE_NAME, 'ReceivingMailNotifications', false, $row['userid']) && $notificationsToSend) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'moduleName' => 'Notification',
- Exclude checks
Line exceeds 120 characters; contains 123 characters Open
if ($ifEmailSend && \App\Config::module('Notification', 'AUTO_MARK_NOTIFICATIONS_READ_AFTER_EMAIL_SEND')) {
- 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\Db::getInstance()->createCommand()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->update('u_#__watchdog_schedule', ['last_execution' => $endDate], ['userid' => $row['userid']])
- 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
$currentTime = time();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$timestampEndDate = empty($row['last_execution']) ? $currentTime : strtotime($row['last_execution'] . ' +' . $row['frequency'] . 'min');
- Exclude checks
Line exceeds 120 characters; contains 144 characters Open
$timestampEndDate = empty($row['last_execution']) ? $currentTime : strtotime($row['last_execution'] . ' +' . $row['frequency'] . 'min');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$endDate = $this->getEndDate($currentTime, $timestampEndDate, $row['frequency']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($ifEmailSend && \App\Config::module('Notification', 'AUTO_MARK_NOTIFICATIONS_READ_AFTER_EMAIL_SEND')) {
- 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
* Function set notifications as read.
- 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
$noticeRecordModel = \Vtiger_Record_Model::getInstanceById($notification->get('notificationid'), 'Notification');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->markSentNotificationsAsRead($notificationsToSend);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$scheduleData = Vtiger_Watchdog_Model::getWatchingModulesSchedule($userId, true);
- 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
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function getEndDate($currentTime, $timestampEndDate, $frequency)
- 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
*
- 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
$notificationsToSend = $this->existNotifications($row['userid'], $row['last_execution'], $endDate);
- 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
* Function get date.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $currentTime
- 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 ($timestampEndDate <= $currentTime && ($nextEndDateTime = $timestampEndDate + ($frequency * 60)) <= $currentTime) {
- 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 ($notificationsType as $notification) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$ifEmailSend = \App\Mailer::sendFromTemplate([
- 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
return date('Y-m-d H:i:s', $timestampEndDate);
- 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
private function markSentNotificationsAsRead($notificationsToSend): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($currentTime >= $timestampEndDate) {
- 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
$query = (new \App\Db\Query())->from('u_#__watchdog_schedule');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function executeScheduled($row)
- Exclude checks
Line exceeds 120 characters; contains 142 characters Open
if (\App\Privilege::isPermitted(self::MODULE_NAME, 'ReceivingMailNotifications', false, $row['userid']) && $notificationsToSend) {
- 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
* @param string $startDate
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($scheduleData) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$modules = $scheduleData['modules'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $row
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'template' => 'SendNotificationsViaMail',
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'to' => \App\User::getUserModel($row['userid'])->getDetail('email1'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$timestampEndDate = $nextEndDateTime;
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
$noticeRecordModel = \Vtiger_Record_Model::getInstanceById($notification->get('notificationid'), 'Notification');
- 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
Line exceeds 120 characters; contains 129 characters Open
while ($timestampEndDate <= $currentTime && ($nextEndDateTime = $timestampEndDate + ($frequency * 60)) <= $currentTime) {
- 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
$noticeRecordModel->setMarked();
- 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
$this->executeScheduled($row);
- 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
while ($row = $dataReader->read()) {
- 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
'userId' => $row['userid'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private function existNotifications($userId, $startDate, $endDate): array
- 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
* @param int $frequency
- 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 ($notificationsToSend as $notificationsType) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function executes the sending notifications action.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'startDate' => $row['last_execution'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'endDate' => $endDate,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Function checks if notification exists.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $userId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return Notification_Module_Model::getEmailSendEntries($userId, $modules, $startDate, $endDate);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $notificationsToSend
- 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 string $endDate
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $timestampEndDate
- Exclude checks
Class name "Notification_Notifications_Cron" is not in camel caps format Open
class Notification_Notifications_Cron extends \App\CronHandler
- Exclude checks