YetiForceCompany/YetiForceCRM

View on GitHub
modules/OpenStreetMap/views/MapModal.php

Summary

Maintainability
A
35 mins
Test Coverage
A
91%

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

    public function process(App\Request $request)
    {
        $moduleName = $request->getModule();
        $moduleModel = OpenStreetMap_Module_Model::getInstance($moduleName);
        $coordinatesModel = OpenStreetMap_Coordinate_Model::getInstance();
Severity: Minor
Found in modules/OpenStreetMap/views/MapModal.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 '35', column '14').
Open

            throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

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 '38', column '14').
Open

            throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

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\Map\Address' in method 'preProcessAjax'.
Open

        $viewer->assign('ADDRESS_PROVIDERS', \App\Map\Address::getActiveProviders());

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

        } else {
            $cacheRecords = $coordinatesModel->getCachedRecords();
        }

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

Avoid using static access to class 'Users_Privileges_Model' in method 'checkPermission'.
Open

        $currentUserPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();

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 'OpenStreetMap_Module_Model' in method 'process'.
Open

        $moduleModel = OpenStreetMap_Module_Model::getInstance($moduleName);

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 'OpenStreetMap_Coordinate_Model' in method 'process'.
Open

        $coordinatesModel = OpenStreetMap_Coordinate_Model::getInstance();

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

            $srcModuleModel = Vtiger_Module_Model::getInstance($request->getByType('srcModule'));

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 "srcModule" 6 times.
Open

        if (!$request->isEmpty('srcModule', true) && !$currentUserPrivilegesModel->hasModulePermission($request->getByType('srcModule'))) {

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.

Argument 1 (mixed) is string but \Users_Privileges_Model::hasModulePermission() takes int defined at /code/modules/Users/models/Privileges.php:101
Open

        if (!$currentUserPrivilegesModel->hasModulePermission($request->getModule())) {

Call to undeclared method \OpenStreetMap_MapModal_View::checkAndConvertCssStyles
Open

        return $this->checkAndConvertCssStyles([
Severity: Critical
Found in modules/OpenStreetMap/views/MapModal.php by phan

Call to undeclared method \OpenStreetMap_MapModal_View::getViewer
Open

        $viewer = $this->getViewer($request);
Severity: Critical
Found in modules/OpenStreetMap/views/MapModal.php by phan

Reference to undeclared class \App\Controller\Modal
Open

        parent::preProcessAjax($request);
Severity: Critical
Found in modules/OpenStreetMap/views/MapModal.php by phan

Class extends undeclared class \App\Controller\Modal
Open

class OpenStreetMap_MapModal_View extends \App\Controller\Modal
Severity: Critical
Found in modules/OpenStreetMap/views/MapModal.php by phan

Variable $cacheRecords was undeclared, but array fields are being added to it.
Open

            $cacheRecords[$request->getByType('srcModule')] = 0; // default values

Call to undeclared method \OpenStreetMap_MapModal_View::getViewer
Open

        $viewer = $this->getViewer($request);
Severity: Critical
Found in modules/OpenStreetMap/views/MapModal.php by phan

Call to undeclared method \OpenStreetMap_MapModal_View::checkAndConvertJsScripts
Open

        return $this->checkAndConvertJsScripts([
Severity: Critical
Found in modules/OpenStreetMap/views/MapModal.php by phan

Avoid excessively long variable names like $currentUserPrivilegesModel. Keep variable name length under 20.
Open

        $currentUserPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

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

class OpenStreetMap_MapModal_View extends \App\Controller\Modal

The class OpenStreetMap_MapModal_View is not named in CamelCase.
Open

class OpenStreetMap_MapModal_View extends \App\Controller\Modal
{
    /** {@inheritdoc} */
    public $modalSize = 'modal-fullscreen';

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

        if (!$currentUserPrivilegesModel->hasModulePermission($request->getModule())) {

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

        parent::preProcessAjax($request);

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

        $viewer = $this->getViewer($request);

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

            '~libraries/leaflet/dist/leaflet.css',

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

    public $headerClass = 'py-2';

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

    }

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

        $moduleName = $request->getModule();

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

        $viewer->assign('FIELDS_TO_GROUP', $fieldsToGroup);

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

        $viewer->assign('SRC_MODULE', $request->getByType('srcModule'));

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

            'modules.OpenStreetMap.resources.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

        ]);

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

    public function preProcessAjax(App\Request $request)

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

    protected function preProcessTplName(App\Request $request)

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

        return $this->checkAndConvertCssStyles([

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

    public function checkPermission(App\Request $request)

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

        $moduleModel = OpenStreetMap_Module_Model::getInstance($moduleName);

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

            $srcModuleModel = Vtiger_Module_Model::getInstance($request->getByType('srcModule'));

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

        $viewer->assign('MODULE_NAME', $moduleName);

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

    public function getModalCss(App\Request $request)

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

    public $modalSize = 'modal-fullscreen';

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

            }

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

            $cacheRecords[$request->getByType('srcModule')] = 0; // default values

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

        $viewer->view('MapModal.tpl', $moduleName);

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

    protected $pageTitle = 'LBL_MAP';

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

            throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

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

    public function process(App\Request $request)

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 getModalScripts(App\Request $request)

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

            '~libraries/leaflet/dist/leaflet.js',

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

    {

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

            foreach ($fields as $fieldModel) {

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

            $cacheRecords = $coordinatesModel->getCachedRecords();

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

            '~libraries/leaflet.awesome-markers/dist/leaflet.awesome-markers.js',

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

        if (!$request->isEmpty('srcModule', true)) {

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

    public $modalIcon = 'fas fa-globe';

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

        if (!$request->isEmpty('srcModule', true) && !$currentUserPrivilegesModel->hasModulePermission($request->getByType('srcModule'))) {

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

    /** {@inheritdoc} */

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

            $cacheRecords = array_merge($cacheRecords, $coordinatesModel->getCachedRecords());

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

        $viewer->assign('ALLOWED_MODULES', $moduleModel->getAllowedModules());

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

            '~libraries/leaflet.awesome-markers/dist/leaflet.awesome-markers.css',

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

    public $showFooter = 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

    }

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

        return 'MapModalHeader.tpl';

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

        $coordinatesModel = OpenStreetMap_Coordinate_Model::getInstance();

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

            $fieldsToGroup = [];

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

    }

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

            throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);

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

        $viewer = $this->getViewer($request);

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

        $viewer->assign('ADDRESS_PROVIDERS', \App\Map\Address::getActiveProviders());

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

                if ('picklist' === $fieldModel->getFieldDataType()) {

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

        }

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

            '~libraries/leaflet.markercluster/dist/leaflet.markercluster.js',

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

    }

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

            '~libraries/leaflet.markercluster/dist/MarkerCluster.css',

Line exceeds 120 characters; contains 139 characters
Open

        if (!$request->isEmpty('srcModule', true) && !$currentUserPrivilegesModel->hasModulePermission($request->getByType('srcModule'))) {

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

    }

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

            $fields = $srcModuleModel->getFields();

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

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

    /** {@inheritdoc} */

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

        $currentUserPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();

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

        return $this->checkAndConvertJsScripts([

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

            '~libraries/leaflet.markercluster/dist/MarkerCluster.Default.css',

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

        $viewer->assign('CACHE_GROUP_RECORDS', $cacheRecords);

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

    {

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

class OpenStreetMap_MapModal_View extends \App\Controller\Modal

There are no issues that match your filters.

Category
Status