YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
0 mins
Test Coverage
F
34%

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

        $isExists = (new \App\Db\Query())->from('vtiger_pricebookproductrel')->where(['pricebookid' => $this->getId(), 'productid' => $relatedRecordId])->exists();
Severity: Minor
Found in modules/PriceBooks/models/Record.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 '25', column '15').
Open

        return (new \App\Db\Query())->select(['listprice'])
Severity: Minor
Found in modules/PriceBooks/models/Record.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 '67', column '22').
Open

        $dataReader = (new App\Db\Query())->from('vtiger_pricebookproductrel')
Severity: Minor
Found in modules/PriceBooks/models/Record.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\Log' in method 'updateListPrices'.
Open

        \App\Log::trace('Exiting function updateListPrices...');
Severity: Minor
Found in modules/PriceBooks/models/Record.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 '\App\Log' in method 'updateListPrices'.
Open

        \App\Log::trace('Entering function updateListPrices...');
Severity: Minor
Found in modules/PriceBooks/models/Record.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 '\App\Fields\Currency' in method 'updateListPrices'.
Open

            $productCurrencyInfo = \App\Fields\Currency::getById($row['usedcurrency']);
Severity: Minor
Found in modules/PriceBooks/models/Record.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 updateListPrice uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $status = App\Db::getInstance()->createCommand()
                ->insert('vtiger_pricebookproductrel', [
                    'pricebookid' => $this->getId(),
                    'productid' => $relatedRecordId,
Severity: Minor
Found in modules/PriceBooks/models/Record.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 '\App\Fields\Currency' in method 'updateListPrices'.
Open

            $pricebookCurrencyInfo = \App\Fields\Currency::getById($pricebookCurrency);
Severity: Minor
Found in modules/PriceBooks/models/Record.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 "usedcurrency" 4 times.
Open

                    'usedcurrency' => $this->get('currency_id'),
Severity: Critical
Found in modules/PriceBooks/models/Record.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 "listprice" 4 times.
Open

        return (new \App\Db\Query())->select(['listprice'])
Severity: Critical
Found in modules/PriceBooks/models/Record.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_pricebookproductrel" 6 times.
Open

            ->from('vtiger_pricebookproductrel')
Severity: Critical
Found in modules/PriceBooks/models/Record.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 "productid" 6 times.
Open

            ->where(['pricebookid' => $this->getId(), 'productid' => $relatedRecordId])
Severity: Critical
Found in modules/PriceBooks/models/Record.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 "pricebookid" 6 times.
Open

            ->where(['pricebookid' => $this->getId(), 'productid' => $relatedRecordId])
Severity: Critical
Found in modules/PriceBooks/models/Record.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::createCommand
Open

            $status = App\Db::getInstance()->createCommand()
Severity: Critical
Found in modules/PriceBooks/models/Record.php by phan

Doc-block of $name in updateListPrice contains phpdoc param type mixed which is incompatible with the param type string declared in the signature
Open

     * @param mixed $name
Severity: Minor
Found in modules/PriceBooks/models/Record.php by phan

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

            $status = App\Db::getInstance()->createCommand()
Severity: Critical
Found in modules/PriceBooks/models/Record.php by phan

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

        \App\Log::trace('Exiting function updateListPrices...');
Severity: Critical
Found in modules/PriceBooks/models/Record.php by phan

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

        return (new \App\Db\Query())->select(['listprice'])
Severity: Critical
Found in modules/PriceBooks/models/Record.php by phan

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

        $isExists = (new \App\Db\Query())->from('vtiger_pricebookproductrel')->where(['pricebookid' => $this->getId(), 'productid' => $relatedRecordId])->exists();
Severity: Critical
Found in modules/PriceBooks/models/Record.php by phan

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

            App\Db::getInstance()->createCommand()
Severity: Critical
Found in modules/PriceBooks/models/Record.php by phan

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

        $dataReader = (new App\Db\Query())->from('vtiger_pricebookproductrel')
Severity: Critical
Found in modules/PriceBooks/models/Record.php by phan

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

        \App\Log::trace('Entering function updateListPrices...');
Severity: Critical
Found in modules/PriceBooks/models/Record.php by phan

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

            $pricebookCurrencyInfo = \App\Fields\Currency::getById($pricebookCurrency);
Severity: Minor
Found in modules/PriceBooks/models/Record.php by phpmd

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 PriceBooks_Record_Model extends Vtiger_Record_Model

The class PriceBooks_Record_Model is not named in CamelCase.
Open

class PriceBooks_Record_Model extends Vtiger_Record_Model
{
    /**
     * Function returns the List Price for PriceBook-Product/Service relation.
     *
Severity: Minor
Found in modules/PriceBooks/models/Record.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

     * Function returns the List Price for PriceBook-Product/Service relation.

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

     * @param int   $relatedRecordId - Product/Service Id

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

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

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

        $dataReader = (new App\Db\Query())->from('vtiger_pricebookproductrel')

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

            $computedListPrice = $row['listprice'] * $pricebookCurrencyInfo['conversion_rate'] / $productCurrencyInfo['conversion_rate'];

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

     * @param int $relatedRecordId - Product/Service Id

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

            ->from('vtiger_pricebookproductrel')

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

            ->where(['pricebookid' => $this->getId(), 'productid' => $relatedRecordId])

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

        } else {

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

     * @return false|string|null

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

        $isExists = (new \App\Db\Query())->from('vtiger_pricebookproductrel')->where(['pricebookid' => $this->getId(), 'productid' => $relatedRecordId])->exists();

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

                ->update('vtiger_pricebookproductrel', [$name => $value], ['pricebookid' => $this->getId(), 'productid' => $relatedRecordId])

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

                    'usedcurrency' => $this->get('currency_id'),

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

        return $status;

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(['and', ['pricebookid' => $this->getId()], ['<>', 'usedcurrency', $pricebookCurrency]])

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

            $pricebookCurrencyInfo = \App\Fields\Currency::getById($pricebookCurrency);

Line exceeds 120 characters; contains 198 characters
Open

                ->update('vtiger_pricebookproductrel', ['listprice' => $computedListPrice, 'usedcurrency' => $pricebookCurrency], ['pricebookid' => $this->getId(), 'productid' => $row['productid']])

Line exceeds 120 characters; contains 163 characters
Open

        $isExists = (new \App\Db\Query())->from('vtiger_pricebookproductrel')->where(['pricebookid' => $this->getId(), 'productid' => $relatedRecordId])->exists();

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

                ])->execute();

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

        parent::saveToDb();

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

        \App\Log::trace('Entering function updateListPrices...');

Line exceeds 120 characters; contains 137 characters
Open

            $computedListPrice = $row['listprice'] * $pricebookCurrencyInfo['conversion_rate'] / $productCurrencyInfo['conversion_rate'];

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('Exiting function updateListPrices...');

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

        if ($isExists) {

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

                ->update('vtiger_pricebookproductrel', ['listprice' => $computedListPrice, 'usedcurrency' => $pricebookCurrency], ['pricebookid' => $this->getId(), 'productid' => $row['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

     *

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

                ->insert('vtiger_pricebookproductrel', [

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

        $pricebookCurrency = $this->get('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

    public function saveToDb()

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

    public function getProductsListPrice($relatedRecordId)

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\Db::getInstance()->createCommand()

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

    {

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

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

     * @param mixed $name

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

                ->execute();

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

                    'productid' => $relatedRecordId,

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

     * @param mixed $value           - listprice

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

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

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

    public function updateListPrice(int $relatedRecordId, $value, string $name = 'listprice')

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

    {

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

                    'pricebookid' => $this->getId(),

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

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

            $productCurrencyInfo = \App\Fields\Currency::getById($row['usedcurrency']);

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

        return (new \App\Db\Query())->select(['listprice'])

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

            ->scalar();

Line exceeds 120 characters; contains 141 characters
Open

                ->update('vtiger_pricebookproductrel', [$name => $value], ['pricebookid' => $this->getId(), 'productid' => $relatedRecordId])

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

                    $name => $value,

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

     * Function updates ListPrice for PriceBook-Product/Service relation.

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

    {

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

        $this->updateListPrices();

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

    /**

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

class PriceBooks_Record_Model extends Vtiger_Record_Model

There are no issues that match your filters.

Category
Status