YetiForceCompany/YetiForceCRM

View on GitHub
modules/Calendar/views/SendInvitationModal.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

Function getStructure has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    public function getStructure(): array
    {
        $structure = [];
        $moduleName = $this->recordModel->getModuleName();
        $textParser = App\TextParser::getInstanceByModel($this->recordModel);
Severity: Minor
Found in modules/Calendar/views/SendInvitationModal.php - About 2 hrs 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

Method getStructure has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getStructure(): array
    {
        $structure = [];
        $moduleName = $this->recordModel->getModuleName();
        $textParser = App\TextParser::getInstanceByModel($this->recordModel);
Severity: Minor
Found in modules/Calendar/views/SendInvitationModal.php - About 1 hr to fix

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

        public function getStructure(): array
        {
            $structure = [];
            $moduleName = $this->recordModel->getModuleName();
            $textParser = App\TextParser::getInstanceByModel($this->recordModel);

    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

    Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed.
    Open

        public function getStructure(): array

    Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

    See

    Missing class import via use statement (line '31', column '14').
    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

    Avoid assigning values to variables in if clauses and the like (line '63', column '7').
    Open

        public function getStructure(): array
        {
            $structure = [];
            $moduleName = $this->recordModel->getModuleName();
            $textParser = App\TextParser::getInstanceByModel($this->recordModel);

    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

    Avoid using static access to class '\App\Language' in method 'getStructure'.
    Open

                        $structure[$blockName][$field['var_value']] = \App\Language::translate($field['label'], $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 '\App\Language' in method 'getStructure'.
    Open

                    $structure[\App\Language::translate('Other', $moduleName)][implode(',', $emails)] = \App\Language::translate('LBL_INVITE_RECORDS', $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 '\App\Language' in method 'getStructure'.
    Open

                    $blockName = \App\Language::translate($blockName, $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 '\App\Privilege' in method 'getStructure'.
    Open

                    if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {

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

                    $structure[\App\Language::translate('Other', $moduleName)][implode(',', $emails)] = \App\Language::translate('LBL_INVITE_RECORDS', $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 '70', column '10').
    Open

        public function getStructure(): array
        {
            $structure = [];
            $moduleName = $this->recordModel->getModuleName();
            $textParser = App\TextParser::getInstanceByModel($this->recordModel);

    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

    Avoid using static access to class '\App\Record' in method 'getStructure'.
    Open

                    if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {

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

            $this->recordModel = $request->isEmpty('record') ? null : \Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());

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

            if (!$this->recordModel || !($this->recordModel->isEditable() && \App\Mail::checkInternalMailClient())) {

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

        public function getStructure(): array
        {
            $structure = [];
            $moduleName = $this->recordModel->getModuleName();
            $textParser = App\TextParser::getInstanceByModel($this->recordModel);

    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

    Avoid using static access to class 'App\TextParser' in method 'getStructure'.
    Open

            $textParser = App\TextParser::getInstanceByModel($this->recordModel);

    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\Record' in method 'getStructure'.
    Open

                    if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {

    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\Record' in method 'getStructure'.
    Open

                        $name = trim(\App\Record::getLabel($crmId));

    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

    Class extends undeclared class \App\Controller\Modal
    Open

    class Calendar_SendInvitationModal_View extends \App\Controller\Modal

    Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
    Open

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

    Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
    Open

            $textParser = App\TextParser::getInstanceByModel($this->recordModel);

    Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
    Open

            $this->recordModel = $request->isEmpty('record') ? null : \Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());

    Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
    Open

            if ($invites = $this->recordModel->getInvities()) {

    Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
    Open

            $moduleName = $this->recordModel->getModuleName();

    Reference to undeclared property \Calendar_SendInvitationModal_View->recordModel
    Open

            if (!$this->recordModel || !($this->recordModel->isEditable() && \App\Mail::checkInternalMailClient())) {

    Call to undeclared method \Calendar_SendInvitationModal_View::getViewer
    Open

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

    Call to method getInstanceByModel from undeclared class \App\TextParser (Did you mean class \Tests\App\TextParser)
    Open

            $textParser = App\TextParser::getInstanceByModel($this->recordModel);

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

    class Calendar_SendInvitationModal_View extends \App\Controller\Modal

    The class Calendar_SendInvitationModal_View is not named in CamelCase.
    Open

    class Calendar_SendInvitationModal_View extends \App\Controller\Modal
    {
        /** {@inheritdoc} */
        protected $pageTitle = 'LBL_SEND_CALENDAR';
        /** {@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

            $viewer->assign('FIELDS', $this->getStructure());

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

         *

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

                    $structure[\App\Language::translate('Other', $moduleName)][implode(',', $emails)] = \App\Language::translate('LBL_INVITE_RECORDS', $moduleName);

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

        public $modalIcon = 'yfi-send-invitation';

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

            if ($invites = $this->recordModel->getInvities()) {

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

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

                    foreach ($fields as $field) {

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

        }

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

            $textParser = App\TextParser::getInstanceByModel($this->recordModel);

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

                    if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {

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

        public $successBtn = 'LBL_SEND';

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

            $moduleName = $this->recordModel->getModuleName();

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

                    $blockName = \App\Language::translate($blockName, $moduleName);

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

            $viewer->view('Modals/SendInvitationModal.tpl', $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

                    if (($email = $invite['email'])) {

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

                        $emails[] = $name ? "{$name} <{$email}>" : $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

        protected $pageTitle = 'LBL_SEND_CALENDAR';

    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

         * Gets structure.

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

         * @return array

    Line exceeds 120 characters; contains 121 characters
    Open

                        $structure[$blockName][$field['var_value']] = \App\Language::translate($field['label'], $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

            if (!$this->recordModel || !($this->recordModel->isEditable() && \App\Mail::checkInternalMailClient())) {

    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 160 characters
    Open

                    $structure[\App\Language::translate('Other', $moduleName)][implode(',', $emails)] = \App\Language::translate('LBL_INVITE_RECORDS', $moduleName);

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

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

                    $name = trim($invite['name']);

    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

            return $structure;

    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

            foreach ($textParser->getRelatedVariable('email', true) as $modules) {

    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

            $this->recordModel = $request->isEmpty('record') ? null : \Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $request->getModule());

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

                foreach ($modules as $blockName => $fields) {

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

                        $name = trim(\App\Record::getLabel($crmId));

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

                    }

    Line exceeds 120 characters; contains 159 characters
    Open

            $this->recordModel = $request->isEmpty('record') ? null : \Vtiger_Record_Model::getInstanceById($request->getInteger('record'), $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

        {

    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('EMAIL_FIELD_OPTION', $this->getStructure());

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

                        $structure[$blockName][$field['var_value']] = \App\Language::translate($field['label'], $moduleName);

    Line exceeds 120 characters; contains 176 characters
    Open

                    if (!$name && ($crmId = $invite['crmid']) && \App\Record::isExists($crmId) && \App\Privilege::isPermitted(\App\Record::getType($crmId), 'DetailView', $crmId)) {

    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

        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

         */

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

            $structure = [];

    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 ($invites as $invite) {

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

                if ($emails) {

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

                }

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

    class Calendar_SendInvitationModal_View extends \App\Controller\Modal

    There are no issues that match your filters.

    Category
    Status