YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
1 hr
Test Coverage
F
25%

Function getCustomViewList has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    public function getCustomViewList()
    {
        $filters = (new \App\Db\Query())->select(['cvid', 'viewname', 'entitytype', 'vtiger_tab.tabid'])
            ->from('vtiger_customview')
            ->leftJoin('vtiger_tab', 'vtiger_tab.name = vtiger_customview.entitytype')->all();
Severity: Minor
Found in modules/Settings/Menu/models/Module.php - About 1 hr 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

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

    public function getMenuUrl($row)
    {
        switch ($row['type']) {
            case 0:
                $moduleModel = Vtiger_Module_Model::getInstance($row['module']);
Severity: Minor
Found in modules/Settings/Menu/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 '133', column '24').
Open

                $fileFilters = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filterDir, FilesystemIterator::SKIP_DOTS));

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 '133', column '54').
Open

                $fileFilters = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filterDir, FilesystemIterator::SKIP_DOTS));

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 '113', column '23').
Open

        $maxSequence = (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 '127', column '19').
Open

        $filters = (new \App\Db\Query())->select(['cvid', 'viewname', 'entitytype', 'vtiger_tab.tabid'])

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 '86', column '15').
Open

        return (new \App\Db\Query())->select(['tabid', 'name'])->from('vtiger_tab')

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

    public function getMenuTypes($key = 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 'Vtiger_Loader' in method 'getCustomViewList'.
Open

                    $handlerClass = Vtiger_Loader::getComponentClassName('Filter', $name, $module->get('name'));

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 'Vtiger_Module_Model' in method 'getMenuUrl'.
Open

                $moduleModel = Vtiger_Module_Model::getInstance($row['module']);

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 'Vtiger_Module_Model' in method 'getCustomViewList'.
Open

        foreach (Vtiger_Module_Model::getAll() as $module) {

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 "parentid" 5 times.
Open

        'id', 'role', 'parentid', 'type', 'sequence', 'module', 'label', 'newwindow',

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 "dataurl" 5 times.
Open

        'dataurl', 'showicon', 'icon', 'sizeicon', 'hotkey', 'filters', 'edit', 'source', 'countentries',

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.

Saw possibly unextractable annotation for a fragment of comment '* @param bool true/false': after bool, did not see an element name (will guess based on comment order)
Open

     * @param bool true/false

Assigning array{0:'id',1:'role',2:'parentid',3:'type',4:'sequence',5:'module',6:'label',7:'newwindow',8:'dataurl',9:'showicon',10:'icon',11:'sizeicon',12:'hotkey',13:'filters',14:'edit',15:'source',16:'countentries'} to property but \Settings_Menu_Module_Model->editFields is \strung[]
Open

    protected $editFields = [

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

        $filters = (new \App\Db\Query())->select(['cvid', 'viewname', 'entitytype', 'vtiger_tab.tabid'])
Severity: Critical
Found in modules/Settings/Menu/models/Module.php by phan

Saw unextractable annotation for comment '* @return <settings_menu_module_model>'</settings_menu_module_model>
Open

     * @return <Settings_Menu_Module_Model>

Property \Settings_Menu_Module_Model->editFields has undeclared type \strung[] (Did you mean string)
Open

    protected $editFields = [

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

        $maxSequence = (new \App\Db\Query())
Severity: Critical
Found in modules/Settings/Menu/models/Module.php by phan

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

        return (new \App\Db\Query())->select(['tabid', 'name'])->from('vtiger_tab')
Severity: Critical
Found in modules/Settings/Menu/models/Module.php by phan

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

class Settings_Menu_Module_Model

The class Settings_Menu_Module_Model is not named in CamelCase.
Open

class Settings_Menu_Module_Model
{
    /**
     * Fields to edit.
     *

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

        'dataurl', 'showicon', 'icon', 'sizeicon', 'hotkey', 'filters', 'edit', 'source', 'countentries',

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

    {

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

     * Function to get editable fields.

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

                break;

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

        return $url;

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

     * Fields to edit.

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

    }

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

                $moduleModel = Vtiger_Module_Model::getInstance($row['module']);

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

                $url = 'index.php?module=' . $row['name'] . '&view=List&viewname=' . $row['dataurl'] . '&mid=' . $row['id'] . (empty($row['parentid']) ? '' : ('&parent=' . $row['parentid']));

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

            ->from('vtiger_customview')

Line exceeds 120 characters; contains 136 characters
Open

                $fileFilters = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filterDir, FilesystemIterator::SKIP_DOTS));

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

                            'entitytype' => $module->get('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

        if (false === $key) {

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

        return array_search($val, \App\Menu::TYPES);

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

    public function getMenuUrl($row)

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

            case 4:

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

        return (int) $maxSequence;

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

    /**

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

     * Function to get all filters.

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

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

            case 0:

Line exceeds 120 characters; contains 191 characters
Open

                $url = 'index.php?module=' . $row['name'] . '&view=List&viewname=' . $row['dataurl'] . '&mid=' . $row['id'] . (empty($row['parentid']) ? '' : ('&parent=' . $row['parentid']));

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 getModulesList(): array

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

    }

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

        $modules = $this->getModulesList();

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

            $filterDir = 'modules' . DIRECTORY_SEPARATOR . $module->get('name') . DIRECTORY_SEPARATOR . 'filters';

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

    public function getMenuTypes($key = false)

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

    {

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

        switch ($row['type']) {

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

                $url = addslashes($row['dataurl']);

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

    }

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

            ->max('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

                break;

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

                $url = $row['dataurl'];

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

        return (new \App\Db\Query())->select(['tabid', 'name'])->from('vtiger_tab')

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 (Vtiger_Module_Model::getAll() as $module) {

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

     * @return <Settings_Menu_Module_Model>

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

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

            return \App\Menu::TYPES;

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

                $url = $row['dataurl'];

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

            ->where(['not in', 'name', ['Users', 'ModComments']])

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 string[]

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

                break;

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

                break;

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

            ->andWhere(['or', ['isentitytype' => 1], ['name' => ['OSSMail', 'Rss']]])

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

            ->andWhere(['presence' => 0])

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

            ->all();

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

        foreach ($modules as $key => $module) {

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

            if (!Vtiger_Module_Model::getInstance($module['name'])->isQuickCreateSupported()) {

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

        $filters = (new \App\Db\Query())->select(['cvid', 'viewname', 'entitytype', 'vtiger_tab.tabid'])

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

                    $handlerClass = Vtiger_Loader::getComponentClassName('Filter', $name, $module->get('name'));

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

    protected $editFields = [

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

     * Function to get instance.

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

     * @param bool true/false

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

        }

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

            default:

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

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

            ->from('yetiforce_menu')

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

                            'cvid' => $name,

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

     * @var strung[]

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

    }

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

            case 1:

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

    {

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

                unset($modules[$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

                        $filters[] = [

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

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 \App\Menu::TYPES[$key];

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

    public function getMenuTypeKey($val)

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

            case 7:

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

     * Module list.

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

        'id', 'role', 'parentid', 'type', 'sequence', 'module', 'label', 'newwindow',

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

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

                foreach ($fileFilters as $filter) {

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

     * Get a list of modules with quick create support.

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

     */

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

        return $modules;

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

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

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

            if (file_exists($filterDir)) {

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

                $fileFilters = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($filterDir, FilesystemIterator::SKIP_DOTS));

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

                            'viewname' => (new $handlerClass())->getViewName(),

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

                            'tabid' => $module->getId(),

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

                break;

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

            ->orderBy('tabsequence')

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

            ->leftJoin('vtiger_tab', 'vtiger_tab.name = vtiger_customview.entitytype')->all();

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

                    $name = str_replace('.php', '', $filter->getFilename());

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

                    }

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

                $url = $moduleModel->getDefaultUrl() . '&mid=' . $row['id'] . (empty($row['parentid']) ? '' : ('&parent=' . $row['parentid']));

Line exceeds 120 characters; contains 143 characters
Open

                $url = $moduleModel->getDefaultUrl() . '&mid=' . $row['id'] . (empty($row['parentid']) ? '' : ('&parent=' . $row['parentid']));

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 getQuickCreateModuleList(): array

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

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

                    if (class_exists($handlerClass)) {

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

class Settings_Menu_Module_Model

There are no issues that match your filters.

Category
Status