YetiForceCompany/YetiForceCRM

View on GitHub
modules/Settings/Inventory/models/Module.php

Summary

Maintainability
A
0 mins
Test Coverage
F
0%

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

        \App\Log::trace('Start ' . __METHOD__ . ' | Type: ' . print_r($type, true) . ' | Name: ' . print_r($name, true));

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 Settings_Inventory_Module_Model::getConfig() calls the typical debug function print_r() which is mostly only used during development.
Open

        \App\Log::trace('Start ' . __METHOD__ . ' | Type: ' . print_r($type, true) . ' | Name: ' . print_r($name, true));

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 getConfig has a boolean flag argument $name, which is a certain sign of a Single Responsibility Principle violation.
Open

    public static function getConfig($type, $name = 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

Missing class import via use statement (line '37', column '17').
Open

        $query = (new \App\Db\Query())->from($tableName);

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

        \App\Log::trace('Start ' . __METHOD__ . ' | Type: ' . print_r($type, true) . ' | Name: ' . print_r($name, true));

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

        \App\Log::trace('Start ' . __METHOD__);

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\Cache' in method 'setConfig'.
Open

        \App\Cache::delete('Inventory', $type);

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

        \App\Log::trace('End ' . __METHOD__);

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

        \App\Log::trace('End ' . __METHOD__);

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

            $output[$row['param']] = $row['value'];

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 "param" 4 times.
Open

            $query->where(['param' => $name]);

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 method trace from undeclared class \App\Log
Open

        \App\Log::trace('End ' . __METHOD__);

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

        $query = (new \App\Db\Query())->from($tableName);

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

        \App\Db::getInstance()->createCommand()

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

        \App\Log::trace('Start ' . __METHOD__);

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

        \App\Log::trace('Start ' . __METHOD__ . ' | Type: ' . print_r($type, true) . ' | Name: ' . print_r($name, true));

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

        \App\Log::trace('End ' . __METHOD__);

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

class Settings_Inventory_Module_Model extends \App\Base

The class Settings_Inventory_Module_Model is not named in CamelCase.
Open

class Settings_Inventory_Module_Model extends \App\Base
{
    public static $picklist = [
        'aggregation' => ['LBL_CANNOT_BE_COMBINED', 'LBL_IN_TOTAL', 'LBL_CASCADE'],
        'discounts' => ['LBL_GLOBAL', 'LBL_GROUP', 'LBL_INDIVIDUAL', 'LBL_ADDITIONAL'],

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

        'discounts' => ['LBL_GLOBAL', 'LBL_GROUP', 'LBL_INDIVIDUAL', 'LBL_ADDITIONAL'],

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

    private static $tablename = ['DiscountConfiguration' => 'a_#__discounts_config', 'TaxConfiguration' => 'a_#__taxes_config'];

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

        $output = [];

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

        'taxs' => ['LBL_GLOBAL', 'LBL_GROUP', 'LBL_INDIVIDUAL', 'LBL_REGIONAL'],

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

        \App\Log::trace('End ' . __METHOD__);

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

        $dataReader->close();

Line exceeds 120 characters; contains 128 characters
Open

    private static $tablename = ['DiscountConfiguration' => 'a_#__discounts_config', 'TaxConfiguration' => 'a_#__taxes_config'];

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

     * @param array  $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

     * @return bool

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

        return self::$picklist[$type];

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

    {

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

        $dataReader = $query->createCommand()->query();

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

     * @param string $type

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

    public static function getCleanInstance()

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

    {

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

            $query->where(['param' => $name]);

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

        return new self();

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

    public static function getPicklistValues($type)

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

        'aggregation' => ['LBL_CANNOT_BE_COMBINED', 'LBL_IN_TOTAL', 'LBL_CASCADE'],

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 static::$tablename[$type];

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

        $tableName = self::getTableNameFromType($type);

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 static function getConfig($type, $name = false)

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

        $query = (new \App\Db\Query())->from($tableName);

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

        return $output;

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

    public static $picklist = [

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

    }

Line exceeds 120 characters; contains 121 characters
Open

        \App\Log::trace('Start ' . __METHOD__ . ' | Type: ' . print_r($type, true) . ' | Name: ' . print_r($name, true));

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

            $name = [$name];

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

     *

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

    public static function getTableNameFromType($type)

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

        if ($name && !\is_array($name)) {

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

            $output[$row['param']] = $row['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

        \App\Log::trace('Start ' . __METHOD__ . ' | Type: ' . print_r($type, true) . ' | Name: ' . print_r($name, true));

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('Start ' . __METHOD__);

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

        \App\Cache::delete('Inventory', $type);

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

        return true;

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

     * Function saves configuration data to database.

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

        $tableName = self::getTableNameFromType($type);

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 setConfig($type, $param)

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

            ->update($tableName, ['value' => $param['value']], ['param' => $param['param']])

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

        \App\Log::trace('End ' . __METHOD__);

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

    }

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

class Settings_Inventory_Module_Model extends \App\Base

There are no issues that match your filters.

Category
Status