YetiForceCompany/YetiForceCRM

View on GitHub
modules/MailIntegration/views/Iframe.php

Summary

Maintainability
A
25 mins
Test Coverage
F
0%

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

    public function getModules(): array
    {
        $modules = [];
        $quickCreate = App\Config::module('MailIntegration', 'modulesListQuickCreate', []);
        foreach (\App\Relation::getByModule('OSSMailView', true) as $relation) {
Severity: Minor
Found in modules/MailIntegration/views/Iframe.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

Avoid using static access to class 'App\Config' in method 'process'.
Open

            $viewer->assign('URL', App\Config::main('site_URL'));

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\Mail\Message' in method 'process'.
Open

            $mail = App\Mail\Message::getScannerByEngine($request->getByType('source'));

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\Relation' in method 'getModules'.
Open

        foreach (\App\Relation::getByModule('OSSMailView', true) as $relation) {

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\Privilege' in method 'getModules'.
Open

            if (0 === $relation['presence'] && 'getRecordToMails' === $relation['name'] && App\Privilege::isPermitted($relation['related_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 assigning values to variables in if clauses and the like (line '37', column '8').
Open

    public function process(App\Request $request)
    {
        $moduleName = $request->getModule();
        $viewer = $this->getViewer($request);
        if (Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($request->getModule())) {

IfStatementAssignment

Since: 2.7.0

Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

Example

class Foo
{
    public function bar($flag)
    {
        if ($foo = 'bar') { // possible typo
            // ...
        }
        if ($baz = 0) { // always false
            // ...
        }
    }
}

Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

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 {
                $relations = $mail->findRelatedRecords();
            }

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 'App\Config' in method 'getModules'.
Open

        $quickCreate = App\Config::module('MailIntegration', 'modulesListQuickCreate', []);

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

            if (0 === $relation['presence'] && 'getRecordToMails' === $relation['name'] && App\Privilege::isPermitted($relation['related_modulename'])) {

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 (Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($request->getModule())) {

Call to undeclared method \MailIntegration_Iframe_View::checkAndConvertJsScripts
Open

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

Class extends undeclared class \App\Controller\Modal
Open

class MailIntegration_Iframe_View extends \App\Controller\Modal
Severity: Critical
Found in modules/MailIntegration/views/Iframe.php by phan

Call to undeclared method \MailIntegration_Iframe_View::getViewer
Open

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

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

class MailIntegration_Iframe_View extends \App\Controller\Modal

The class MailIntegration_Iframe_View is not named in CamelCase.
Open

class MailIntegration_Iframe_View extends \App\Controller\Modal
{
    /** {@inheritdoc} */
    public $showHeader = false;
    /** {@inheritdoc} */

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

        return $modules;

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

        return true;

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

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

                $viewer->assign('MODULES', $this->getModules());

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

                $relations = $mail->getRelatedRecords();

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

            'modules.Vtiger.resources.Edit',

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

    public function getModules(): array

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

        $quickCreate = App\Config::module('MailIntegration', 'modulesListQuickCreate', []);

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

            $mail->initFromRequest($request);

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

            '~layouts/resources/validator/FieldValidator.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

    public $showHeader = false;

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

     * Get modules.

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

            if (0 === $relation['presence'] && 'getRecordToMails' === $relation['name'] && App\Privilege::isPermitted($relation['related_modulename'])) {

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

            '~layouts/resources/Field.js',

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

    {

Line exceeds 120 characters; contains 153 characters
Open

            if (0 === $relation['presence'] && 'getRecordToMails' === $relation['name'] && App\Privilege::isPermitted($relation['related_modulename'])) {

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

            $mail = App\Mail\Message::getScannerByEngine($request->getByType('source'));

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

            $viewer->assign('MODAL_SCRIPTS', $this->getModalScripts($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

        $modules = [];

Line exceeds 120 characters; contains 132 characters
Open

                $quickCreateSupported = Vtiger_Module_Model::getInstance($relation['related_modulename'])->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

                $quickCreateSupported = Vtiger_Module_Model::getInstance($relation['related_modulename'])->isQuickCreateSupported();

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

    /** {@inheritdoc} */

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

            if ($mailId = $mail->getMailCrmId()) {

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

                $relations = $mail->findRelatedRecords();

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

            $viewer->assign('MAIL_ID', $mailId);

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

            '~layouts/resources/validator/BaseValidator.js',

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

            $viewer->assign('RELATIONS', $relations);

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

    /** {@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

     */

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

        if (Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission($request->getModule())) {

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

    }

Line exceeds 120 characters; contains 161 characters
Open

                $modules[$relation['related_modulename']] = $quickCreateSupported && (!$quickCreate || \in_array($relation['related_modulename'], $quickCreate));

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('URL', App\Config::main('site_URL'));

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

        $viewer->view('Iframe/Container.tpl', $moduleName);

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

        foreach (\App\Relation::getByModule('OSSMailView', true) as $relation) {

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

            } else {

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

            "modules.{$request->getModule()}.resources.{$request->getByType('view', 2)}",

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

                $modules[$relation['related_modulename']] = $quickCreateSupported && (!$quickCreate || \in_array($relation['related_modulename'], $quickCreate));

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

        }

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

     * @return string[]

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

class MailIntegration_Iframe_View extends \App\Controller\Modal

There are no issues that match your filters.

Category
Status