YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/inventoryfields/Currency.php

Summary

Maintainability
A
25 mins
Test Coverage
F
45%

The method Vtiger_Currency_InventoryField::validate() calls the typical debug function print_r() which is mostly only used during development.
Open

            throw new \App\Exceptions\Security("ERR_VALUE_IS_TOO_LONG||$columnName||" . print_r($value, true), 406);

DevelopmentCodeFragment

Since: 2.3.0

Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.

Example

class SuspectCode {

    public function doSomething(array $items)
    {
        foreach ($items as $i => $item) {
            // …

            if ('qafoo' == $item) var_dump($i);

            // …
        }
    }
}

Source https://phpmd.org/rules/design.html#developmentcodefragment

The method Vtiger_Currency_InventoryField::validate() calls the typical debug function print_r() which is mostly only used during development.
Open

                throw new \App\Exceptions\Security("ERR_ILLEGAL_FIELD_VALUE||$columnName||" . print_r($value, true), 406);

DevelopmentCodeFragment

Since: 2.3.0

Functions like vardump(), printr() etc. are normally only used during development and therefore such calls in production code are a good indicator that they were just forgotten.

Example

class SuspectCode {

    public function doSomething(array $items)
    {
        foreach ($items as $i => $item) {
            // …

            if ('qafoo' == $item) var_dump($i);

            // …
        }
    }
}

Source https://phpmd.org/rules/design.html#developmentcodefragment

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

    public function validate($value, string $columnName, bool $isUserFormat, $originalValue = null)
    {
        if ($columnName === $this->getColumnName()) {
            if (!is_numeric($value) || !isset(\App\Fields\Currency::getAll()[$value])) {
                throw new \App\Exceptions\Security("ERR_ILLEGAL_FIELD_VALUE||$columnName||" . print_r($value, true), 406);
Severity: Minor
Found in modules/Vtiger/inventoryfields/Currency.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 '85', column '15').
Open

                throw new \App\Exceptions\Security("ERR_ILLEGAL_FIELD_VALUE||$columnName||" . print_r($value, true), 406);

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 '88', column '14').
Open

            throw new \App\Exceptions\Security("ERR_VALUE_IS_TOO_LONG||$columnName||" . print_r($value, true), 406);

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($value, array $rowData = [], bool $rawText = false)

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 'getDisplayValue'.
Open

}

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\TextUtils' in method 'validate'.
Open

        } elseif (!\is_array($value) && \App\TextUtils::getTextLength($value) > $this->customMaximumLength[$columnName]) {

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 'validate'.
Open

}

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 'vtlib\Functions' in method 'getCurrencyParam'.
Open

                $params[$currency['id']] = vtlib\Functions::getConversionRateInfo($currency['id']);

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\Json' in method 'getCurrencyParam'.
Open

            $params = \App\Json::decode($param);

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 "currencyparam" 3 times.
Open

        'currencyparam' => [\yii\db\Schema::TYPE_STRING, 1024],

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.

Reference to constant TYPE_STRING from undeclared class \yii\db\Schema (Did you mean class \App\Db\Drivers\Mysql\Schema or class \App\Db\Drivers\Pgsql\Schema)
Open

        'currencyparam' => [\yii\db\Schema::TYPE_STRING, 1024],

Reference to constant TYPE_INTEGER from undeclared class \yii\db\Schema (Did you mean class \App\Db\Drivers\Mysql\Schema or class \App\Db\Drivers\Pgsql\Schema)
Open

    protected $dbType = [\yii\db\Schema::TYPE_INTEGER, 11];

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

class Vtiger_Currency_InventoryField extends Vtiger_Basic_InventoryField

The class Vtiger_Currency_InventoryField is not named in CamelCase.
Open

class Vtiger_Currency_InventoryField extends Vtiger_Basic_InventoryField
{
    protected $type = 'Currency';
    protected $defaultLabel = 'LBL_CURRENCY';
    protected $columnName = 'currency';

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

     * Gets currency param.

Line exceeds 120 characters; contains 122 characters
Open

        } elseif (!\is_array($value) && \App\TextUtils::getTextLength($value) > $this->customMaximumLength[$columnName]) {

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

    protected $customColumn = [

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

    protected $purifyType = \App\Purifier::INTEGER;

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

            return '';

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 $params;

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

        } elseif (!\is_array($value) && \App\TextUtils::getTextLength($value) > $this->customMaximumLength[$columnName]) {

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

        'currencyparam' => [\yii\db\Schema::TYPE_STRING, 1024],

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

    protected $blocks = [0];

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

    protected $customPurifyType = [

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

        'currencyparam' => App\Purifier::TEXT

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

        return 'inventoryTypes/Currency.tpl';

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

        $params = [];

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

        if ($param) {

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

    {

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

    protected $maximumLength = '-2147483648,2147483647';

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

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

        }

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

    protected $type = 'Currency';

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

    protected $dbType = [\yii\db\Schema::TYPE_INTEGER, 11];

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

    protected $defaultLabel = 'LBL_CURRENCY';

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

    protected $customMaximumLength = [

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

            throw new \App\Exceptions\Security("ERR_VALUE_IS_TOO_LONG||$columnName||" . print_r($value, true), 406);

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

    public function getDisplayValue($value, array $rowData = [], bool $rawText = false)

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

     * @throws \App\Exceptions\AppException

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

            $params = \App\Json::decode($param);

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

            if (!isset($params[$currency['id']])) {

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

            $value = (int) $value;

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

    protected $columnName = 'currency';

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

     * @param array  $currencies

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

                $params[$currency['id']] = vtlib\Functions::getConversionRateInfo($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

    }

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

    public function getDBValue($value, ?string $name = '')

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

        if ($name === $this->getColumnName()) {

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

                throw new \App\Exceptions\Security("ERR_ILLEGAL_FIELD_VALUE||$columnName||" . print_r($value, true), 406);

Line exceeds 120 characters; contains 122 characters
Open

                throw new \App\Exceptions\Security("ERR_ILLEGAL_FIELD_VALUE||$columnName||" . print_r($value, true), 406);

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 validate($value, string $columnName, bool $isUserFormat, $originalValue = null)

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 ($currencies as $currency) {

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

    /** {@inheritdoc} */

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

        if ($columnName === $this->getColumnName()) {

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 (empty($value)) {

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

    public function getCurrencyParam(array $currencies, $param = '')

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

        'currencyparam' => 1024

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

        return \App\Fields\Currency::getById($value)['currency_name'];

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 $value;

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

            if (!is_numeric($value) || !isset(\App\Fields\Currency::getAll()[$value])) {

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

     * @return array

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

    public function getEditTemplateName()

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

            }

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

class Vtiger_Currency_InventoryField extends Vtiger_Basic_InventoryField

There are no issues that match your filters.

Category
Status