YetiForceCompany/YetiForceCRM

View on GitHub
modules/Import/models/Map.php

Summary

Maintainability
A
35 mins
Test Coverage
F
0%

Function getInstanceFromDb has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public static function getInstanceFromDb($row)
    {
        $map = [];
        foreach ($row as $key => $value) {
            if ('content' == $key) {
Severity: Minor
Found in modules/Import/models/Map.php - About 35 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 '95', column '22').
Open

        $dataReader = (new App\Db\Query())->from(self::$tableName)
Severity: Minor
Found in modules/Import/models/Map.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 getInstanceFromDb uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $map[$key] = $value;
            }
Severity: Minor
Found in modules/Import/models/Map.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

Define a constant instead of duplicating this literal "module" 3 times.
Open

            $dbCommand->update(self::$tableName, ['content' => $this->getStringifiedContent()], ['name' => $this->getValue('name'), 'module' => $this->getValue('module')])->execute();
Severity: Critical
Found in modules/Import/models/Map.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 "content" 5 times.
Open

            if ('content' == $key) {
Severity: Critical
Found in modules/Import/models/Map.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

        \App\Db::getInstance()
Severity: Critical
Found in modules/Import/models/Map.php by phan

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

            $dbCommand = App\Db::getInstance()->createCommand();
Severity: Critical
Found in modules/Import/models/Map.php by phan

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

        $dataReader = (new App\Db\Query())->from(self::$tableName)
Severity: Critical
Found in modules/Import/models/Map.php by phan

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

class Import_Map_Model extends \App\Base

The class Import_Map_Model is not named in CamelCase.
Open

class Import_Map_Model extends \App\Base
{
    public static $tableName = 'vtiger_import_maps';
    public $map;

Severity: Minor
Found in modules/Import/models/Map.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

                $map[$key] = $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

            ->update('vtiger_import_maps', ['date_modified' => date('Y-m-d H:i:s'), 'deleted' => 1], ['id' => $mapId])

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

            $key = str_replace('&', '/amp/', $key);

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

        }

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

            $importMap = self::getInstanceFromDb($row);

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

                foreach ($pairs as $pair) {

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

                    $mappedName = str_replace('/eq/', '=', $mappedName);

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

        return $this->map[$key];

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

        $keyValueStrings = [];

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

        if (\count($values) > 0) {

Line exceeds 120 characters; contains 183 characters
Open

            $dbCommand->update(self::$tableName, ['content' => $this->getStringifiedContent()], ['name' => $this->getValue('name'), 'module' => $this->getValue('module')])->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

    public function getAllValues()

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

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

        return new self($map);

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

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

            ->createCommand()->query();

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

        $dataReader = (new App\Db\Query())->from(self::$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

        while ($row = $dataReader->read()) {

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

                $content = [];

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

                    $mappedName = str_replace('/amp/', '&', $mappedName);

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

                $map[$key] = $content;

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 getAllByModule($moduleName)

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

        $map = [];

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

    {

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

        $savedMaps = [];

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

    public $map;

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

        foreach ($row as $key => $value) {

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

            if ('content' == $key) {

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

    {

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

            $key = str_replace('=', '/eq/', $key);

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

            $keyValueStrings[] = $key . '=' . $value;

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

            $dbCommand->insert(self::$tableName, $values)->execute();

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

    public static $tableName = 'vtiger_import_maps';

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

                $pairs = $value ? explode('&', $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

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

        if (empty($this->map['content'])) {

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

        $content = $this->map['content'];

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

    {

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

        $values['content'] = null;

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

        $values['date_entered'] = date('Y-m-d H:i:s');

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

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

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

            $savedMaps[$importMap->getId()] = $importMap;

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

    public static function getInstanceFromDb($row)

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

        return $this->map['id'];

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

    public function getStringifiedContent()

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

        foreach ($content as $key => $value) {

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

        $this->map = $map;

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

    }

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

                    $content["$mappedName"] = $sequence;

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

    public static function markAsDeleted($mapId)

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

        \App\Db::getInstance()

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

    public function getId()

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

    public function getValue($key)

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

                    [$mappedName, $sequence] = explode('=', $pair);

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

    public function save()

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

    public function __construct($map)

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 implode('&', $keyValueStrings);

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 $this->map;

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

    {

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

        $values = $this->getAllValues();

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

            $dbCommand->update(self::$tableName, ['content' => $this->getStringifiedContent()], ['name' => $this->getValue('name'), 'module' => $this->getValue('module')])->execute();

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

            ->where(['deleted' => 0, 'module' => $moduleName])

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

class Import_Map_Model extends \App\Base

There are no issues that match your filters.

Category
Status