YetiForceCompany/YetiForceCRM

View on GitHub
app/Controller/Components/View/MailMessageAnalysisModal.php

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

Function checkPermission has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function checkPermission(\App\Request $request)
    {
        if ($request->has('record')) {
            if (!\App\Security\AdminAccess::isPermitted('MailRbl')) {
                throw new \App\Exceptions\NoPermittedForAdmin('LBL_PERMISSION_DENIED');
Severity: Minor
Found in app/Controller/Components/View/MailMessageAnalysisModal.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

The method checkPermission() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
Open

    public function checkPermission(\App\Request $request)
    {
        if ($request->has('record')) {
            if (!\App\Security\AdminAccess::isPermitted('MailRbl')) {
                throw new \App\Exceptions\NoPermittedForAdmin('LBL_PERMISSION_DENIED');

CyclomaticComplexity

Since: 0.1

Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

Example

// Cyclomatic Complexity = 11
class Foo {
1   public function example() {
2       if ($a == $b) {
3           if ($a1 == $b1) {
                fiddle();
4           } elseif ($a2 == $b2) {
                fiddle();
            } else {
                fiddle();
            }
5       } elseif ($c == $d) {
6           while ($c == $d) {
                fiddle();
            }
7        } elseif ($e == $f) {
8           for ($n = 0; $n < $h; $n++) {
                fiddle();
            }
        } else {
            switch ($z) {
9               case 1:
                    fiddle();
                    break;
10              case 2:
                    fiddle();
                    break;
11              case 3:
                    fiddle();
                    break;
                default:
                    fiddle();
                    break;
            }
        }
    }
}

Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

Missing class import via use statement (line '44', column '15').
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 '40', column '15').
Open

                throw new \App\Exceptions\NoPermittedForAdmin('LBL_PERMISSION_DENIED');

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

                throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 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 '51', column '14').
Open

            throw new \App\Exceptions\AppException('ERR_NO_CONTENT', 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\Privilege' in method 'checkPermission'.
Open

            if (!\App\Privilege::isPermitted($request->getByType('sourceModule', 'Alnum'), 'DetailView', $request->getInteger('sourceRecord'))) {

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\Security\AdminAccess' in method 'checkPermission'.
Open

            if (!\App\Security\AdminAccess::isPermitted('MailRbl')) {

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

        } else {
            throw new \App\Exceptions\AppException('ERR_NO_CONTENT', 406);
        }

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\Mail\Rbl' in method 'preProcessAjax'.
Open

            $this->recordModel = \App\Mail\Rbl::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 '\App\Language' in method 'getPageTitle'.
Open

        return \App\Language::translate('LBL_MAIL_MESSAGE_DETAILS', 'Settings:MailRbl');

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

            $this->recordModel = \App\Mail\Rbl::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 '\App\Mail\Rbl' in method 'preProcessAjax'.
Open

            $this->recordModel = \App\Mail\Rbl::getRequestById($request->getInteger('record'));

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

        } else {
            $this->recordModel = \App\Mail\Rbl::getInstance([]);
            [$headers] = explode("\r\n\r\n", str_replace(["\r\n", "\r", "\n"], ["\n", "\n", "\r\n"], $request->getRaw('content')), 2);
            $this->recordModel->set('rawBody', $request->getRaw('content'));
            $this->recordModel->set('header', $headers);

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

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

        } elseif ($request->has('header') && $request->has('body') && $request->has('sourceModule') && $request->has('sourceRecord')) {

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

        if ($request->has('record')) {

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

        } elseif ($request->has('content')) {

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 "label" 9 times.
Open

            'fromName' => ['icon' => 'fas fa-upload', 'label' => 'LBL_FROM_NAME'],

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\Controller\Components\View\MailMessageAnalysisModal::getViewer
Open

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

Class extends undeclared class \App\Controller\Modal
Open

class MailMessageAnalysisModal extends \App\Controller\Modal

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

            if (!\Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission('OSSMail')) {

Reference to undeclared class \App\Controller\Modal
Open

        parent::preProcessAjax($request);

Call to undeclared method \App\Controller\Components\View\MailMessageAnalysisModal::getViewer
Open

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

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

    public function checkPermission(\App\Request $request)

Line exceeds 120 characters; contains 135 characters
Open

        } elseif ($request->has('header') && $request->has('body') && $request->has('sourceModule') && $request->has('sourceRecord')) {

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

    public $modalIcon = 'fas fa-lock';

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

        parent::preProcessAjax($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

    /** {@inheritdoc} */

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

            'byIP' => ['icon' => 'fas fa-network-wired', 'label' => 'LBL_BY_IP'],

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

            'dateTime' => ['icon' => 'fas fa-clock', 'label' => 'LBL_DATE'],

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

        if ($request->has('record')) {

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

        }

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

     * MailRbl record model.

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 ($request->has('record')) {

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

            if (!\Users_Privileges_Model::getCurrentUserPrivilegesModel()->hasModulePermission('OSSMail')) {

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

            if (!\App\Privilege::isPermitted($request->getByType('sourceModule', 'Alnum'), 'DetailView', $request->getInteger('sourceRecord'))) {

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

    public function getPageTitle(\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

    /** {@inheritdoc} */

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

            'fromHostname' => ['icon' => 'fas fa-server', 'label' => 'LBL_FROM_HOST_NAME'],

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

        } elseif ($request->has('header') && $request->has('body') && $request->has('sourceModule') && $request->has('sourceRecord')) {

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

    }

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

        $viewer->assign('TABLE_HEADERS', ['fromName', 'fromIP', 'byName', 'extraWith', 'extraComments', 'dateTime']);

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

            $this->recordModel->set('body', $request->getRaw('body'));

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

        $this->recordModel->parse();

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

        $viewer->assign('VERIFY_SENDER', $this->recordModel->verifySender());

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

            'extraComments' => ['icon' => 'far fa-comment-alt', 'label' => 'LBL_EXTRA_WITH'],

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

        $viewer->view('MailMessageAnalysisModal.tpl', $request->getModule(false));

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

    public $dangerBtn = 'LBL_CLOSE';

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

            if (!\App\Security\AdminAccess::isPermitted('MailRbl')) {

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

                throw new \App\Exceptions\NoPermittedForAdmin('LBL_PERMISSION_DENIED');

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

            }

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

            [$headers] = explode("\r\n\r\n", str_replace(["\r\n", "\r", "\n"], ["\n", "\n", "\r\n"], $request->getRaw('content')), 2);

Line exceeds 120 characters; contains 134 characters
Open

            [$headers] = explode("\r\n\r\n", str_replace(["\r\n", "\r", "\n"], ["\n", "\n", "\r\n"], $request->getRaw('content')), 2);

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

            $this->recordModel->set('header', $headers);

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

        $viewer->assign('VERIFY_DKIM', $this->recordModel->verifyDkim());

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

            'fromName' => ['icon' => 'fas fa-upload', 'label' => 'LBL_FROM_NAME'],

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

     * @var \App\Mail\Rbl

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

    protected $recordModel;

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

            }

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

            $this->recordModel = \App\Mail\Rbl::getRequestById($request->getInteger('record'));

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

        } elseif ($request->has('header') && $request->has('body')) {

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

            $this->recordModel->set('rawBody', $request->getRaw('content'));

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

            'fromIP' => ['icon' => 'fas fa-network-wired', 'label' => 'LBL_FROM_IP'],

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

            'byName' => ['icon' => 'fas fa-download', 'label' => 'LBL_BY_NAME'],

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

                throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);

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

            $this->recordModel = \App\Mail\Rbl::getInstance([]);

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

            'byHostname' => ['icon' => 'fas fa-server', 'label' => 'LBL_BY_HOST_NAME'],

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 $successBtn = '';

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

            throw new \App\Exceptions\AppException('ERR_NO_CONTENT', 406);

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('VERIFY_DMARC', $this->recordModel->verifyDmarc());

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

        } elseif ($request->has('content')) {

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

        }

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

    /** {@inheritdoc} */

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

    public $modalSize = 'modal-blg';

Line exceeds 120 characters; contains 145 characters
Open

            if (!\App\Privilege::isPermitted($request->getByType('sourceModule', 'Alnum'), 'DetailView', $request->getInteger('sourceRecord'))) {

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

    /** {@inheritdoc} */

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

        $viewer->assign('RECORD', $this->recordModel);

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

        $viewer->assign('SENDER', $this->recordModel->getSender());

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

        $viewer->assign('VERIFY_SPF', $this->recordModel->verifySpf());

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

        $viewer->assign('CARD_MAP', [

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

        return \App\Language::translate('LBL_MAIL_MESSAGE_DETAILS', 'Settings:MailRbl');

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

        $viewer->assign('LANG_MODULE_NAME', 'Settings:MailRbl');

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

        return 'MailMessageAnalysisModalHeader.tpl';

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

            $this->recordModel->set('header', $request->getRaw('header'));

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

            $this->recordModel = \App\Mail\Rbl::getInstance([]);

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

            'extraWith' => ['icon' => 'fab fa-expeditedssl', 'label' => 'LBL_EXTRA_COMMENTS'],

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

    }

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

    {

There are no issues that match your filters.

Category
Status