YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

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

    public function doTask($recordModel)
    {
        $entityId = $recordModel->getId();

        $delta = $recordModel->getPreviousValue();
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTUpdateCalendarDates.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

Method doTask has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function doTask($recordModel)
    {
        $entityId = $recordModel->getId();

        $delta = $recordModel->getPreviousValue();
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTUpdateCalendarDates.php - About 1 hr to fix

    Refactor this function to reduce its Cognitive Complexity from 18 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 '45', column '16').
    Open

                $task = new \ArrayObject(unserialize($row['task']));

    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 '42', column '17').
    Open

            $query = (new \App\Db\Query())->from('vtiger_activity_update_dates')->innerJoin('com_vtiger_workflowtasks', 'com_vtiger_workflowtasks.task_id = vtiger_activity_update_dates.task_id')->where(['vtiger_activity_update_dates.parent' => $entityId]);

    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 {
                    $baseDateEnd = $recordModel->get($task['datefield_end']);
                    if ('' === $baseDateEnd) {
                        $baseDateEnd = date('Y-m-d');
                    }

    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

                $rowRecordModel = Vtiger_Record_Model::getInstanceById($row['activityid'], 'Calendar');

    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 {
                    $baseDateStart = $recordModel->get($task['datefield_start']);
                    if ('' === $baseDateStart) {
                        $baseDateStart = date('Y-m-d');
                    }

    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

    Call to undeclared method \App\Db\Query::from
    Open

            $query = (new \App\Db\Query())->from('vtiger_activity_update_dates')->innerJoin('com_vtiger_workflowtasks', 'com_vtiger_workflowtasks.task_id = vtiger_activity_update_dates.task_id')->where(['vtiger_activity_update_dates.parent' => $entityId]);

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

    class VTUpdateCalendarDates extends VTTask

    Line exceeds 120 characters; contains 162 characters
    Open

                $date_start = strftime('%Y-%m-%d', $baseDateStart + $task['days_start'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 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

         *

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

                    $baseDateEnd = date('Y-m-d H:i:s');

    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

         */

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

         * @var bool

    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

            while ($row = $dataReader->read()) {

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

                    if ('' === $baseDateEnd) {

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

                }

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

                $date_start = strftime('%Y-%m-%d', $baseDateStart + $task['days_start'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 1));

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

            $entityId = $recordModel->getId();

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

            $dataReader = $query->createCommand()->query();

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

                    $baseDateStart = date('Y-m-d H:i:s');

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

        }

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

                        $baseDateStart = date('Y-m-d');

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

                if ('wfRunTime' === $task['datefield_end']) {

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

                    $baseDateEnd = $recordModel->get($task['datefield_end']);

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

                    $baseDateStart = $recordModel->get($task['datefield_start']);

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

                $baseDateEnd = strtotime($match[0]);

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

            $delta = $recordModel->getPreviousValue();

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

                $baseDateStart = strtotime($match[0]);

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

                $rowRecordModel->save();

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

                        $baseDateEnd = date('Y-m-d');

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

                $due_date = strftime('%Y-%m-%d', $baseDateEnd + $task['days_end'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 1));

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

                $rowRecordModel->set('due_date', $due_date);

    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 array

    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

        public function doTask($recordModel)

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

                    if ('' === $baseDateStart) {

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

                $rowRecordModel->set('date_start', $date_start);

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

         * Execute immediately.

    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

        /**

    Line exceeds 120 characters; contains 252 characters
    Open

            $query = (new \App\Db\Query())->from('vtiger_activity_update_dates')->innerJoin('com_vtiger_workflowtasks', 'com_vtiger_workflowtasks.task_id = vtiger_activity_update_dates.task_id')->where(['vtiger_activity_update_dates.parent' => $entityId]);

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

                $task = new \ArrayObject(unserialize($row['task']));

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

         * Get field names.

    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

                return;

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

                $rowRecordModel = Vtiger_Record_Model::getInstanceById($row['activityid'], 'Calendar');

    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

        public function getFieldNames()

    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

                    }

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

                preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDateEnd, $match);

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

         */

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

                preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDateStart, $match);

    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

            if (!$delta) {

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

            $query = (new \App\Db\Query())->from('vtiger_activity_update_dates')->innerJoin('com_vtiger_workflowtasks', 'com_vtiger_workflowtasks.task_id = vtiger_activity_update_dates.task_id')->where(['vtiger_activity_update_dates.parent' => $entityId]);

    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

                if ('wfRunTime' === $task['datefield_start']) {

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

                    }

    Line exceeds 120 characters; contains 156 characters
    Open

                $due_date = strftime('%Y-%m-%d', $baseDateEnd + $task['days_end'] * 24 * 60 * 60 * ('before' == strtolower($task['direction_start']) ? -1 : 1));

    The variable $date_start is not named in camelCase.
    Open

        public function doTask($recordModel)
        {
            $entityId = $recordModel->getId();
    
            $delta = $recordModel->getPreviousValue();

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $due_date is not named in camelCase.
    Open

        public function doTask($recordModel)
        {
            $entityId = $recordModel->getId();
    
            $delta = $recordModel->getPreviousValue();

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $date_start is not named in camelCase.
    Open

        public function doTask($recordModel)
        {
            $entityId = $recordModel->getId();
    
            $delta = $recordModel->getPreviousValue();

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    The variable $due_date is not named in camelCase.
    Open

        public function doTask($recordModel)
        {
            $entityId = $recordModel->getId();
    
            $delta = $recordModel->getPreviousValue();

    CamelCaseVariableName

    Since: 0.2

    It is considered best practice to use the camelCase notation to name variables.

    Example

    class ClassName {
        public function doSomething() {
            $data_module = new DataModule();
        }
    }

    Source

    There are no issues that match your filters.

    Category
    Status