YetiForceCompany/YetiForceCRM

View on GitHub
modules/OSSTimeControl/textparsers/DetailedList.php

Summary

Maintainability
C
1 day
Test Coverage
F
0%

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

    public function process()
    {
        $moduleModel = Vtiger_Module_Model::getInstance($this->textParser->moduleName);
        $fields = $moduleModel->getFields();
        $ids = $this->textParser->getParam('pdf')->getVariable('recordsId');
Severity: Minor
Found in modules/OSSTimeControl/textparsers/DetailedList.php - About 3 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 63 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function process()
    {
        $moduleModel = Vtiger_Module_Model::getInstance($this->textParser->moduleName);
        $fields = $moduleModel->getFields();
        $ids = $this->textParser->getParam('pdf')->getVariable('recordsId');
Severity: Major
Found in modules/OSSTimeControl/textparsers/DetailedList.php - About 2 hrs to fix

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

        public function process()
        {
            $moduleModel = Vtiger_Module_Model::getInstance($this->textParser->moduleName);
            $fields = $moduleModel->getFields();
            $ids = $this->textParser->getParam('pdf')->getVariable('recordsId');

    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()
        {
            $moduleModel = Vtiger_Module_Model::getInstance($this->textParser->moduleName);
            $fields = $moduleModel->getFields();
            $ids = $this->textParser->getParam('pdf')->getVariable('recordsId');

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

        public function process()

    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

    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 {
                        $value = $recordModel->getDisplayValue($columnName);
                    }

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

                $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $this->textParser->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 'process'.
    Open

                    $html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $this->textParser->moduleName) . '</th>';

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

            $moduleModel = Vtiger_Module_Model::getInstance($this->textParser->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\Fields\RangeTime' in method 'process'.
    Open

                    $content = '<strong>' . \App\Fields\RangeTime::displayElapseTime($summary['sum_time']) . '</strong>';

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

                    $content = '<strong>' . \App\Language::translate('LBL_SUMMARY', $this->textParser->moduleName) . ':' . '</strong>';

    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\Fields\DateTime' in method 'process'.
    Open

                        $value = \App\Fields\DateTime::formatToDisplay($recordModel->getDisplayValue($columnName) . ' ' . $recordModel->getDisplayValue('time_start'));

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

            foreach (['name',  'date_start', 'time_start', 'assigned_user_id', 'sum_time'] as $fieldName) {

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

            foreach (['name',  'date_start', 'time_start', 'assigned_user_id', 'sum_time'] as $fieldName) {

    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.

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

            $moduleModel = Vtiger_Module_Model::getInstance($this->textParser->moduleName);

    Invalid offset "sum_time" of array type array{}
    Open

                        $summary['sum_time'] = $summary['sum_time'] ?? 0;

    Call to deprecated function \Vtiger_Field_Model::getFieldLabel() defined at /code/modules/Vtiger/models/Field.php:215
    Open

                    $html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $this->textParser->moduleName) . '</th>';

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

                    $content = '<strong>' . \App\Language::translate('LBL_SUMMARY', $this->textParser->moduleName) . ':' . '</strong>';

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

                    $html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $this->textParser->moduleName) . '</th>';

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

            $ids = $this->textParser->getParam('pdf')->getVariable('recordsId');

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

                $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $this->textParser->moduleName);

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

            foreach ($columns as $column) {
                $style = $bodyStyle;
                $columnName = $column->getName();
                $content = '';
                if ('sum_time' === $columnName) {
    Severity: Major
    Found in modules/OSSTimeControl/textparsers/DetailedList.php and 1 other location - About 2 hrs to fix
    modules/OSSTimeControl/textparsers/List.php on lines 66..77

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 136.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

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

    class OSSTimeControl_DetailedList_Textparser extends \App\TextParser\Base

    The class OSSTimeControl_DetailedList_Textparser is not named in CamelCase.
    Open

    class OSSTimeControl_DetailedList_Textparser extends \App\TextParser\Base
    {
        /** @var string Class name */
        public $name = 'LBL_TIME_CONTROL_DETAILED_LIST';
    
    

    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

            $ids = $this->textParser->getParam('pdf')->getVariable('recordsId');

    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

                }

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

            }

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

            $summary = [];

    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

                $fieldModel = $fields[$fieldName];

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

                    $columns[$fieldModel->getName()] = $fieldModel;

    Line exceeds 120 characters; contains 163 characters
    Open

                        $value = \App\Fields\DateTime::formatToDisplay($recordModel->getDisplayValue($columnName) . ' ' . $recordModel->getDisplayValue('time_start'));

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

                $html .= "<td style=\"{$style}\">" . $content . '</td>';

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

            return $html;

    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

                if ('sum_time' === $columnName) {

    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 (!\is_array($ids)) {

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

            $html .= '<table border="1" class="products-table" style="border-collapse:collapse;width:100%;"><thead><tr>';

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

            $columns = [];

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

                foreach ($columns as $column) {

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

                    }

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

                    $content = '<strong>' . \App\Fields\RangeTime::displayElapseTime($summary['sum_time']) . '</strong>';

    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

                    $styleDate = $bodyStyle . 'text-align:center;';

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

                $html .= '</tr>';

    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 mixed Parser type */

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

                $ids = [$ids];

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

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

    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

            $html = '';

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

                        $style = $styleDate;

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

                        $summary['sum_time'] += $recordModel->get($columnName);

    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

                $html .= '<tr>';

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

                    $html .= "<td style=\"{$style}\">" . $value . '</td>';

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

                $columnName = $column->getName();

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

         */

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

            $bodyStyle = 'font-size:8px;border:1px solid #ddd;padding:0px4px;';

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

            $html .= '</tr></thead><tbody>';

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

                        $style = $styleDate;

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

                    } else {

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

                    if ('sum_time' === $columnName) {

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

            $html .= '</tr></tfoot></table>';

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

        public $name = 'LBL_TIME_CONTROL_DETAILED_LIST';

    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

            }

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

            foreach (['name',  'date_start', 'time_start', 'assigned_user_id', 'sum_time'] as $fieldName) {

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

                if (!$fieldModel || !$fieldModel->isActiveField()) {

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

                    $style = $bodyStyle;

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

                }

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

                $style = $bodyStyle;

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

                    $content = '<strong>' . \App\Language::translate('LBL_SUMMARY', $this->textParser->moduleName) . ':' . '</strong>';

    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

                    $columnName = $column->getName();

    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

                $content = '';

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

                        $value = \App\Fields\DateTime::formatToDisplay($recordModel->getDisplayValue($columnName) . ' ' . $recordModel->getDisplayValue('time_start'));

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

            foreach ($columns as $column) {

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

            $headerStyle = 'font-size:9px;padding:0px 4px;text-align:center;';

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

            foreach ($ids as $recordId) {

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

                $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $this->textParser->moduleName);

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

                        $summary['sum_time'] = $summary['sum_time'] ?? 0;

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

            $html .= '</tbody><tfoot><tr>';

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

                } elseif ('name' === $columnName) {

    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 ('time_start' !== $fieldName) {

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

                    if ('date_start' === $columnName) {

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

                        $value = $recordModel->getDisplayValue($columnName);

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

        }

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

            $moduleModel = Vtiger_Module_Model::getInstance($this->textParser->moduleName);

    Line exceeds 120 characters; contains 155 characters
    Open

                    $html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $this->textParser->moduleName) . '</th>';

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

                    $style = $bodyStyle . 'text-align:center;';

    Line exceeds 120 characters; contains 131 characters
    Open

                    $content = '<strong>' . \App\Language::translate('LBL_SUMMARY', $this->textParser->moduleName) . ':' . '</strong>';

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

            $fields = $moduleModel->getFields();

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

                }

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

                    $html .= "<th style=\"{$headerStyle}\">" . \App\Language::translate($fieldModel->getFieldLabel(), $this->textParser->moduleName) . '</th>';

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

            }

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

    class OSSTimeControl_DetailedList_Textparser extends \App\TextParser\Base

    There are no issues that match your filters.

    Category
    Status