YetiForceCompany/YetiForceCRM

View on GitHub
modules/Calendar/crons/SendReminder.php

Summary

Maintainability
B
6 hrs
Test Coverage
F
22%

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',
Severity: Minor
Found in modules/Calendar/crons/SendReminder.php - About 3 hrs to fix

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',
Severity: Major
Found in modules/Calendar/crons/SendReminder.php - About 2 hrs to fix

    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',

    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()

    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([

    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");

    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();

    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);

    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');

    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);

    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);

    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')) {

    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,

    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'],

    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');

    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');

    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');

    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']);

    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');

    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();
    Severity: Critical
    Found in modules/Calendar/crons/SendReminder.php by phan

    Call to method trace from undeclared class \App\Log
    Open

            \App\Log::trace('Start SendReminder');
    Severity: Critical
    Found in modules/Calendar/crons/SendReminder.php by phan

    Call to undeclared method \App\Db\Query::select
    Open

            $dataReader = (new \App\Db\Query())->select([
    Severity: Critical
    Found in modules/Calendar/crons/SendReminder.php by phan

    Argument 1 (value) is string but \DateTimeField::__construct() takes \type defined at /code/include/fields/DateTimeField.php:31
    Open

                    $date = new DateTimeField("$dateStart $timeStart");

    Call to method trace from undeclared class \App\Log
    Open

                        \App\Log::trace('Start Send SendReminder');
    Severity: Critical
    Found in modules/Calendar/crons/SendReminder.php by phan

    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();
    Severity: Critical
    Found in modules/Calendar/crons/SendReminder.php by phan

    Argument 1 (value) is null but \DateTimeField::__construct() takes \type defined at /code/include/fields/DateTimeField.php:31
    Open

                    $date = new DateTimeField(null);

    Call to method trace from undeclared class \App\Log
    Open

                        \App\Log::trace('End Send SendReminder');
    Severity: Critical
    Found in modules/Calendar/crons/SendReminder.php by phan

    Call to undeclared method \Vtiger_Record_Model::getInvities
    Open

                            $invitees = $recordModel->getInvities();
    Severity: Critical
    Found in modules/Calendar/crons/SendReminder.php by phan

    Avoid excessively long variable names like $differenceOfActivityTimeAndCurrentTime. Keep variable name length under 20.
    Open

                    $differenceOfActivityTimeAndCurrentTime = ($activityTime - $currTime);

    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

    The class Calendar_SendReminder_Cron is not named in CamelCase.
    Open

    class Calendar_SendReminder_Cron extends \App\CronHandler
    {
        /** {@inheritdoc} */
        public function process()
        {

    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',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    ['vtiger_activity.status' => 'PLL_PLANNED'],

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                ]);

    Spaces must be used to indent lines; tabs are not allowed
    Open

        /** {@inheritdoc} */

    Spaces must be used to indent lines; tabs are not allowed
    Open

        {

    Spaces must be used to indent lines; tabs are not allowed
    Open

            \App\Log::trace('Start SendReminder');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vtiger_activity.date_start',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $reminderTime = $row['reminder_time'] * 60;

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $recordModel->setId($activityId);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                'to' => $toEmail,

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $dbCommand->update('vtiger_activity_reminder', ['reminder_sent' => 1], ['activity_id' => $activityId])->execute();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                    'moduleName' => 'Calendar',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    ['vtiger_activity_reminder.reminder_sent' => 0],

    Spaces must be used to indent lines; tabs are not allowed
    Open

            if ($dataReader->count()) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $timeStart = $row['time_start'];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $invitees = [];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            $invitees = $recordModel->getInvities();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                'recordId' => $activityId,

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            ]);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ])->createCommand()->query();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $differenceOfActivityTimeAndCurrentTime = ($activityTime - $currTime);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                'moduleName' => 'Calendar',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            $dataReader = (new \App\Db\Query())->select([

    Spaces must be used to indent lines; tabs are not allowed
    Open

            ])->from('vtiger_activity')

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    //code included for recurring events by jaguar ends

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        $toEmail = App\Fields\Email::getUserMail($row['smownerid']);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vtiger_activity.activitytype',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $dBFomatedDate = DateTimeField::convertToDBFormat($userFormatedString);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $activityTime = strtotime("$dBFomatedDate $timeFormatedString");

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    ['>=', 'vtiger_activity.date_start', date('Y-m-d')],

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $date = new DateTimeField("$dateStart $timeStart");

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vtiger_crmentity.smownerid',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ->where(['and',

    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();

    Spaces must be used to indent lines; tabs are not allowed
    Open

        public function process()

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $dateStart = $row['date_start'];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $dBFomatedDate = DateTimeField::convertToDBFormat($userFormatedString);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $timeFormatedString = $date->getDisplayTime();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                    'template' => 'ActivityReminderNotificationInvitation',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vtiger_activity.activityid',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                'vtiger_activity_reminder.reminder_time'

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $date = new DateTimeField(null);

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    if (($differenceOfActivityTimeAndCurrentTime > 0) && (($differenceOfActivityTimeAndCurrentTime <= $reminderTime) || ($differenceOfActivityTimeAndCurrentTime <= $reminderFrequency))) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                    'recordId' => $activityId,

    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();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $activityId = $row['activityid'];

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $userFormatedString = $date->getDisplayDate();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        foreach ($invitees as &$invitation) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                \App\Mailer::sendFromTemplate([

    Spaces must be used to indent lines; tabs are not allowed
    Open

                while ($row = $dataReader->read()) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $userFormatedString = $date->getDisplayDate();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        \App\Log::trace('Start Send SendReminder');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        if (App\Config::module('Calendar', 'SEND_REMINDER_INVITATION')) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                'template' => 'ActivityReminderNotificationTask',

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $timeFormatedString = $date->getDisplayTime();

    Line exceeds 120 characters; contains 199 characters
    Open

                    if (($differenceOfActivityTimeAndCurrentTime > 0) && (($differenceOfActivityTimeAndCurrentTime <= $reminderTime) || ($differenceOfActivityTimeAndCurrentTime <= $reminderFrequency))) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            \App\Mailer::sendFromTemplate([

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ->innerJoin('vtiger_crmentity', 'vtiger_crmentity.crmid=vtiger_activity.activityid')

    Spaces must be used to indent lines; tabs are not allowed
    Open

                //To fetch reminder frequency from cron tasks

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $recordModel = Vtiger_Record_Model::getCleanInstance('Calendar');

    Spaces must be used to indent lines; tabs are not allowed
    Open

                ->innerJoin('vtiger_activity_reminder', 'vtiger_activity.activityid = vtiger_activity_reminder.activity_id')

    Spaces must be used to indent lines; tabs are not allowed
    Open

                $dbCommand = App\Db::getInstance()->createCommand();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    $currTime = strtotime("$dBFomatedDate $timeFormatedString");

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        if (!empty($toEmail)) {

    Line exceeds 120 characters; contains 138 characters
    Open

                            $dbCommand->update('vtiger_activity_reminder', ['reminder_sent' => 1], ['activity_id' => $activityId])->execute();

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                            if (!empty($invitation['email'])) {

    Spaces must be used to indent lines; tabs are not allowed
    Open

                                    'to' => $invitation['email'],

    Spaces must be used to indent lines; tabs are not allowed
    Open

                }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                    }

    Spaces must be used to indent lines; tabs are not allowed
    Open

        }

    Spaces must be used to indent lines; tabs are not allowed
    Open

            }

    Spaces must be used to indent lines; tabs are not allowed
    Open

                        \App\Log::trace('End Send SendReminder');

    Class name "Calendar_SendReminder_Cron" is not in camel caps format
    Open

    class Calendar_SendReminder_Cron extends \App\CronHandler

    There are no issues that match your filters.

    Category
    Status