YetiForceCompany/YetiForceCRM

View on GitHub
modules/Contacts/models/Module.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

Function getQueryByModuleField has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
    {
        if ('SRecurringOrders' === $sourceModule && $record) {
            $queryGenerator->addJoin(['INNER JOIN', 'u_#__srecurringorders', 'u_#__srecurringorders.accountid = vtiger_contactdetails.parentid AND u_#__srecurringorders.srecurringordersid = :records', [':records' => $record]]);
        }
Severity: Minor
Found in modules/Contacts/models/Module.php - About 1 hr 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 getQueryByModuleField has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
    {
        if ('SRecurringOrders' === $sourceModule && $record) {
            $queryGenerator->addJoin(['INNER JOIN', 'u_#__srecurringorders', 'u_#__srecurringorders.accountid = vtiger_contactdetails.parentid AND u_#__srecurringorders.srecurringordersid = :records', [':records' => $record]]);
        }
Severity: Minor
Found in modules/Contacts/models/Module.php - About 1 hr to fix

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

        public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
        {
            if ('SRecurringOrders' === $sourceModule && $record) {
                $queryGenerator->addJoin(['INNER JOIN', 'u_#__srecurringorders', 'u_#__srecurringorders.accountid = vtiger_contactdetails.parentid AND u_#__srecurringorders.srecurringordersid = :records', [':records' => $record]]);
            }
    Severity: Minor
    Found in modules/Contacts/models/Module.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

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

                    $subQuery = (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record]);
    Severity: Minor
    Found in modules/Contacts/models/Module.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 '46', column '22').
    Open

                    $subQuery = (new App\Db\Query())
    Severity: Minor
    Found in modules/Contacts/models/Module.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 '50', column '28').
    Open

                    $secondSubQuery = (new App\Db\Query())
    Severity: Minor
    Found in modules/Contacts/models/Module.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

    The method getQueryByModuleField uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                } else {
                    $subQuery = (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record]);
                    $condition = ['not in', 'vtiger_contactdetails.contactid', $subQuery];
                }
    Severity: Minor
    Found in modules/Contacts/models/Module.php by phpmd

    ElseExpression

    Since: 1.4.0

    An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

    Example

    class Foo
    {
        public function bar($flag)
        {
            if ($flag) {
                // one branch
            } else {
                // another branch
            }
        }
    }

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

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

                    $condition = ['and', ['not in', 'vtiger_contactdetails.contactid', $subQuery], ['not in', 'vtiger_contactdetails.contactid', $secondSubQuery]];
    Severity: Critical
    Found in modules/Contacts/models/Module.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" 4 times.
    Open

                        $fieldName = 'crmid';
    Severity: Critical
    Found in modules/Contacts/models/Module.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 "vtiger_contactdetails.contactid" 4 times.
    Open

                    $condition = ['and', ['not in', 'vtiger_contactdetails.contactid', $subQuery], ['not in', 'vtiger_contactdetails.contactid', $secondSubQuery]];
    Severity: Critical
    Found in modules/Contacts/models/Module.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.

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

                    $subQuery = (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record]);
    Severity: Critical
    Found in modules/Contacts/models/Module.php by phan

    Parameter $queryGenerator has undeclared type \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

        public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
    Severity: Minor
    Found in modules/Contacts/models/Module.php by phan

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

                    $subQuery = (new App\Db\Query())
    Severity: Critical
    Found in modules/Contacts/models/Module.php by phan

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

                    $secondSubQuery = (new App\Db\Query())
    Severity: Critical
    Found in modules/Contacts/models/Module.php by phan

    Call to method addJoin from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                $queryGenerator->addJoin(['INNER JOIN', 'u_#__srecurringorders', 'u_#__srecurringorders.accountid = vtiger_contactdetails.parentid AND u_#__srecurringorders.srecurringordersid = :records', [':records' => $record]]);
    Severity: Critical
    Found in modules/Contacts/models/Module.php by phan

    Call to method addNativeCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                $queryGenerator->addNativeCondition($condition);
    Severity: Critical
    Found in modules/Contacts/models/Module.php by phan

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                if ('Services' === $sourceModule) {
                    $subQuery = (new App\Db\Query())
                        ->select(['relcrmid'])
                        ->from('vtiger_crmentityrel')
                        ->where(['crmid' => $record]);
    Severity: Major
    Found in modules/Contacts/models/Module.php and 1 other location - About 1 hr to fix
    modules/Leads/models/Module.php on lines 76..88

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 116.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    class Contacts_Module_Model extends Vtiger_Module_Model

    The class Contacts_Module_Model is not named in CamelCase.
    Open

    class Contacts_Module_Model extends Vtiger_Module_Model
    {
        /** {@inheritdoc} */
        public $allowTypeChange = false;
    
    
    Severity: Minor
    Found in modules/Contacts/models/Module.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

         */

    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

                        ->from('vtiger_crmentityrel')

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

            if ('SRecurringOrders' === $sourceModule && $record) {

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

                        $tableName = 'vtiger_campaign_records';

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

                } else {

    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

         * Function to get list view query for popup window.

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

         * @param string              $sourceModule   Parent module

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

         * @param \App\QueryGenerator $queryGenerator

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

                        $fieldName = 'crmid';

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

                    $condition = ['not in', 'vtiger_contactdetails.contactid', $subQuery];

    Line exceeds 120 characters; contains 227 characters
    Open

                $queryGenerator->addJoin(['INNER JOIN', 'u_#__srecurringorders', 'u_#__srecurringorders.accountid = vtiger_contactdetails.parentid AND u_#__srecurringorders.srecurringordersid = :records', [':records' => $record]]);

    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

                        ->select(['relcrmid'])

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

        public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)

    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

                        ->from('vtiger_crmentityrel')

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

                    $condition = ['<>', 'vtiger_contactdetails.contactid', $record];

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

         *

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

                        $relatedFieldName = 'productid';

    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 ('Contacts' === $sourceModule && 'contact_id' === $field) {

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

                        $fieldName = 'crmid';

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

                    $subQuery = (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record]);

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

            if (\in_array($sourceModule, ['Campaigns', 'Products', 'Services']) || ('Contacts' === $sourceModule && 'contact_id' === $field && $record)) {

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

                    case 'Products':

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

                    $secondSubQuery = (new App\Db\Query())

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

                        $tableName = 'vtiger_seproductsrel';

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

         * @param string              $record         parent id

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

        {

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

                $queryGenerator->addJoin(['INNER JOIN', 'u_#__srecurringorders', 'u_#__srecurringorders.accountid = vtiger_contactdetails.parentid AND u_#__srecurringorders.srecurringordersid = :records', [':records' => $record]]);

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

                if ('Services' === $sourceModule) {

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

        public $allowTypeChange = false;

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

            }

    Line exceeds 120 characters; contains 128 characters
    Open

                    $subQuery = (new App\Db\Query())->select([$fieldName])->from($tableName)->where([$relatedFieldName => $record]);

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

        /**

    Line exceeds 120 characters; contains 150 characters
    Open

            if (\in_array($sourceModule, ['Campaigns', 'Products', 'Services']) || ('Contacts' === $sourceModule && 'contact_id' === $field && $record)) {

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

                switch ($sourceModule) {

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

                    case 'Campaigns':

    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(['crmid' => $record]);

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

                        ->where(['relcrmid' => $record]);

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

         * @param string              $field          parent fieldname

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

                        ->select(['crmid'])

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

                        $relatedFieldName = 'campaignid';

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

                    default:

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

                    $subQuery = (new App\Db\Query())

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

                    $condition = ['and', ['not in', 'vtiger_contactdetails.contactid', $subQuery], ['not in', 'vtiger_contactdetails.contactid', $secondSubQuery]];

    Line exceeds 120 characters; contains 159 characters
    Open

                    $condition = ['and', ['not in', 'vtiger_contactdetails.contactid', $subQuery], ['not in', 'vtiger_contactdetails.contactid', $secondSubQuery]];

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

                $queryGenerator->addNativeCondition($condition);

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

            }

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

        }

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

    class Contacts_Module_Model extends Vtiger_Module_Model

    There are no issues that match your filters.

    Category
    Status