YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

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

    public static function getConditionBuilderStructure(Vtiger_Module_Model $moduleModel, ?string $skipfield): array
    {
        $structure = [];
        $blockModelList = $moduleModel->getBlocks();
        foreach ($blockModelList as $blockLabel => $blockModel) {
Severity: Minor
Found in modules/Settings/PickListDependency/models/Module.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

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

    public function getListFields(): array
    {
        if (!isset($this->listFieldModels)) {
            foreach (parent::getListFields() as $fieldName => $fieldModel) {
                if ('tabid' !== $fieldName) {
Severity: Minor
Found in modules/Settings/PickListDependency/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 '75', column '22').
Open

        $dataReader = (new \App\Db\Query())->select(['vtiger_field.tabid', 'vtiger_tab.tablabel', 'name' => 'vtiger_tab.name'])->from('vtiger_field')

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

Define a constant instead of duplicating this literal "tabid" 5 times.
Open

        'tabid' => 'LBL_MODULE',

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

        $dataReader = (new \App\Db\Query())->select(['vtiger_field.tabid', 'vtiger_tab.tablabel', 'name' => 'vtiger_tab.name'])->from('vtiger_field')

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::select
Open

        $dataReader = (new \App\Db\Query())->select(['vtiger_field.tabid', 'vtiger_tab.tablabel', 'name' => 'vtiger_tab.name'])->from('vtiger_field')

Return type of getConditionBuilderStructure() is undeclared type \voiarrayd
Open

    public static function getConditionBuilderStructure(Vtiger_Module_Model $moduleModel, ?string $skipfield): array

Reference to undeclared property \Settings_PickListDependency_Module_Model->listFieldModels
Open

        return $this->listFieldModels;

Doc-block of getConditionBuilderStructure contains declared return type \voiarrayd which is incompatible with the return type array declared in the signature
Open

     * @return voiarrayd

Reference to undeclared property \Settings_PickListDependency_Module_Model->listFieldModels
Open

        if (!isset($this->listFieldModels)) {

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

class Settings_PickListDependency_Module_Model extends Settings_Vtiger_Module_Model

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 13 and the first side effect is on line 11.
Open

<?php

The class Settings_PickListDependency_Module_Model is not named in CamelCase.
Open

class Settings_PickListDependency_Module_Model extends Settings_Vtiger_Module_Model
{
    /** @var string Module name. */
    public $name = 'PickListDependency';
    /** @var string Module name. */

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

    /** @var string Module name. */

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

    /** @var string Module name. */

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

    public $baseIndex = 'id';

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

    public $listFields = [

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

    public function getDefaultUrl()

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

        'source_field' => 'LBL_SOURCE_FIELD'

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

    /** @var string Base table. */

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

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

            $tabId = $row['tabid'] = (int) $row['tabid'];

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 ($this->editFields as $fieldName) {

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

     * @param string|null         $skipfield

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 $baseTable = 's_#__picklist_dependency';

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

     */

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

    /** @var array Name fields. */

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

            foreach (parent::getListFields() as $fieldName => $fieldModel) {

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 $nameFields = ['name'];

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

    public static function getPicklistSupportedModules(): array

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

            ->innerJoin('vtiger_tab', 'vtiger_field.tabid = vtiger_tab.tabid')

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

            ->andWhere(['not', ['vtiger_field.block' => null]])

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 the url for default view of the module.

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 'index.php?module=PickListDependency&parent=Settings&view=List';

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

        $structure = [];

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

        $blockModelList = $moduleModel->getBlocks();

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

    public $parent = 'Settings';

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

    public $editFields = ['tabid', 'source_field'];

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

            ->having(['>', 'count(*)', 1])->distinct('vtiger_field.tabid')->createCommand()->query();

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

        return $structure;

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

     * @param Vtiger_Module_Model $moduleModel

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

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

    {

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

            ->groupBy('vtiger_field.tabid, vtiger_tab.tablabel, vtiger_tab.name')

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

    public $name = 'PickListDependency';

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

        'tabid' => 'LBL_MODULE',

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

    /** @var array Name fields. */

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

    public function getCreateRecordUrl()

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

     * Get picklist supported modules.

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

     *

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

            ->andWhere(['<>', 'vtiger_field.tabid', 29])

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

    /**

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

     *

Line exceeds 120 characters; contains 129 characters
Open

                if ($fieldName !== $skipfield && \in_array($fieldModel->getUIType(), [15, 16]) && $fieldModel->isActiveField()) {

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

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

                    $fieldModel->set('sort', true);

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

            ->where(['uitype' => [15, 16], 'vtiger_field.displaytype' => 1, 'vtiger_field.presence' => [0, 2]])

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

            $structure[$fieldName] = $fieldModel;

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

     * @return voiarrayd

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

        foreach ($blockModelList as $blockLabel => $blockModel) {

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

            foreach ($blockModel->getFields() as $fieldName => $fieldModel) {

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

                if ($fieldName !== $skipfield && \in_array($fieldModel->getUIType(), [15, 16]) && $fieldModel->isActiveField()) {

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

    /** @var string Base index. */

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

    /** @var array List fields. */

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

    {

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

     * Get structure fields.

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

    public static function getConditionBuilderStructure(Vtiger_Module_Model $moduleModel, ?string $skipfield): array

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

        return 'index.php?parent=Settings&module=PickListDependency&view=Edit';

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

                if ('tabid' !== $fieldName) {

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

        $dataReader = (new \App\Db\Query())->select(['vtiger_field.tabid', 'vtiger_tab.tablabel', 'name' => 'vtiger_tab.name'])->from('vtiger_field')

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

            $fieldModel = $recordModel->getFieldInstanceByName($fieldName);

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

                    $structure[$blockLabel][$fieldName] = $fieldModel;

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

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

    {

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

        $structure = [];

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 the url for Adding Dependency.

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

        if (!isset($this->listFieldModels)) {

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 getEditViewStructure($recordModel): 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 = [];

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

     * @param Settings_PickListDependency_Record_Model|null $recordModel

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

     * Get condition builder structure.

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

                }

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

    }

Line exceeds 120 characters; contains 149 characters
Open

        $dataReader = (new \App\Db\Query())->select(['vtiger_field.tabid', 'vtiger_tab.tablabel', 'name' => 'vtiger_tab.name'])->from('vtiger_field')

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

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

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

        return $this->listFieldModels;

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

            $modules[$tabId] = $row;

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

        return $modules;

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

class Settings_PickListDependency_Module_Model extends Settings_Vtiger_Module_Model

There are no issues that match your filters.

Category
Status