YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
1 hr
Test Coverage
F
0%

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

    public function getStructure(): array
    {
        $summaryFieldsList = $this->getModule()->getSummaryViewFieldsList();
        $recordModel = $this->getRecord();
        $fieldsDependency = \App\FieldsDependency::getByRecordModel('Detail', $recordModel);
Severity: Minor
Found in modules/Vtiger/models/SummaryRecordStructure.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

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

        $fieldsDependency = \App\FieldsDependency::getByRecordModel('Detail', $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 excessively long variable names like $summaryFieldModelsList. Keep variable name length under 20.
Open

        $summaryFieldModelsList = [];

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

Avoid excessively long variable names like $blockSeqSortSummaryFields. Keep variable name length under 20.
Open

        $blockSeqSortSummaryFields = [];

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

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

class Vtiger_SummaryRecordStructure_Model extends Vtiger_DetailRecordStructure_Model

The class Vtiger_SummaryRecordStructure_Model is not named in CamelCase.
Open

class Vtiger_SummaryRecordStructure_Model extends Vtiger_DetailRecordStructure_Model
{
    /**
     * Function to get the values in structured format.
     *

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

                    $fieldModel->set('fieldvalue', $recordModel->get($fieldName));

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

     * @return array - values in structure array('block'=>array(fieldinfo));

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

        $blockSeqSortSummaryFields = [];

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 (!empty($fieldsDependency['hide']['frontend']) && \in_array($fieldName, $fieldsDependency['hide']['frontend'])) {

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

        $recordModel = $this->getRecord();

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

        ksort($blockSeqSortSummaryFields);

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 $summaryFieldModelsList;

Line exceeds 120 characters; contains 173 characters
Open

                if ($fieldModel->isViewableInDetailView() && (empty($fieldsDependency['hide']['backend']) || !\in_array($fieldName, $fieldsDependency['hide']['backend']))) {

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

        foreach ($blockSeqSortSummaryFields as $blockSequence => $summaryFields) {

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

                        $fieldModel->set('hideField', 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

    public function getStructure(): array

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

        if ($summaryFieldsList) {

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

                    $blockSequence = $fieldModel->block->sequence;

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

                    $blockSeqSortSummaryFields[$blockSequence]['SUMMARY_FIELDS'][$fieldName] = $fieldModel;

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

     * Function to get the values in structured format.

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

     */

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

        $summaryFieldsList = $this->getModule()->getSummaryViewFieldsList();

Line exceeds 120 characters; contains 136 characters
Open

                    if (!empty($fieldsDependency['hide']['frontend']) && \in_array($fieldName, $fieldsDependency['hide']['frontend'])) {

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

                if ($fieldModel->isViewableInDetailView() && (empty($fieldsDependency['hide']['backend']) || !\in_array($fieldName, $fieldsDependency['hide']['backend']))) {

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

            $summaryFieldModelsList = array_replace_recursive($summaryFieldModelsList, $summaryFields);

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

        $fieldsDependency = \App\FieldsDependency::getByRecordModel('Detail', $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

            foreach ($summaryFieldsList as $fieldName => $fieldModel) {

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

        $summaryFieldModelsList = [];

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

class Vtiger_SummaryRecordStructure_Model extends Vtiger_DetailRecordStructure_Model

There are no issues that match your filters.

Category
Status