YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
B
6 hrs
Test Coverage
F
0%

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

    public function doTask($rawRecordModel)
    {
        $recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());
        $recordModel->setData($rawRecordModel->getData());
        $recordModel->ext = $rawRecordModel->ext;
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTUpdateFieldsTask.php - About 4 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 45 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function doTask($rawRecordModel)
    {
        $recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());
        $recordModel->setData($rawRecordModel->getData());
        $recordModel->ext = $rawRecordModel->ext;
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTUpdateFieldsTask.php - About 1 hr to fix

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

        public function doTask($rawRecordModel)
        {
            $recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());
            $recordModel->setData($rawRecordModel->getData());
            $recordModel->ext = $rawRecordModel->ext;

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

        public function doTask($rawRecordModel)

    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 '50', column '27').
    Open

                        $exprEvaluater = new VTFieldExpressionEvaluater($expression);

    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

    Missing class import via use statement (line '48', column '43').
    Open

                        $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

    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

    Missing class import via use statement (line '48', column '20').
    Open

                        $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

    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

    Missing class import via use statement (line '48', column '71').
    Open

                        $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

    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

    The method doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                    } else {
                        if (preg_match('/([^:]+):boolean$/', $fieldValue, $match)) {
                            $fieldValue = $match[1];
                            if ('true' == $fieldValue) {
                                $fieldValue = '1';

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

            $recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());

    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

    The method doTask uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

                            } else {
                                $fieldValue = '0';
                            }

    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 '\App\Json' in method 'doTask'.
    Open

                $fieldValueMapping = \App\Json::decode($this->field_value_mapping);

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

                    $recordModel->set($fieldName, App\Purifier::decodeHtml($fieldValue));

    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 undeclared property \VTUpdateFieldsTask->field_value_mapping (Did you mean $fieldValueMapping)
    Open

            if (!empty($this->field_value_mapping)) {

    Reference to undeclared property \VTUpdateFieldsTask->field_value_mapping (Did you mean $fieldValueMapping)
    Open

                $fieldValueMapping = \App\Json::decode($this->field_value_mapping);

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

    class VTUpdateFieldsTask extends VTTask

    A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 13 and the first side effect is on line 11.
    Open

    <?php

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

            return ['field_value_mapping'];

    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($fieldValueMapping) && \count($fieldValueMapping) > 0) {

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

                foreach ($fieldValueMapping as $fieldInfo) {

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

                    $fieldValueType = $fieldInfo['valuetype'];

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

                    } elseif ('fieldname' === $fieldValueType) {

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

                            if ('true' == $fieldValue) {

    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

            $recordModel->setData($rawRecordModel->getData());

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

            $recordModel->isNew = false;

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

                    $fieldValue = trim($fieldInfo['value']);

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

                        $fieldValue = $exprEvaluater->evaluate($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

                        $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

    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 doTask($rawRecordModel)

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

                            $fieldValue = $match[1];

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

                    $recordModel->set($fieldName, App\Purifier::decodeHtml($fieldValue));

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

        /**

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

                    $fieldName = $fieldInfo['fieldname'];

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

                $fieldValueMapping = \App\Json::decode($this->field_value_mapping);

    Line exceeds 120 characters; contains 122 characters
    Open

                        $parser = new VTExpressionParser(new VTExpressionSpaceFilter(new VTExpressionTokenizer($fieldValue)));

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

                                $fieldValue = '0';

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

                    $recordModel->setHandlerExceptions(['disableHandlerClasses' => ['Vtiger_Workflow_Handler']]);

    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

                        require_once 'modules/com_vtiger_workflow/expression_engine/include.php';

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

    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

                        continue;

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

                    if ('expression' === $fieldValueType) {

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

                    foreach (array_keys($recordModel->getPreviousValue()) as $fieldName) {

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

            $recordModel->ext = $rawRecordModel->ext;

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

            $fieldValueMapping = [];

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

                    if (!isset($moduleFields[$fieldName]) || !$moduleFields[$fieldName]->isActiveField()) {

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

                        $exprEvaluater = new VTFieldExpressionEvaluater($expression);

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

         * @param Vtiger_Record_Model $rawRecordModel

    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

                    $recordModel->save();

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

        public $executeImmediately = 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

                        $fieldValue = $recordModel->get($fieldValue);

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

        {

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

            $moduleFields = $recordModel->getModule()->getFields();

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

            if (!empty($this->field_value_mapping)) {

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

                        $expression = $parser->expression();

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

                                $fieldValue = '1';

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

                }

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

                        $rawRecordModel->set($fieldName, $recordModel->get($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

            $recordModel = \Vtiger_Record_Model::getCleanInstance($rawRecordModel->getModuleName());

    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

                        if (preg_match('/([^:]+):boolean$/', $fieldValue, $match)) {

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

            }

    There are no issues that match your filters.

    Category
    Status