YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

The method getDisplayValue has a boolean flag argument $length, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getDisplayValue($fieldName, $record = false, $rawText = false, $length = false)
Severity: Minor
Found in modules/IStorages/models/Record.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

The method getDisplayValue has a boolean flag argument $record, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getDisplayValue($fieldName, $record = false, $rawText = false, $length = false)
Severity: Minor
Found in modules/IStorages/models/Record.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

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

        $isExists = (new \App\Db\Query())->from($tableInfo['table'])->where([$tableInfo['rel'] => $this->getId(), $tableInfo['base'] => $relatedRecordId])->exists();
Severity: Minor
Found in modules/IStorages/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

The method getDisplayValue has a boolean flag argument $rawText, which is a certain sign of a Single Responsibility Principle violation.
Open

    public function getDisplayValue($fieldName, $record = false, $rawText = false, $length = false)
Severity: Minor
Found in modules/IStorages/models/Record.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 'CRMEntity' in method 'getHierarchy'.
Open

        $focus = CRMEntity::getInstance($this->getModuleName());
Severity: Minor
Found in modules/IStorages/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 updateQtyProducts 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($tableInfo['table'], [
                    $tableInfo['rel'] => $this->getId(),
                    $tableInfo['base'] => $relatedRecordId,
Severity: Minor
Found in modules/IStorages/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 'Vtiger_Relation_Model' in method 'updateQtyProducts'.
Open

        $tableInfo = Vtiger_Relation_Model::getReferenceTableInfo('IStorages', 'Products');
Severity: Minor
Found in modules/IStorages/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 'Vtiger_Record_Model' in method 'getHierarchy'.
Open

                $recordModel = Vtiger_Record_Model::getCleanInstance('IStorages');
Severity: Minor
Found in modules/IStorages/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 "qtyinstock" 3 times.
Open

        if ('qtyinstock' === $fieldName) {
Severity: Critical
Found in modules/IStorages/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 "table" 3 times.
Open

        $isExists = (new \App\Db\Query())->from($tableInfo['table'])->where([$tableInfo['rel'] => $this->getId(), $tableInfo['base'] => $relatedRecordId])->exists();
Severity: Critical
Found in modules/IStorages/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/IStorages/models/Record.php by phan

Call to undeclared method \CRMEntity::getHierarchy
Open

        $hierarchy = $focus->getHierarchy($this->getId());
Severity: Critical
Found in modules/IStorages/models/Record.php by phan

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

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

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

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

Saw unextractable annotation for comment '* @return <array>'</array>
Open

     * @return <Array>
Severity: Info
Found in modules/IStorages/models/Record.php by phan

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

class IStorages_Record_Model extends Vtiger_Record_Model

The class IStorages_Record_Model is not named in CamelCase.
Open

class IStorages_Record_Model extends Vtiger_Record_Model
{
    /**
     * Function returns the details of IStorages Hierarchy.
     *
Severity: Minor
Found in modules/IStorages/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 details of IStorages Hierarchy.

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

     *

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

        foreach ($hierarchy['entries'] as $storageId => $storageInfo) {

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

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

        return $hierarchy;

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

        if ('qtyinstock' === $fieldName) {

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

                    'qtyinstock' => $qty,

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

                preg_match('/[.\s]+/', $storageInfo[0], $dashes);

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

    }

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

     *

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

    public function updateQtyProducts(int $relatedRecordId, float $qty): bool

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

        $isExists = (new \App\Db\Query())->from($tableInfo['table'])->where([$tableInfo['rel'] => $this->getId(), $tableInfo['base'] => $relatedRecordId])->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

        $focus = CRMEntity::getInstance($this->getModuleName());

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

            if (!empty($matches)) {

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

    public function getDisplayValue($fieldName, $record = false, $rawText = false, $length = false)

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

        return parent::getDisplayValue($fieldName, $record, $rawText, $length);

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

    }

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

     * Function updates number of product in storage.

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

     */

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

        $tableInfo = Vtiger_Relation_Model::getReferenceTableInfo('IStorages', 'Products');

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

                $recordModel->setId($storageId);

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

                $hierarchy['entries'][$storageId][0] = ($dashes[0] ?? '') . '<a href=' . $recordModel->getDetailViewUrl() . '>' . $name[2] . '</a>';

Line exceeds 120 characters; contains 148 characters
Open

                $hierarchy['entries'][$storageId][0] = ($dashes[0] ?? '') . '<a href=' . $recordModel->getDetailViewUrl() . '>' . $name[2] . '</a>';

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

                $recordModel = Vtiger_Record_Model::getCleanInstance('IStorages');

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

            return $this->get($fieldName);

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

        return (bool) $status;

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

                preg_match('/<a(.*)>(.*)<\\/a>/i', $storageInfo[0], $name);

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

     * @param int   $relatedRecordId - Product Id

Line exceeds 120 characters; contains 165 characters
Open

        $isExists = (new \App\Db\Query())->from($tableInfo['table'])->where([$tableInfo['rel'] => $this->getId(), $tableInfo['base'] => $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

    /**

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

    }

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

        $hierarchy = $focus->getHierarchy($this->getId());

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

            preg_match('/<a href="+/', $storageInfo[0], $matches);

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

     * @param float $qty

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

                ->insert($tableInfo['table'], [

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

                    $tableInfo['base'] => $relatedRecordId,

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

                    $tableInfo['rel'] => $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

        }

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

     *

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

                ->update($tableInfo['table'], ['qtyinstock' => $qty], [$tableInfo['rel'] => $this->getId(), $tableInfo['base'] => $relatedRecordId])

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

    public function getHierarchy()

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

     * @return bool

Line exceeds 120 characters; contains 148 characters
Open

                ->update($tableInfo['table'], ['qtyinstock' => $qty], [$tableInfo['rel'] => $this->getId(), $tableInfo['base'] => $relatedRecordId])

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

        // This is special field / displayed only in Products module [view=Detail relatedModule=IStorages]

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

class IStorages_Record_Model extends Vtiger_Record_Model

There are no issues that match your filters.

Category
Status