YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
25 mins
Test Coverage
F
9%

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

    public function getQueryByModuleField($sourceModule, $field, $record, App\QueryGenerator $queryGenerator)
    {
        if ('Products' === $sourceModule || 'Services' === $sourceModule) {
            $queryGenerator->setCustomColumn('vtiger_pricebookproductrel.listprice');
            $queryGenerator->addJoin(['LEFT JOIN', 'vtiger_pricebookproductrel', 'vtiger_pricebook.pricebookid = vtiger_pricebookproductrel.pricebookid']);
Severity: Minor
Found in modules/PriceBooks/models/Module.php - About 25 mins 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

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

                $subQuery = (new \App\Db\Query())->select(['pricebookid'])->from('vtiger_pricebookproductrel')->where(['productid' => $record]);
Severity: Minor
Found in modules/PriceBooks/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 getModalRecordsListFields has a boolean flag argument $sourceModule, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getModalRecordsListFields(App\QueryGenerator $queryGenerator, $sourceModule = false)
Severity: Minor
Found in modules/PriceBooks/models/Module.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

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

Avoid using static access to class '\App\Fields\Currency' in method 'getQueryByModuleField'.
Open

}
Severity: Minor
Found in modules/PriceBooks/models/Module.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

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(['pricebookid'])->from('vtiger_pricebookproductrel')->where(['productid' => $record]);
                $queryGenerator->addNativeCondition(['not in', 'vtiger_pricebookproductrel.pricebookid', $subQuery]);
            }
Severity: Minor
Found in modules/PriceBooks/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

Avoid using static access to class 'Vtiger_Field_Model' in method 'getModalRecordsListFields'.
Open

            $fieldModel = Vtiger_Field_Model::getInstance('currency_id', $this);
Severity: Minor
Found in modules/PriceBooks/models/Module.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 "currency_id" 4 times.
Open

            $queryGenerator->addCondition('currency_id', \App\Fields\Currency::getDefault()['id'], 'e');
Severity: Critical
Found in modules/PriceBooks/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.

Avoid unused parameters such as '$field'.
Open

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

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

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

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

                $queryGenerator->setField('currency_id');
Severity: Critical
Found in modules/PriceBooks/models/Module.php by phan

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

            $queryGenerator->addCondition('currency_id', \App\Fields\Currency::getDefault()['id'], 'e');
Severity: Critical
Found in modules/PriceBooks/models/Module.php by phan

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

            $queryGenerator->addJoin(['LEFT JOIN', 'vtiger_pricebookproductrel', 'vtiger_pricebook.pricebookid = vtiger_pricebookproductrel.pricebookid']);
Severity: Critical
Found in modules/PriceBooks/models/Module.php by phan

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

                $queryGenerator->addNativeCondition(['not in', 'vtiger_pricebookproductrel.pricebookid', $subQuery]);
Severity: Critical
Found in modules/PriceBooks/models/Module.php by phan

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

                $queryGenerator->addNativeCondition(['and',
Severity: Critical
Found in modules/PriceBooks/models/Module.php by phan

Reference to instance property currencyId from undeclared class \App\QueryGenerator
Open

                    ['vtiger_pricebook.currency_id' => $queryGenerator->currencyId],
Severity: Minor
Found in modules/PriceBooks/models/Module.php by phan

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

    public function getModalRecordsListFields(App\QueryGenerator $queryGenerator, $sourceModule = false)
Severity: Minor
Found in modules/PriceBooks/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/PriceBooks/models/Module.php by phan

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

            $queryGenerator->setCustomColumn('vtiger_pricebookproductrel.listprice');
Severity: Critical
Found in modules/PriceBooks/models/Module.php by phan

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

                $subQuery = (new \App\Db\Query())->select(['pricebookid'])->from('vtiger_pricebookproductrel')->where(['productid' => $record]);
Severity: Critical
Found in modules/PriceBooks/models/Module.php by phan

Reference to instance property currencyId from undeclared class \App\QueryGenerator
Open

            if (isset($queryGenerator->currencyId)) {
Severity: Minor
Found in modules/PriceBooks/models/Module.php by phan

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

class PriceBooks_Module_Model extends Vtiger_Module_Model

The class PriceBooks_Module_Model is not named in CamelCase.
Open

class PriceBooks_Module_Model extends Vtiger_Module_Model
{
    /**
     * Function to get list view query for popup window.
     *
Severity: Minor
Found in modules/PriceBooks/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

     * @param string              $sourceModule   Parent module

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

                    ['vtiger_pricebook.currency_id' => $queryGenerator->currencyId],

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

    }

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

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

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

    }

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

    public function isSummaryViewSupported()

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

        return false;

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

            $fieldModel = Vtiger_Field_Model::getInstance('currency_id', $this);

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

            if (isset($queryGenerator->currencyId)) {

Line exceeds 120 characters; contains 144 characters
Open

                $subQuery = (new \App\Db\Query())->select(['pricebookid'])->from('vtiger_pricebookproductrel')->where(['productid' => $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

        $popupFields = parent::getModalRecordsListFields($queryGenerator, $sourceModule);

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

     */

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

            if ($fieldModel->getPermissions()) {

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

                $queryGenerator->setField('currency_id');

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

        return $popupFields;

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

                $queryGenerator->addNativeCondition(['and',

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_pricebook.active' => 1],

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

    public function getModalRecordsListFields(App\QueryGenerator $queryGenerator, $sourceModule = false)

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              $record         parent id

Line exceeds 120 characters; contains 155 characters
Open

            $queryGenerator->addJoin(['LEFT JOIN', 'vtiger_pricebookproductrel', 'vtiger_pricebook.pricebookid = vtiger_pricebookproductrel.pricebookid']);

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

                $subQuery = (new \App\Db\Query())->select(['pricebookid'])->from('vtiger_pricebookproductrel')->where(['productid' => $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

        }

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

                $queryGenerator->addNativeCondition(['not in', 'vtiger_pricebookproductrel.pricebookid', $subQuery]);

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

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

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

            $queryGenerator->addCondition('currency_id', \App\Fields\Currency::getDefault()['id'], 'e');

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

     * Function to check whether the module is summary view supported.

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

            $queryGenerator->setCustomColumn('vtiger_pricebookproductrel.listprice');

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

                    ['vtiger_pricebookproductrel.productid' => $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

     * @return bool

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(['LEFT JOIN', 'vtiger_pricebookproductrel', 'vtiger_pricebook.pricebookid = vtiger_pricebookproductrel.pricebookid']);

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 ('Products' === $sourceModule || 'Services' === $sourceModule) {

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

        if (!isset($popupFields['currency_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

            }

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

class PriceBooks_Module_Model extends Vtiger_Module_Model

There are no issues that match your filters.

Category
Status