YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSMail/actions/GetMail.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method process has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process(App\Request $request)
    {
        $moduleName = $request->getModule();
        $sourceRecord = $request->getInteger('sourceRecord');
        $sourceModule = $request->getByType('sourceModule', 2);
Severity: Minor
Found in modules/OSSMail/actions/GetMail.php - About 1 hr to fix

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

        public function process(App\Request $request)
        {
            $moduleName = $request->getModule();
            $sourceRecord = $request->getInteger('sourceRecord');
            $sourceModule = $request->getByType('sourceModule', 2);
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.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

    Missing class import via use statement (line '23', column '14').
    Open

                throw new \App\Exceptions\NoPermitted('LBL_PERMISSION_DENIED', 406);
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

    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 '56', column '26').
    Open

                $viewController = new Vtiger_Index_View();
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

    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 '65', column '20').
    Open

                $response = new Vtiger_Response();
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

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

                throw new \App\Exceptions\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

    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

    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 {
                $email = '';
                if (1 == \count($emails)) {
                    $email = $emails[0]['email'];
                }
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

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

            $emailFields = OSSMailScanner_Record_Model::getEmailSearch($sourceModule);
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

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

            if (!\App\Privilege::isPermitted($request->getByType('sourceModule', 2), 'DetailView', $request->getInteger('sourceRecord'))) {
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

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

            $recordModel = Vtiger_Record_Model::getInstanceById($sourceRecord, $sourceModule);
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

    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 'Users_Privileges_Model' in method 'checkPermission'.
    Open

            $userPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

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

                        'fieldlabel' => App\Language::translate($emailField['fieldlabel'], $emailField['name']),
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

    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

    Call to undeclared method \Vtiger_Viewer::assign
    Open

                $viewer->assign('EMAILS', $emails);
    Severity: Critical
    Found in modules/OSSMail/actions/GetMail.php by phan

    Call to method getEmailSearch from undeclared class \OSSMailScanner_Record_Model
    Open

            $emailFields = OSSMailScanner_Record_Model::getEmailSearch($sourceModule);
    Severity: Critical
    Found in modules/OSSMail/actions/GetMail.php by phan

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

            if (!$userPrivilegesModel->hasModulePermission($moduleName)) {
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phan

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

    class OSSMail_GetMail_Action extends \App\Controller\Action

    The class OSSMail_GetMail_Action is not named in CamelCase.
    Open

    class OSSMail_GetMail_Action extends \App\Controller\Action
    {
        /**
         * Function to check permission.
         *
    Severity: Minor
    Found in modules/OSSMail/actions/GetMail.php by phpmd

    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

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

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

         * Function to check permission.

    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

            $moduleName = $request->getModule();

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

            $sourceModule = $request->getByType('sourceModule', 2);

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

                    if (1 === $maxEmails) {

    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

         *

    Line exceeds 120 characters; contains 135 characters
    Open

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

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

            $emailFields = OSSMailScanner_Record_Model::getEmailSearch($sourceModule);

    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

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

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

            foreach ($emailFields as $emailField) {

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

                $response->setResult($email);

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

            $userPrivilegesModel = Users_Privileges_Model::getCurrentUserPrivilegesModel();

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

            if (!$userPrivilegesModel->hasModulePermission($moduleName)) {

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

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

    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

                        'fieldlabel' => App\Language::translate($emailField['fieldlabel'], $emailField['name']),

    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

         * @param \App\Request $request

    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

                        'email' => $email,

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

                        'name' => $name,

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

                $email = $recordModel->get($emailField['fieldname']);

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

                $viewer->assign('EMAILS', $emails);

    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

                $viewController = new Vtiger_Index_View();

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

                $email = '';

    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\NoPermittedToRecord('ERR_NO_PERMISSIONS_FOR_THE_RECORD', 406);

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

            $sourceRecord = $request->getInteger('sourceRecord');

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

            $recordModel = Vtiger_Record_Model::getInstanceById($sourceRecord, $sourceModule);

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

                if (1 == \count($emails)) {

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

            }

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

            $emails = [];

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

                        break;

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

         * @throws \App\Exceptions\NoPermitted

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

            $maxEmails = $request->has('maxEmails') ? $request->getInteger('maxEmails') : 0;

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

                    $emails[] = [

    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 (\count($emails) > 1) {

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

                $response = new Vtiger_Response();

    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

            $name = $recordModel->getName();

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

                if (!empty($email)) {

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

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

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

                    $email = $emails[0]['email'];

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

                $response->emit();

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

    class OSSMail_GetMail_Action extends \App\Controller\Action

    There are no issues that match your filters.

    Category
    Status