YetiForceCompany/YetiForceCRM

View on GitHub
modules/com_vtiger_workflow/tasks/VTUpdateWorkTime.php

Summary

Maintainability
A
3 hrs
Test Coverage
C
72%

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

    public function doTask($recordModel)
    {
        $referenceFields = $recordModel->getModule()->getFieldsByReference();
        $referenceIds = [];
        foreach ($referenceFields as $fieldModel) {
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTUpdateWorkTime.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 doTask has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function doTask($recordModel)
    {
        $referenceFields = $recordModel->getModule()->getFieldsByReference();
        $referenceIds = [];
        foreach ($referenceFields as $fieldModel) {
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTUpdateWorkTime.php - About 1 hr to fix

    The method doTask() has an NPath complexity of 204. The configured NPath complexity threshold is 200.
    Open

        public function doTask($recordModel)
        {
            $referenceFields = $recordModel->getModule()->getFieldsByReference();
            $referenceIds = [];
            foreach ($referenceFields as $fieldModel) {

    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 doTask() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10.
    Open

        public function doTask($recordModel)
        {
            $referenceFields = $recordModel->getModule()->getFieldsByReference();
            $referenceIds = [];
            foreach ($referenceFields as $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

    Refactor this function to reduce its Cognitive Complexity from 20 to the 15 allowed.
    Open

        public function doTask($recordModel)

    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

    Missing class import via use statement (line '51', column '10').
    Open

                    (new \OSSTimeControl_TimeCounting_Model($metaData['setype'], $referenceId, $referenceIds[$referenceId]))->recalculateTimeControl();

    MissingImport

    Since: 2.7.0

    Importing all external classes in a file through use statements makes them clearly visible.

    Example

    function make() {
        return new \stdClass();
    }

    Source http://phpmd.org/rules/cleancode.html#MissingImport

    Avoid using static access to class 'App\ModuleHierarchy' in method 'doTask'.
    Open

            $modulesHierarchy = array_keys(App\ModuleHierarchy::getModulesHierarchy());

    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 'vtlib\Functions' in method 'doTask'.
    Open

            $metasData = vtlib\Functions::getCRMRecordMetadata(array_keys($referenceIds));

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

                $this->contents = \App\Json::encode($delta);

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

            $delta = \App\Json::decode($this->getContents($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 assigning values to variables in if clauses and the like (line '29', column '8').
    Open

        public function doTask($recordModel)
        {
            $referenceFields = $recordModel->getModule()->getFieldsByReference();
            $referenceIds = [];
            foreach ($referenceFields as $fieldModel) {

    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

    Assigning string to property but \VTUpdateWorkTime->contents is \Vtiger_Record_Model
    Open

                $this->contents = \App\Json::encode($delta);

    Declaration of function getContents(\Vtiger_Record_Model $recordModel) : string should be compatible with function getContents(\Vtiger_Record_Model $recordModel) : \Vtiger_Record_Model defined in /code/modules/com_vtiger_workflow/VTTask.php:63
    Open

        public function getContents($recordModel)

    Returning type \Vtiger_Record_Model but getContents() is declared to return string
    Open

            return $this->contents;

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

        public static $workflowIdsAlreadyDone = [];

    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 VTUpdateWorkTime extends VTTask

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

            $referenceIds = array_diff_key($referenceIds, array_flip(static::$workflowIdsAlreadyDone));

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

         * Function to get contents of this task.

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

        public function getFieldNames()

    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

            $referenceIds = [];

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

                    $referenceIds[$value] = $fieldModel->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

        }

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

         * @return string contents

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

    Line exceeds 120 characters; contains 126 characters
    Open

                $delta = array_intersect_key($recordModel->getPreviousValue(), $recordModel->getModule()->getFieldsByReference());

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

            if (!$this->contents && \is_object($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

                $this->contents = \App\Json::encode($delta);

    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 static $workflowIdsAlreadyDone = [];

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

                    if (!empty($values) && !\is_array($values)) {

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

                    if (\is_array($values) && $values['currentValue']) {

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

                }

    Line exceeds 120 characters; contains 147 characters
    Open

                    (new \OSSTimeControl_TimeCounting_Model($metaData['setype'], $referenceId, $referenceIds[$referenceId]))->recalculateTimeControl();

    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 getContents($recordModel)

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

         * Execute task.

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

            if (\is_array($delta)) {

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

                foreach ($delta as $fieldName => $values) {

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

                        $referenceIds[$values] = $fieldName;

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

                        $referenceIds[$values['oldValue']] = $fieldName;

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

                        $referenceIds[$values['currentValue']] = $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

                }

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

            $referenceFields = $recordModel->getModule()->getFieldsByReference();

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

            $modulesHierarchy = array_keys(App\ModuleHierarchy::getModulesHierarchy());

    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 $this->contents;

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

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

                    } elseif (\is_array($values) && $values['oldValue']) {

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

                if (0 === ((int) $metaData['deleted']) && \in_array($metaData['setype'], $modulesHierarchy)) {

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

                    static::$workflowIdsAlreadyDone[] = $referenceId;

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

         *

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

                $delta = array_intersect_key($recordModel->getPreviousValue(), $recordModel->getModule()->getFieldsByReference());

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

        public $executeImmediately = false;

    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 ($metasData as $referenceId => $metaData) {

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

                    (new \OSSTimeControl_TimeCounting_Model($metaData['setype'], $referenceId, $referenceIds[$referenceId]))->recalculateTimeControl();

    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

         */

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

            $delta = \App\Json::decode($this->getContents($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

            $metasData = vtlib\Functions::getCRMRecordMetadata(array_keys($referenceIds));

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

        public function doTask($recordModel)

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

                if ($value = $recordModel->get($fieldModel->getName())) {

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

                    }

    There are no issues that match your filters.

    Category
    Status