YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSMailScanner/crons/Verification.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
43%

Function process has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    public function process()
    {
        $config = OSSMailScanner_Record_Model::getConfig('cron');
        $duration = $config['time'] ?? 0;
        $email = $config['email'] ?? '';
Severity: Minor
Found in modules/OSSMailScanner/crons/Verification.php - About 2 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 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process()
    {
        $config = OSSMailScanner_Record_Model::getConfig('cron');
        $duration = $config['time'] ?? 0;
        $email = $config['email'] ?? '';
Severity: Minor
Found in modules/OSSMailScanner/crons/Verification.php - About 1 hr to fix

    The method process() has an NPath complexity of 204. The configured NPath complexity threshold is 200.
    Open

        public function process()
        {
            $config = OSSMailScanner_Record_Model::getConfig('cron');
            $duration = $config['time'] ?? 0;
            $email = $config['email'] ?? '';

    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 13. The configured cyclomatic complexity threshold is 10.
    Open

        public function process()
        {
            $config = OSSMailScanner_Record_Model::getConfig('cron');
            $duration = $config['time'] ?? 0;
            $email = $config['email'] ?? '';

    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 16 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 '30', column '13').
    Open

                && !(new \App\Db\Query())->from('vtiger_ossmailscanner_log_cron')->where(['laststart' => $startTime])->exists()) {

    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 '25', column '22').
    Open

            $dataReader = (new App\Db\Query())->from('vtiger_ossmails_logs')->where(['status' => 1])->createCommand()->query();

    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 '45', column '17').
    Open

            $query = (new \App\Db\Query())->from('roundcube_users')->where(['crm_status' => \OSSMail_Record_Model::MAIL_BOX_STATUS_BLOCKED_TEMP]);

    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 'OSSMailScanner_Record_Model' in method 'process'.
    Open

    }

    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

                    $url = \App\Config::main('site_URL');

    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 'OSSMailScanner_Record_Model' in method 'process'.
    Open

            $config = OSSMailScanner_Record_Model::getConfig('cron');

    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 '\OSSMail_Record_Model' in method 'process'.
    Open

                    \OSSMail_Record_Model::imapConnect($account['username'], \App\Encryption::getInstance()->decrypt($account['password']), $account['mail_host'], '', false, [], $account);

    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

                    $mailStatus = \App\Mailer::addMail([
                        'to' => $email,
                        'subject' => App\Language::translate('Email_FromName', 'OSSMailScanner'),
                        'content' => App\Language::translate('Email_Body', 'OSSMailScanner') . "\r\n<br><a href='{$url}'>{$url}</a>",
                    ]);

    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\Language' in method 'process'.
    Open

                        'subject' => App\Language::translate('Email_FromName', 'OSSMailScanner'),

    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\Language' in method 'process'.
    Open

                        'content' => App\Language::translate('Email_Body', 'OSSMailScanner') . "\r\n<br><a href='{$url}'>{$url}</a>",

    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 "laststart" 3 times.
    Open

                && !(new \App\Db\Query())->from('vtiger_ossmailscanner_log_cron')->where(['laststart' => $startTime])->exists()) {

    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 "status" 3 times.
    Open

            $dataReader = (new App\Db\Query())->from('vtiger_ossmails_logs')->where(['status' => 1])->createCommand()->query();

    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 "vtiger_ossmailscanner_log_cron" 3 times.
    Open

                && !(new \App\Db\Query())->from('vtiger_ossmailscanner_log_cron')->where(['laststart' => $startTime])->exists()) {

    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 getConfig from undeclared class \OSSMailScanner_Record_Model
    Open

            $hours = OSSMailScanner_Record_Model::getConfig('cron')['blockCheckHours'] ?? '';

    Call to method getConfig from undeclared class \OSSMailScanner_Record_Model
    Open

            $config = OSSMailScanner_Record_Model::getConfig('cron');

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

                && !(new \App\Db\Query())->from('vtiger_ossmailscanner_log_cron')->where(['laststart' => $startTime])->exists()) {

    Call to undeclared method \App\Db::createCommand
    Open

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

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

            $query = (new \App\Db\Query())->from('roundcube_users')->where(['crm_status' => \OSSMail_Record_Model::MAIL_BOX_STATUS_BLOCKED_TEMP]);

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

            $dataReader = (new App\Db\Query())->from('vtiger_ossmails_logs')->where(['status' => 1])->createCommand()->query();

    Call to method getInstance from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
    Open

                    \OSSMail_Record_Model::imapConnect($account['username'], \App\Encryption::getInstance()->decrypt($account['password']), $account['mail_host'], '', false, [], $account);

    Each class must be in a namespace of at least one level (a top-level vendor name)
    Open

    class OSSMailScanner_Verification_Cron extends \App\CronHandler

    The class OSSMailScanner_Verification_Cron is not named in CamelCase.
    Open

    class OSSMailScanner_Verification_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

            $dataReader = (new App\Db\Query())->from('vtiger_ossmails_logs')->where(['status' => 1])->createCommand()->query();

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

                && !(new \App\Db\Query())->from('vtiger_ossmailscanner_log_cron')->where(['laststart' => $startTime])->exists()) {

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

                }

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

            $query = (new \App\Db\Query())->from('roundcube_users')->where(['crm_status' => \OSSMail_Record_Model::MAIL_BOX_STATUS_BLOCKED_TEMP]);

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

                    $check = date('Y-m-d G', strtotime($account['failed_login'])) !== date('Y-m-d G');

    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

                    $url = \App\Config::main('site_URL');

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

            $dataReader->close();

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

                    if ($hours && $check) {

    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

                        'content' => App\Language::translate('Email_Body', 'OSSMailScanner') . "\r\n<br><a href='{$url}'>{$url}</a>",

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

                if (empty($account['actions'])) {

    Line exceeds 120 characters; contains 163 characters
    Open

                    $dbCommand->insert('vtiger_ossmailscanner_log_cron', ['laststart' => $startTime, 'status' => 0, 'created_time' => date('Y-m-d H:i:s')])->execute();

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

                    $mailStatus = \App\Mailer::addMail([

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

                    $dbCommand->update('vtiger_ossmailscanner_log_cron', ['status' => (int) $mailStatus], ['laststart' => $startTime])->execute();

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

                    \OSSMail_Record_Model::imapConnect($account['username'], \App\Encryption::getInstance()->decrypt($account['password']), $account['mail_host'], '', false, [], $account);

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

                        'subject' => App\Language::translate('Email_FromName', 'OSSMailScanner'),

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

                && strtotime('now') > $startTime + ($duration * 60)

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

                    $dbCommand->insert('vtiger_ossmailscanner_log_cron', ['laststart' => $startTime, 'status' => 0, 'created_time' => date('Y-m-d H:i:s')])->execute();

    Line exceeds 120 characters; contains 129 characters
    Open

                        'content' => App\Language::translate('Email_Body', 'OSSMailScanner') . "\r\n<br><a href='{$url}'>{$url}</a>",

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

            $config = OSSMailScanner_Record_Model::getConfig('cron');

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

                $startTime = strtotime($row['start_time']);

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

                if ($duration && $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

            $hours = OSSMailScanner_Record_Model::getConfig('cron')['blockCheckHours'] ?? '';

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

                $check = true;

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

            $dataReader->close();

    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

            }

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

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

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

            $email = $config['email'] ?? '';

    Line exceeds 120 characters; contains 123 characters
    Open

            $dataReader = (new App\Db\Query())->from('vtiger_ossmails_logs')->where(['status' => 1])->createCommand()->query();

    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

                if ($check) {

    Line exceeds 120 characters; contains 184 characters
    Open

                    \OSSMail_Record_Model::imapConnect($account['username'], \App\Encryption::getInstance()->decrypt($account['password']), $account['mail_host'], '', false, [], $account);

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

                        $check = \in_array(date('G'), $hours);

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

        /** {@inheritdoc} */

    Line exceeds 120 characters; contains 126 characters
    Open

                && !(new \App\Db\Query())->from('vtiger_ossmailscanner_log_cron')->where(['laststart' => $startTime])->exists()) {

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

                    ]);

    Line exceeds 120 characters; contains 142 characters
    Open

            $query = (new \App\Db\Query())->from('roundcube_users')->where(['crm_status' => \OSSMail_Record_Model::MAIL_BOX_STATUS_BLOCKED_TEMP]);

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

                    continue;

    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

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

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

                        'to' => $email,

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

            $duration = $config['time'] ?? 0;

    Line exceeds 120 characters; contains 142 characters
    Open

                    $dbCommand->update('vtiger_ossmailscanner_log_cron', ['status' => (int) $mailStatus], ['laststart' => $startTime])->execute();

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

            $hours = $hours ? explode(',', $hours) : [];

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

            $dataReader = $query->createCommand()->query();

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

                if (!empty($account['failed_login'])) {

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

    class OSSMailScanner_Verification_Cron extends \App\CronHandler

    There are no issues that match your filters.

    Category
    Status