YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
0 mins
Test Coverage
A
95%

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

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

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 '52', column '13').
Open

            if ((new \App\Db\Query())->select('type', 'name')

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

        \App\Cache::delete('AddressFinder', 'Config');

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

        $db = \App\Db::getInstance();

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 setConfig uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $result = $db->createCommand()->insert($this->baseTable, ['val' => $val, 'type' => $type, 'name' => $key])->execute();
            }

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

Doc-block of $type in getConfig is phpdoc param type string which is not a permitted replacement of the nullable param type ?string declared in the signature ('?T' should be documented as 'T|null' or '?T')
Open

     * @param string $type

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

            if ((new \App\Db\Query())->select('type', 'name')

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

                $result = $db->createCommand()->insert($this->baseTable, ['val' => $val, 'type' => $type, 'name' => $key])->execute();

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

                $result = $db->createCommand()->update($this->baseTable, ['val' => $val], ['type' => $type, 'name' => $key])->execute();

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

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

Doc-block of getConfig contains declared return type void which is incompatible with the return type array declared in the signature
Open

     * @return void

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

class Settings_ApiAddress_Module_Model extends Settings_Vtiger_Module_Model

The class Settings_ApiAddress_Module_Model is not named in CamelCase.
Open

class Settings_ApiAddress_Module_Model extends Settings_Vtiger_Module_Model
{
    /** {@inheritdoc} */
    public $baseTable = 's_#__address_finder_config';

CamelCaseClassName

Since: 0.2

It is considered best practice to use the CamelCase notation to name classes.

Example

class class_name {
}

Source

Avoid variables with short names like $db. Configured minimum length is 3.
Open

        $db = \App\Db::getInstance();

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

Source https://phpmd.org/rules/naming.html#shortvariable

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

    public function getConfig(string $type = null): array

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

        $rawData = [];

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 void

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

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

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

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

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

    public $baseTable = 's_#__address_finder_config';

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

     */

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

     * Get configuration.

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

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

    /**

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

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

                $result = $db->createCommand()->update($this->baseTable, ['val' => $val], ['type' => $type, 'name' => $key])->execute();

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

    public function setConfig(array $data): bool

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

                ->from($this->baseTable)

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

                ->where(['name' => $key, 'type' => $type])

Line exceeds 120 characters; contains 136 characters
Open

                $result = $db->createCommand()->update($this->baseTable, ['val' => $val], ['type' => $type, 'name' => $key])->execute();

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

     * Save Configuration.

Line exceeds 120 characters; contains 134 characters
Open

                $result = $db->createCommand()->insert($this->baseTable, ['val' => $val, 'type' => $type, 'name' => $key])->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

        return (bool) $result;

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

     * @param array $data

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

                ->exists()

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

                $result = $db->createCommand()->insert($this->baseTable, ['val' => $val, 'type' => $type, 'name' => $key])->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

        \App\Cache::delete('AddressFinder', 'Config');

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

     *

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

        return $rawData;

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

     *

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

            ['name' => $key, 'type' => $type, 'val' => $val] = $value;

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

        $db = \App\Db::getInstance();

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

        $result = false;

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

            if ((new \App\Db\Query())->select('type', '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

            $rawData[$row['type']][$row['name']] = $row['val'];

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

    }

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 {

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

class Settings_ApiAddress_Module_Model extends Settings_Vtiger_Module_Model

There are no issues that match your filters.

Category
Status