YetiForceCompany/YetiForceCRM

View on GitHub
app/TextParser/RelatedAttachments.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

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

    public function process(): string
    {
        $relatedModuleName = 'Documents';
        if (!$this->textParser->recordModel
            || !\App\Privilege::isPermitted($relatedModuleName)
Severity: Minor
Found in app/TextParser/RelatedAttachments.php - About 1 hr to fix

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

        public function process(): string
        {
            $relatedModuleName = 'Documents';
            if (!$this->textParser->recordModel
                || !\App\Privilege::isPermitted($relatedModuleName)
    Severity: Minor
    Found in app/TextParser/RelatedAttachments.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 process() has an NPath complexity of 4864. The configured NPath complexity threshold is 200.
    Open

        public function process(): string
        {
            $relatedModuleName = 'Documents';
            if (!$this->textParser->recordModel
                || !\App\Privilege::isPermitted($relatedModuleName)
    Severity: Minor
    Found in app/TextParser/RelatedAttachments.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 19. The configured cyclomatic complexity threshold is 10.
    Open

        public function process(): string
        {
            $relatedModuleName = 'Documents';
            if (!$this->textParser->recordModel
                || !\App\Privilege::isPermitted($relatedModuleName)
    Severity: Minor
    Found in app/TextParser/RelatedAttachments.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 19 to the 15 allowed.
    Open

        public function process(): string
    Severity: Critical
    Found in app/TextParser/RelatedAttachments.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 assigning values to variables in if clauses and the like (line '70', column '10').
    Open

        public function process(): string
        {
            $relatedModuleName = 'Documents';
            if (!$this->textParser->recordModel
                || !\App\Privilege::isPermitted($relatedModuleName)
    Severity: Minor
    Found in app/TextParser/RelatedAttachments.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

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

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

                || !($relationListView = \Vtiger_RelationListView_Model::getInstance($this->textParser->recordModel, $relatedModuleName))
    Severity: Minor
    Found in app/TextParser/RelatedAttachments.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 '71', column '10').
    Open

        public function process(): string
        {
            $relatedModuleName = 'Documents';
            if (!$this->textParser->recordModel
                || !\App\Privilege::isPermitted($relatedModuleName)
    Severity: Minor
    Found in app/TextParser/RelatedAttachments.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

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

        public function process(): string
        {
            $relatedModuleName = 'Documents';
            if (!$this->textParser->recordModel
                || !\App\Privilege::isPermitted($relatedModuleName)
    Severity: Minor
    Found in app/TextParser/RelatedAttachments.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

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

        public function process(): string
        {
            $relatedModuleName = 'Documents';
            if (!$this->textParser->recordModel
                || !\App\Privilege::isPermitted($relatedModuleName)
    Severity: Minor
    Found in app/TextParser/RelatedAttachments.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

    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/RelatedAttachments.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

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

            $fields = $fields ?: ['notes_title', 'filename'];
    Severity: Critical
    Found in app/TextParser/RelatedAttachments.php by sonar-php

    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.

    Call to undeclared method \Vtiger_Record_Model::getFileDetails
    Open

                  && ($info = $relatedRecordModel->getFileDetails())
    Severity: Critical
    Found in app/TextParser/RelatedAttachments.php by phan

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

            if (!$this->textParser->recordModel
    Severity: Minor
    Found in app/TextParser/RelatedAttachments.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/RelatedAttachments.php by phan

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

            $pdf = $attachFiles ? $this->textParser->getParam('pdf') : null;
    Severity: Critical
    Found in app/TextParser/RelatedAttachments.php by phan

    Call to undeclared method \Vtiger_Record_Model::checkFileIntegrity
    Open

                if ($pdf && $relatedRecordModel->checkFileIntegrity()
    Severity: Critical
    Found in app/TextParser/RelatedAttachments.php by phan

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

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

        /** @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

        /** @var string Class name */

    Line exceeds 120 characters; contains 133 characters
    Open

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

    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 $default = '$(custom : RelatedAttachments|__FIELD_NAMES__|__CONDITIONS__|__ATTACH_FILES__)$';

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

         *

    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

            }

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

         */

    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

                if ($pdf && $relatedRecordModel->checkFileIntegrity()

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

                  && ($filePath = $info['path'] . $info['attachmentsid'])

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

         * @return string

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

        public function process(): string

    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

                return '';

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

                if (!($fieldModel = $relationListView->getRelatedModuleModel()->getFieldByName($field)) || !$fieldModel->isActiveField()) {

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

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

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

                    $row[] = 'filename' === $fieldName ? "({$value})" : $value;

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

            }

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

            $counter = 0;

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

                  && !isset($pdf->attachFiles[$filePath])

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

            $relatedModuleName = 'Documents';

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

                $rows[] = "{$counter}. " . implode(', ', $row);

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

            if (trim($conditions)) {

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

                }

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

                    $pdf->attachFiles[$filePath] = ['name' => $info['name'], 'path' => $filePath];

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

         * Process.

    Line exceeds 120 characters; contains 135 characters
    Open

                if (!($fieldModel = $relationListView->getRelatedModuleModel()->getFieldByName($field)) || !$fieldModel->isActiveField()) {

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

            $rows = [];

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

                    $value = $relatedRecordModel->getDisplayValue($fieldName, false, true);

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

                  && ($info = $relatedRecordModel->getFileDetails())

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

        public $name = 'LBL_RELATED_ATTACHMENTS';

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

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

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

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

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

                $row = [];

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

            $relationListView->setFields(array_unique(array_merge($fields, ['notes_title', 'filename', 'filelocationtype'])));

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

                foreach ($fields as $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

            foreach ($fields as $key => $field) {

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

            return empty($rows) ? '' : implode('<br>', $rows);

    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

            [$fields, $conditions, $attachFiles] = array_pad($this->params, 3, '');

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

            $pdf = $attachFiles ? $this->textParser->getParam('pdf') : null;

    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

            $fields = $fields ?: ['notes_title', 'filename'];

    Line exceeds 120 characters; contains 122 characters
    Open

            $relationListView->setFields(array_unique(array_merge($fields, ['notes_title', 'filename', 'filelocationtype'])));

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

                ) {

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

                    unset($fields[$key]);

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

                }

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

                    $value = trim($value);

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

    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

                ++$counter;

    There are no issues that match your filters.

    Category
    Status