YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
25 mins
Test Coverage
A
93%

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

    public static function getPicklistValue()
    {
        $keys = ['name', 'label', 'value', 'table', 'field'];
        $calendarConfig = [];
        foreach (self::getCalendarColorPicklist() as $picklistName) {
Severity: Minor
Found in modules/Settings/Calendar/models/Module.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 '68', column '17').
Open

        $query = (new \App\Db\Query())

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

        $query = (new \App\Db\Query())

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\Fields\Picklist' in method 'getPicklistValue'.
Open

            $picklistValues = \App\Fields\Picklist::getValues($picklistName);

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

        \App\Cache::clear();

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

        } else {
            $value = '';
        }

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

                'value' => $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 "color" 6 times.
Open

        \App\Db::getInstance()->createCommand()->update('vtiger_calendar_config', ['value' => $params['color']], ['name' => $params['id']])

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

                'label' => $row['label'],

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

            ->from('vtiger_calendar_config')

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\Query::from
Open

        $query = (new \App\Db\Query())

@throws type of getNotWorkingDays has undeclared type \yii\db\Exception (Did you mean class \Exception)
Open

    public static function getNotWorkingDays()

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

        $query = (new \App\Db\Query())

Suspicious array access to nullable ?array{color:string}|?mixed
Open

                    'value' => $picklistValue[$picklistName],

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

        \App\Db::getInstance()->createCommand()->update('vtiger_calendar_config', ['value' => $value], ['name' => 'notworkingdays']

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

        \App\Db::getInstance()->createCommand()->update('vtiger_calendar_config', ['value' => $params['color']], ['name' => $params['id']])

@throws type of updateNotWorkingDays has undeclared type \yii\db\Exception (Did you mean class \Exception)
Open

    public static function updateNotWorkingDays(array $params)

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

class Settings_Calendar_Module_Model extends Settings_Vtiger_Module_Model

The class Settings_Calendar_Module_Model is not named in CamelCase.
Open

class Settings_Calendar_Module_Model extends Settings_Vtiger_Module_Model
{
    public static function getCalendarConfig($type)
    {
        $query = (new \App\Db\Query())

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

        $calendarConfig = [];

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

                'name' => $row['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

     *

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();

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

        if ('colors' == $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

        $calendarConfig = [];

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

                    'color' => $picklistValue['color'],

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 getCalendarColorPicklist()

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

                    'id' => $picklistValueId,

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

    public static function getCalendarConfig($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

     * @param array $params

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

    public static function updateNotWorkingDays(array $params)

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 picklist values.

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

                }

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

                    'field' => $picklistName, ]);

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

        }

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

            ->where(['name' => 'notworkingdays']);

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

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

        if (!empty($params['val'])) {

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

                    'value' => $picklistValue[$picklistName],

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

    public static function updateCalendarConfig($params)

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

     *

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

     * @throws \yii\db\Exception

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

            ->from('vtiger_calendar_config')

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

                    'table' => 'vtiger_' . $picklistName,

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

        }

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

            ->from('vtiger_calendar_config')

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::clear();

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

     * Get not working days.

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 array

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

                if (false === strpos($picklistValue['color'], '#')) {

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

            }

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

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

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

    }

Line exceeds 120 characters; contains 131 characters
Open

        \App\Db::getInstance()->createCommand()->update('vtiger_calendar_config', ['value' => $value], ['name' => 'notworkingdays']

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

                'label' => $row['label'],

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\Db::getInstance()->createCommand()->update('vtiger_calendar_config', ['value' => $params['color']], ['name' => $params['id']])

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

            $value = '';

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

        \App\Db::getInstance()->createCommand()->update('vtiger_calendar_config', ['value' => $value], ['name' => 'notworkingdays']

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

     * @throws \yii\db\Exception

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

        $keys = ['name', 'label', 'value', 'table', 'field'];

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

                'value' => $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

            $value = implode(';', $params['val']);

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 ['activitytype'];

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

    public static function getPicklistValue()

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

                    $picklistValue['color'] = '#' . $picklistValue['color'];

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

     * Updates working days.

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 = [];

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

            $return = explode(';', $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

        return $return;

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

            $picklistValues = \App\Fields\Picklist::getValues($picklistName);

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

            foreach ($picklistValues as $picklistValueId => $picklistValue) {

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

                $calendarConfig[] = array_combine($keys, [

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

            $calendarConfig[] = [

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

    }

Line exceeds 120 characters; contains 139 characters
Open

        \App\Db::getInstance()->createCommand()->update('vtiger_calendar_config', ['value' => $params['color']], ['name' => $params['id']])

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

        $query = (new \App\Db\Query())

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

            $calendarConfig = array_merge($calendarConfig, self::getPicklistValue());

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

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

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

    public static function getNotWorkingDays()

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

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

        $row = $query->createCommand()->queryOne();

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 (self::getCalendarColorPicklist() as $picklistName) {

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

class Settings_Calendar_Module_Model extends Settings_Vtiger_Module_Model

Expected 0 spaces before closing bracket; newline found
Open

        \App\Db::getInstance()->createCommand()->update('vtiger_calendar_config', ['value' => $value], ['name' => 'notworkingdays']

There are no issues that match your filters.

Category
Status