YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
C
7 hrs
Test Coverage
F
25%

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

    public function process()
    {
        $dbCommand = App\Db::getInstance()->createCommand();
        $scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
        $dataReader = (new App\Db\Query())->select([
Severity: Minor
Found in modules/OSSMailScanner/crons/Bind.php - About 4 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 66 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process()
    {
        $dbCommand = App\Db::getInstance()->createCommand();
        $scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
        $dataReader = (new App\Db\Query())->select([
Severity: Major
Found in modules/OSSMailScanner/crons/Bind.php - About 2 hrs to fix

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

        public function process()
        {
            $dbCommand = App\Db::getInstance()->createCommand();
            $scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
            $dataReader = (new App\Db\Query())->select([
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    NPathComplexity

    Since: 0.1

    The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

    Example

    class Foo {
        function bar() {
            // lots of complicated code
        }
    }

    Source https://phpmd.org/rules/codesize.html#npathcomplexity

    The method process() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10.
    Open

        public function process()
        {
            $dbCommand = App\Db::getInstance()->createCommand();
            $scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
            $dataReader = (new App\Db\Query())->select([
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    CyclomaticComplexity

    Since: 0.1

    Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

    Example

    // Cyclomatic Complexity = 11
    class Foo {
    1   public function example() {
    2       if ($a == $b) {
    3           if ($a1 == $b1) {
                    fiddle();
    4           } elseif ($a2 == $b2) {
                    fiddle();
                } else {
                    fiddle();
                }
    5       } elseif ($c == $d) {
    6           while ($c == $d) {
                    fiddle();
                }
    7        } elseif ($e == $f) {
    8           for ($n = 0; $n < $h; $n++) {
                    fiddle();
                }
            } else {
                switch ($z) {
    9               case 1:
                        fiddle();
                        break;
    10              case 2:
                        fiddle();
                        break;
    11              case 3:
                        fiddle();
                        break;
                    default:
                        fiddle();
                        break;
                }
            }
        }
    }

    Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

    Refactor this function to reduce its Cognitive Complexity from 29 to the 15 allowed.
    Open

        public function process()
    Severity: Critical
    Found in modules/OSSMailScanner/crons/Bind.php by sonar-php

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

    Missing class import via use statement (line '34', column '22').
    Open

            $dataReader = (new App\Db\Query())->from('s_#__mail_relation_updater')->createCommand()->query();
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '22', column '22').
    Open

            $dataReader = (new App\Db\Query())->select([
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Missing class import via use statement (line '72', column '28').
    Open

                    $dataReaderMail = (new App\Db\Query())->select(['vtiger_ossmailview.*', 'roundcube_users.actions'])
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Avoid using static access to class '\App\Module' in method 'process'.
    Open

                $moduleName = \App\Module::getModuleName($relationRow['tabid']);
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class 'Vtiger_Record_Model' in method 'process'.
    Open

                $recordModel = Vtiger_Record_Model::getInstanceById($relationRow['crmid'], $moduleName);
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class 'Vtiger_Record_Model' in method 'process'.
    Open

            $scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Define a constant instead of duplicating this literal "vtiger_ossmailview" 3 times.
    Open

            ])->from('vtiger_ossmailview')
    Severity: Critical
    Found in modules/OSSMailScanner/crons/Bind.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "email" 3 times.
    Open

                    $bind = 'email';
    Severity: Critical
    Found in modules/OSSMailScanner/crons/Bind.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Define a constant instead of duplicating this literal "crmid" 5 times.
    Open

                $dbCommand->delete('vtiger_ossmailview_relation', ['crmid' => $relationRow['crmid']])->execute();
    Severity: Critical
    Found in modules/OSSMailScanner/crons/Bind.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Avoid unused local variables such as '$fieldModel'.
    Open

                    foreach ($fieldModels as $fieldName => $fieldModel) {
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

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

            $dbCommand = App\Db::getInstance()->createCommand();
    Severity: Critical
    Found in modules/OSSMailScanner/crons/Bind.php by phan

    Call to undeclared method \Vtiger_Record_Model::bindMail
    Open

                $scannerModel->bindMail($row);
    Severity: Critical
    Found in modules/OSSMailScanner/crons/Bind.php by phan

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

                    $dataReaderMail = (new App\Db\Query())->select(['vtiger_ossmailview.*', 'roundcube_users.actions'])
    Severity: Critical
    Found in modules/OSSMailScanner/crons/Bind.php by phan

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

            $dataReader = (new App\Db\Query())->from('s_#__mail_relation_updater')->createCommand()->query();
    Severity: Critical
    Found in modules/OSSMailScanner/crons/Bind.php by phan

    Call to undeclared method \Vtiger_Record_Model::bindMail
    Open

                        $scannerModel->bindMail($row);
    Severity: Critical
    Found in modules/OSSMailScanner/crons/Bind.php by phan

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

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

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

    class OSSMailScanner_Bind_Cron extends \App\CronHandler

    The class OSSMailScanner_Bind_Cron is not named in CamelCase.
    Open

    class OSSMailScanner_Bind_Cron extends \App\CronHandler
    {
        /** {@inheritdoc} */
        public function process()
        {
    Severity: Minor
    Found in modules/OSSMailScanner/crons/Bind.php by phpmd

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

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

        public function process()

    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

                $dbCommand->update('vtiger_ossmailview', ['verify' => 0], ['ossmailviewid' => $row['ossmailviewid']])->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

                    }

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

                $where = [];

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

                    foreach ($fieldModels as $fieldName => $fieldModel) {

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

                        $scannerModel->bindMail($row);

    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

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

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

                'vtiger_ossmailview.*',

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

                ->innerJoin('roundcube_users', 'roundcube_users.user_id = vtiger_ossmailview.rc_user')->where(['vtiger_ossmailview.verify' => 1])

    Line exceeds 120 characters; contains 125 characters
    Open

                $dbCommand->update('vtiger_ossmailview', ['verify' => 0], ['ossmailviewid' => $row['ossmailviewid']])->execute();

    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

            $bindByEmail = ['Leads', 'Accounts', 'Partners', 'Vendors', 'Competition', 'Contacts', 'OSSEmployees'];

    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

            $bindByPrefix = ['Campaigns', 'HelpDesk', 'Project', 'SSalesProcesses'];

    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

                if ('prefix' == $bind) {

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

                            $where[] = ['to_email' => $email];

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

                $dbCommand->delete('s_#__mail_relation_updater', ['crmid' => $relationRow['crmid']])->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

        {

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

            $scannerModel = Vtiger_Record_Model::getCleanInstance('OSSMailScanner');

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

                            $where[] = ['bcc_email' => $email];

    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

            $dataReader = (new App\Db\Query())->from('s_#__mail_relation_updater')->createCommand()->query();

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

                            $where[] = ['cc_email' => $email];

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

                        ->where($where)->createCommand()->query();

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

                'roundcube_users.actions',

    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

                    $bind = '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

                        ->innerJoin('roundcube_users', 'roundcube_users.user_id = vtiger_ossmailview.rc_user')

    Line exceeds 120 characters; contains 141 characters
    Open

                ->innerJoin('roundcube_users', 'roundcube_users.user_id = vtiger_ossmailview.rc_user')->where(['vtiger_ossmailview.verify' => 1])

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

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

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

                $dbCommand->delete('vtiger_ossmailview_relation', ['crmid' => $relationRow['crmid']])->execute();

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

                $bind = false;

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

                    $fieldModels = $recordModel->getModule()->getFieldsByType('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

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

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

                    break;

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

            }

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

                $moduleName = \App\Module::getModuleName($relationRow['tabid']);

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

                    }

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

                    $dataReaderMail = (new App\Db\Query())->select(['vtiger_ossmailview.*', 'roundcube_users.actions'])

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

                    $dataReaderMail->close();

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

                if ($this->checkTimeout()) {

    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

                if (!empty($where) && $where !== ['or']) {

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

                $scannerModel->bindMail($row);

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

                $recordModel = Vtiger_Record_Model::getInstanceById($relationRow['crmid'], $moduleName);

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

                    if (empty($recordNumber)) {

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

                    $where = ['like', 'vtiger_ossmailview.subject', "[{$recordNumber}]"];

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

                            $where[] = ['from_email' => $email];

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

                        ->from('vtiger_ossmailview')

    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 (\in_array($moduleName, $bindByEmail)) {

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

                        if (!$recordModel->isEmpty($fieldName)) {

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

                            $email = $recordModel->get($fieldName);

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

                    $bind = 'prefix';

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

                if (false === $bind) {

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

                    $recordNumber = $recordModel->getRecordNumber();

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

                }

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

                    $where = ['or'];

    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 (\in_array($moduleName, $bindByPrefix)) {

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

                }

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

                } elseif ('email' == $bind) {

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

            ])->from('vtiger_ossmailview')

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

                }

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

    class OSSMailScanner_Bind_Cron extends \App\CronHandler

    There are no issues that match your filters.

    Category
    Status