YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/models/RecordPopover.php

Summary

Maintainability
A
2 hrs
Test Coverage
F
0%

Method getHeaderLinks has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getHeaderLinks(): array
    {
        $links = [];
        $detailUrl = $this->recordModel->getFullDetailViewUrl();
        $editUrl = $this->recordModel->isEditable() ? $this->recordModel->getEditViewUrl() : '';
Severity: Minor
Found in modules/Vtiger/models/RecordPopover.php - About 1 hr to fix

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

        public function getFields(): array
        {
            $summaryFields = [];
            $fields = $this->recordModel->getModule()->getFields();
            foreach ($fields as $fieldName => $fieldModel) {
    Severity: Minor
    Found in modules/Vtiger/models/RecordPopover.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 getFields() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
    Open

        public function getFields(): array
        {
            $summaryFields = [];
            $fields = $this->recordModel->getModule()->getFields();
            foreach ($fields as $fieldName => $fieldModel) {

    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

    Avoid unused local variables such as '$fieldLabel'.
    Open

                foreach ($this->recordModel->getEntity()->list_fields_name as $fieldLabel => $fieldName) {

    UnusedLocalVariable

    Since: 0.2

    Detects when a local variable is declared and/or assigned, but not used.

    Example

    class Foo {
        public function doSomething()
        {
            $i = 5; // Unused
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

    Reference to undeclared property \CRMEntity->list_fields_name
    Open

                foreach ($this->recordModel->getEntity()->list_fields_name as $fieldLabel => $fieldName) {

    Avoid using static access to class 'Vtiger_Record_Model' in method 'getInstance'.
    Open

            $instance->setRecord(Vtiger_Record_Model::getInstanceById($recordId, $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 'Vtiger_Link_Model' in method 'getHeaderLinks'.
    Open

                $linksModels[] = Vtiger_Link_Model::getInstanceFromValues($link);

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

            $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'RecordPopover', $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

    Define a constant instead of duplicating this literal "RECORD_POPOVER_VIEW" 3 times.
    Open

                        'linktype' => 'RECORD_POPOVER_VIEW',

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

                        'linkclass' => 'btn-sm btn-outline-primary js-quick-edit-modal',

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

                        'linkicon' => 'yfi yfi-quick-creation',

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

                        'linktype' => 'RECORD_POPOVER_VIEW',

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

                        'linklabel' => 'LBL_QUICK_EDIT',

    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.

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

    class Vtiger_RecordPopover_Model extends \App\Base

    The class Vtiger_RecordPopover_Model is not named in CamelCase.
    Open

    class Vtiger_RecordPopover_Model extends \App\Base
    {
        /**
         * Model of record which is display.
         *

    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

         * Model of record which is display.

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

         *

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

         * Function to get model of view "RecordPopover".

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

        public static function getInstance(string $moduleName, int $recordId): self

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

         * @return \Vtiger_Record_Model

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

        public function getHeaderLinks(): array

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

            $links = [];

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

                        'linkclass' => 'btn-sm btn-outline-primary js-quick-edit-modal',

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

                            'record' => $this->recordModel->getId(),

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

                $linksModels[] = Vtiger_Link_Model::getInstanceFromValues($link);

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

        }

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

         * Returns list of fields to display.

    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

                    'linklabel' => 'LBL_EDIT',

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

            }

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

                    'linkurl' => $detailUrl,

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

        public function getFields(): array

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

            $summaryFields = [];

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

                if (!$this->recordModel->isEmpty($fieldName) && $fieldModel->isSummaryField() && $fieldModel->isViewableInDetailView()) {

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

         * @param int    $recordId

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

         * @throws \App\Exceptions\AppException

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

        }

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

                        'linkicon' => 'yfi yfi-quick-creation',

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

                    'linkclass' => 'btn-sm btn-outline-secondary js-calendar-popover__button',

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

                    'linkclass' => 'btn-sm btn-outline-secondary js-calendar-popover__button',

    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 = $this->recordModel->getModule()->getFields();

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

                    if ($fieldModel && !$this->recordModel->isEmpty($fieldName) && $fieldModel->isViewableInDetailView()) {

    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

         */

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

                        'linktype' => 'RECORD_POPOVER_VIEW',

    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 [];

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

            return $this->recordModel;

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

            $detailUrl = $this->recordModel->getFullDetailViewUrl();

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

            if ($this->recordModel->isEditable()) {

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

                if ($this->recordModel->getModule()->isQuickCreateSupported()) {

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

                    'linkicon' => 'yfi yfi-full-editing-view',

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

         */

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

                    $summaryFields[$fieldName] = $fieldModel;

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

                        $summaryFields[$fieldName] = $fieldModel;

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

         * @return array

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

         * @var Vtiger_Record_Model

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

            $this->recordModel = $recordModel;

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

                        'linklabel' => 'LBL_QUICK_EDIT',

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

            $linksModels = [];

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

            return $linksModels;

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

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

        {

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

            $instance->setRecord(Vtiger_Record_Model::getInstanceById($recordId, $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

        public function setRecord(Vtiger_Record_Model $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

         * Returns array with model of buttons.

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

                    'linktype' => 'RECORD_POPOVER_VIEW',

    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

        /**

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

        public function getFieldsIcon(): array

    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

            $instance = new $modelClassName();

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

            return $instance;

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

         * @return void

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

        {

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

            $editUrl = $this->recordModel->isEditable() ? $this->recordModel->getEditViewUrl() : '';

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

                    'linktype' => 'RECORD_POPOVER_VIEW',

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

            if ($this->recordModel->isViewable()) {

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

                    'linkhref' => true,

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

        /**

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

            $modelClassName = Vtiger_Loader::getComponentClassName('Model', 'RecordPopover', $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

                    'linkhref' => true,

    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 of module.

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

         * @var string

    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 \Vtiger_Record_Model $recordModel

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

        public function getRecord(): Vtiger_Record_Model

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

                ];

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

         * Returns icons for fields.

    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

         * @param string $moduleName

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

         * Gets model of record.

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

                }

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

                $links[] = [

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

         * @return \Vtiger_Field_Model[]

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

         *

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

            $instance->moduleName = $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

                    $links[] = [

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

                $links[] = [

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

                    'linkurl' => $editUrl,

    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 (!$summaryFields) {

    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

        {

    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 Vtiger_Link_Model[]

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

                            'module' => $this->recordModel->getModuleName(),

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

                    'linkicon' => 'fas fa-th-list',

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

                    $fieldModel = $fields[$fieldName] ?? '';

    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

         * @return \Vtiger_RecordPopover_Model

    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

                        'linkdata' => [

    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 ($links as $link) {

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

            return $summaryFields;

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

        /**

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

         * Sets model of record.

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

                    'linklabel' => 'DetailView',

    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 $fieldName => $fieldModel) {

    Line exceeds 120 characters; contains 133 characters
    Open

                if (!$this->recordModel->isEmpty($fieldName) && $fieldModel->isSummaryField() && $fieldModel->isViewableInDetailView()) {

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

                foreach ($this->recordModel->getEntity()->list_fields_name as $fieldLabel => $fieldName) {

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

        }

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

    class Vtiger_RecordPopover_Model extends \App\Base

    There are no issues that match your filters.

    Category
    Status