YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
25 mins
Test Coverage
F
25%

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

    public function getListFields(): array
    {
        if (!isset($this->listFieldModels)) {
            $fieldObjects = [];
            $service = $this->getService();
Severity: Minor
Found in modules/Settings/WebserviceUsers/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 '55', column '38').
Open

                    $fieldObjects[$fieldName] = new \App\Base(['name' => $fieldName, 'label' => $fieldLabel]);

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 "index.php?module=" 3 times.
Open

        return 'index.php?module=' . $this->getName() . '&parent=Settings&view=Edit&typeApi=' . $this->typeApi;

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.

Reference to undeclared property \Settings_WebserviceUsers_Module_Model->listFieldModels
Open

        return $this->listFieldModels;

Reference to undeclared property \Settings_WebserviceUsers_Module_Model->listFieldModels
Open

            $this->listFieldModels = $fieldObjects;

Reference to undeclared property \Settings_WebserviceUsers_Module_Model->listFieldModels
Open

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

Returning type string but getBaseTable() is declared to return \type
Open

        return $this->getService()->baseTable;

Returning type ?object but getService() is declared to return \Settings_WebserviceUsers_Record_Model
Open

        return $recordService;

Return type of getBaseTable() is undeclared type \type
Open

    public function getBaseTable()

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

class Settings_WebserviceUsers_Module_Model extends Settings_Vtiger_Module_Model

The class Settings_WebserviceUsers_Module_Model is not named in CamelCase.
Open

class Settings_WebserviceUsers_Module_Model extends Settings_Vtiger_Module_Model
{
    /** @var string Api type. */
    public $typeApi;

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

    }

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

                    $fieldObjects[$fieldName] = new \App\Base(['name' => $fieldName, 'label' => $fieldLabel]);

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

    public $name = 'WebserviceUsers';

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

        return $recordService;

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

    /**

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

            $fieldObjects = [];

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

            $service = $this->getService();

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

        return 'index.php?module=' . $this->getName() . '&parent=Settings&view=Edit&typeApi=' . $this->typeApi;

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

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

            $recordService->typeApi = $this->typeApi;

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

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

    public function getTableIndex()

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

    }

Line exceeds 120 characters; contains 122 characters
Open

        return 'index.php?module=' . $this->getName() . '&parent=Settings&view=ListViewSession&typeApi=' . $this->typeApi;

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

            $recordService = new $class();

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

            $this->listFieldModels = $fieldObjects;

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

     * Gets service record instance.

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

    public function getNameFields()

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

     * @return string - url

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

    public function getHistoryAccessActivityUrl(): string

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=' . $this->getName() . '&parent=Settings&view=HistoryAccessActivity&typeApi=' . $this->typeApi;

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

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

     * Function to get table primary 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

     *

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

     * @return array - array which contains fields which together construct name fields

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

        $recordService = 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

     * Function returns name of table in database.

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

    public function getSessionViewUrl(): string

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

     * @return \Settings_WebserviceUsers_Record_Model

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

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

    {

Line exceeds 120 characters; contains 128 characters
Open

        return 'index.php?module=' . $this->getName() . '&parent=Settings&view=HistoryAccessActivity&typeApi=' . $this->typeApi;

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=' . $this->getName() . '&parent=Settings&view=ListViewSession&typeApi=' . $this->typeApi;

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

     * Function to get the url for history activity view of the user.

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

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

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

    }

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

        if (class_exists($class)) {

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 ($service->listFields as $fieldName => $fieldLabel) {

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

     * Function to retrieve name fields of a module.

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

     */

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

    public function getEditViewUrl()

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

     */

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

        $class = "Settings_WebserviceUsers_{$this->typeApi}_Service";

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

            if ($service) {

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

    {

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 session view of the user.

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

class Settings_WebserviceUsers_Module_Model extends Settings_Vtiger_Module_Model

There are no issues that match your filters.

Category
Status