YetiForceCompany/YetiForceCRM

View on GitHub
app/TextParser/RelatedRecordsData.php

Summary

Maintainability
B
4 hrs
Test Coverage
F
0%

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

    public function process()
    {
        $data = [];
        [$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
        if (is_numeric($relationId)) {
Severity: Minor
Found in app/TextParser/RelatedRecordsData.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 process has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process()
    {
        $data = [];
        [$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
        if (is_numeric($relationId)) {
Severity: Minor
Found in app/TextParser/RelatedRecordsData.php - About 1 hr to fix

    The method process() has an NPath complexity of 1152. The configured NPath complexity threshold is 200.
    Open

        public function process()
        {
            $data = [];
            [$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
            if (is_numeric($relationId)) {
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phpmd

    NPathComplexity

    Since: 0.1

    The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

    Example

    class Foo {
        function bar() {
            // lots of complicated code
        }
    }

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

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

        public function process()
        {
            $data = [];
            [$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
            if (is_numeric($relationId)) {
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phpmd

    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 17 to the 15 allowed.
    Open

        public function process()
    Severity: Critical
    Found in app/TextParser/RelatedRecordsData.php by sonar-php

    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

    Avoid using static access to class '\App\Privilege' in method 'process'.
    Open

                || !\App\Privilege::isPermitted($relatedModuleName)
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.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\Json' in method 'process'.
    Open

                $relationListView->set('search_rel_params', \App\Json::decode($relConditions));
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.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\Relation' in method 'process'.
    Open

                $relationId = \App\Relation::getRelationId($this->textParser->moduleName, $relatedModuleName);
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.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\Json' in method 'process'.
    Open

                $transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($conditions));
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.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\Relation' in method 'process'.
    Open

    }
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.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 assigning values to variables in if clauses and the like (line '45', column '9').
    Open

        public function process()
        {
            $data = [];
            [$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');
            if (is_numeric($relationId)) {
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phpmd

    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

    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 {
                $relatedModuleName = $relationId;
                $relationId = \App\Relation::getRelationId($this->textParser->moduleName, $relatedModuleName);
            }
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.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 '\Vtiger_RelationListView_Model' in method 'process'.
    Open

                || !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.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

    Reference to instance property recordModel from undeclared class \App\TextParser
    Open

            if (!$this->textParser->recordModel
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phan

    Reference to instance property recordModel from undeclared class \App\TextParser
    Open

                if ($id === $this->textParser->recordModel->getId()) {
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phan

    Argument 1 (relationId) is '' but \App\Relation::getById() takes int defined at /code/app/Relation.php:76
    Open

                $relatedModuleName = \App\Relation::getById($relationId)['related_modulename'] ?? '';
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phan

    Argument 3 (relationId) is ?''|?int but \Vtiger_RelationListView_Model::getInstance() takes bool|false|int defined at /code/modules/Vtiger/models/RelationListView.php:142
    Open

                || !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phan

    Reference to instance property recordModel from undeclared class \App\TextParser
    Open

                || !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phan

    Call to method parseBaseSearchParamsToCondition from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                $transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($conditions));
    Severity: Critical
    Found in app/TextParser/RelatedRecordsData.php by phan

    Call to method setLimit from undeclared class \App\QueryGenerator (Did you mean class \Tests\App\QueryGenerator)
    Open

                $relationListView->getQueryGenerator()->setLimit((int) $limit);
    Severity: Critical
    Found in app/TextParser/RelatedRecordsData.php by phan

    Reference to instance property moduleName from undeclared class \App\TextParser
    Open

                $relationId = \App\Relation::getRelationId($this->textParser->moduleName, $relatedModuleName);
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phan

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

                $transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($conditions));
    Severity: Minor
    Found in app/TextParser/RelatedRecordsData.php by phpmd

    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

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

            $data = [];

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

                $relationListView->set('orderby', $orderBy);

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

        public $name = 'LBL_RECORDS_LIST_DATA_TEMPLATE';

    Line exceeds 120 characters; contains 177 characters
    Open

        public $default = "YFParser('\$(custom : RelatedRecordsData|__RELATION_MODULE_OR_RELATION_ID__|__FIELDS__|__CONDITIONS__|__LIMIT__|__ORDER_BY__|__RELATION_CONDITION__)\$')";

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

                $relatedModuleName = $relationId;

    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

            } else {

    Line exceeds 120 characters; contains 144 characters
    Open

                $transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($conditions));

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

            if (!empty($limit)) {

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

            if ($relConditions) {

    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

                $relationId = \App\Relation::getRelationId($this->textParser->moduleName, $relatedModuleName);

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

            }

    Line exceeds 120 characters; contains 146 characters
    Open

                || !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))

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

            $fields = explode(',', $fields);

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

            if (is_numeric($relationId)) {

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

            if (!$this->textParser->recordModel

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

                $relationListView->set('search_rel_params', \App\Json::decode($relConditions));

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

            if ($orderBy) {

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

                        $data[$id][$fieldModel->getName()] = $fieldModel->getDisplayValue($relatedRecordModel->get($fieldModel->getName()), $id, $relatedRecordModel, true);

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

            if ($conditions) {

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

                $relationListView->set('search_params', $transformedSearchParams);

    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 ($fieldsModel as $fieldModel) {

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

            return $data;

    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

            $fieldsModel = array_intersect_key($relationListView->getHeaders(), array_flip($fields));

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

            foreach ($relationListView->getAllEntries() as $id => $relatedRecordModel) {

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

                    continue;

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

                    if ($fieldModel->get('fromOutsideList') || $fieldModel->isViewable()) {

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

         * Process.

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

        /** @var mixed Parser type */

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

        public function process()

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

                $transformedSearchParams = $relationListView->getQueryGenerator()->parseBaseSearchParamsToCondition(\App\Json::decode($conditions));

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

                $relatedModuleName = \App\Relation::getById($relationId)['related_modulename'] ?? '';

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

            $relationListView->setFields($fields);

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

                }

    Line exceeds 120 characters; contains 168 characters
    Open

                        $data[$id][$fieldModel->getName()] = $fieldModel->getDisplayValue($relatedRecordModel->get($fieldModel->getName()), $id, $relatedRecordModel, true);

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

        /** @var string Class name */

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

        /** @var string Default template */

    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

                $relationListView->getQueryGenerator()->setLimit((int) $limit);

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

         */

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

            [$relationId, $fields, $conditions, $limit, $orderBy, $relConditions] = array_pad($this->params, 6, '');

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

            }

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

                || !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName, $relationId))

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

                return $data;

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

                if ($id === $this->textParser->recordModel->getId()) {

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

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

                || !\App\Privilege::isPermitted($relatedModuleName)

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

            $data = [];

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

        public $default = "YFParser('\$(custom : RelatedRecordsData|__RELATION_MODULE_OR_RELATION_ID__|__FIELDS__|__CONDITIONS__|__LIMIT__|__ORDER_BY__|__RELATION_CONDITION__)\$')";

    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