YetiForceCompany/YetiForceCRM

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

Summary

Maintainability
D
1 day
Test Coverage
F
0%

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

    public function doTask($recordModel)
    {
        if (!\App\Module::isModuleActive('Calendar')) {
            return;
        }
Severity: Minor
Found in modules/com_vtiger_workflow/tasks/VTCreateEventTask.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 doTask has 72 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function doTask($recordModel)
    {
        if (!\App\Module::isModuleActive('Calendar')) {
            return;
        }
Severity: Major
Found in modules/com_vtiger_workflow/tasks/VTCreateEventTask.php - About 2 hrs to fix

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

        public function doTask($recordModel)
        {
            if (!\App\Module::isModuleActive('Calendar')) {
                return;
            }

    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 15. The configured cyclomatic complexity threshold is 10.
    Open

        public function doTask($recordModel)
        {
            if (!\App\Module::isModuleActive('Calendar')) {
                return;
            }

    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 22 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

    The class VTCreateEventTask has a coupling between objects value of 13. Consider to reduce the number of dependencies under 13.
    Open

    class VTCreateEventTask extends VTTask
    {
        public $executeImmediately = true;
    
        public function getFieldNames()

    CouplingBetweenObjects

    Since: 1.1.0

    A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

    Example

    class Foo {
        /**
         * @var \foo\bar\X
         */
        private $x = null;
    
        /**
         * @var \foo\bar\Y
         */
        private $y = null;
    
        /**
         * @var \foo\bar\Z
         */
        private $z = null;
    
        public function setFoo(\Foo $foo) {}
        public function setBar(\Bar $bar) {}
        public function setBaz(\Baz $baz) {}
    
        /**
         * @return \SplObjectStorage
         * @throws \OutOfRangeException
         * @throws \InvalidArgumentException
         * @throws \ErrorException
         */
        public function process(\Iterator $it) {}
    
        // ...
    }

    Source https://phpmd.org/rules/design.html#couplingbetweenobjects

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

                $userExists = (new App\Db\Query())->from('vtiger_users')

    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 '57', column '24').
    Open

                    $groupExist = (new App\Db\Query())->from('vtiger_groups')

    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 '132', column '15').
    Open

            $date = new DateTime();

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

                $userId = \App\User::getCurrentUserId();

    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 '90', column '8').
    Open

        public function doTask($recordModel)
        {
            if (!\App\Module::isModuleActive('Calendar')) {
                return;
            }

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

        public function doTask($recordModel)
        {
            if (!\App\Module::isModuleActive('Calendar')) {
                return;
            }

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

            if (!\App\Module::isModuleActive('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

    Avoid using static access to class 'Users' in method 'doTask'.
    Open

                $userId = Users::getActiveAdminUser();

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

                    $parentModuleName = \App\Record::getType($parentRecord);

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

            $field = \App\ModuleHierarchy::getMappingRelatedField($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\Record' in method 'doTask'.
    Open

            if ($parentRecord = \App\Record::getParentRecord($id)) {

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

            $newRecordModel = Vtiger_Record_Model::getCleanInstance('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

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

            $relationModel = \Vtiger_Relation_Model::getInstance($recordModel->getModule(), $newRecordModel->getModule());

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

                $field = \App\ModuleHierarchy::getMappingRelatedField($parentModuleName);

    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 'DateTimeField' in method 'convertToDBFormat'.
    Open

            $dbInsertDateTime = DateTimeField::convertToDBTimeZone($date->format('Y-m-d') . ' ' . $time);

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

            $textParser = \App\TextParser::getInstanceByModel($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 using static access to class '\App\Record' in method 'doTask'.
    Open

                $parentModuleName = \App\Record::getType($parentRecord);

    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 {
                    $groupExist = (new App\Db\Query())->from('vtiger_groups')
                        ->where(['groupid' => $this->assigned_user_id])
                        ->exists();
                    if ($groupExist) {

    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\Fields\Time' in method 'convertToDBFormat'.
    Open

            $time = \App\Fields\Time::sanitizeDbFormat($timeStr);

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

                if ($parentRecord = \App\Record::getParentRecord($parentRecord)) {

    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 conv12to24hour uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
    Open

            } else {
                $hours = ((int) $arr[1]) % 12 + 12;
            }

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

                    $field = \App\ModuleHierarchy::getMappingRelatedField($parentModuleName);

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

                'status', 'priority', 'assigned_user_id', ];

    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 undeclared property \VTCreateEventTask->startDays
    Open

            $startDate = $this->calculateDate($recordModel, $this->startDays, $this->startDirection, $this->startDatefield);

    Reference to undeclared property \VTCreateEventTask->endDirection
    Open

            $endDate = $this->calculateDate($recordModel, $this->endDays, $this->endDirection, $this->endDatefield);

    Reference to undeclared property \VTCreateEventTask->assigned_user_id
    Open

                        $userId = $this->assigned_user_id;

    Reference to undeclared property \VTCreateEventTask->description
    Open

                'description' => $textParser->setContent($this->description)->parse()->getContent(),

    Reference to undeclared property \VTCreateEventTask->startDirection
    Open

            $startDate = $this->calculateDate($recordModel, $this->startDays, $this->startDirection, $this->startDatefield);

    Reference to undeclared property \VTCreateEventTask->endTime
    Open

                'time_end' => self::convertToDBFormat($this->endTime),

    Reference to undeclared property \VTCreateEventTask->startDatefield
    Open

            $startDate = $this->calculateDate($recordModel, $this->startDays, $this->startDirection, $this->startDatefield);

    Reference to undeclared property \VTCreateEventTask->assigned_user_id
    Open

            } elseif (!empty($this->assigned_user_id)) { // Added to check if the user/group is active

    Reference to undeclared property \VTCreateEventTask->assigned_user_id
    Open

                        ->where(['groupid' => $this->assigned_user_id])

    Reference to undeclared property \VTCreateEventTask->eventType
    Open

                'activitytype' => $this->eventType,

    Reference to undeclared property \VTCreateEventTask->assigned_user_id
    Open

            } elseif ('triggerUser' === $this->assigned_user_id) {

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

                $userExists = (new App\Db\Query())->from('vtiger_users')

    Reference to undeclared property \VTCreateEventTask->eventName
    Open

                'subject' => $textParser->setContent($this->eventName)->parse()->getContent(),

    Reference to undeclared property \VTCreateEventTask->priority
    Open

                'taskpriority' => $this->priority,

    Return type of convertToDBFormat() is undeclared type \time
    Open

        public static function convertToDBFormat($timeStr)

    Argument 1 (input) is int but \str_pad() takes string
    Open

            return str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($arr[2], 2, '0', STR_PAD_LEFT);

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

                    $groupExist = (new App\Db\Query())->from('vtiger_groups')

    Reference to undeclared property \VTCreateEventTask->startTime
    Open

                'time_start' => self::convertToDBFormat($this->startTime),

    Reference to undeclared property \VTCreateEventTask->endDatefield
    Open

            $endDate = $this->calculateDate($recordModel, $this->endDays, $this->endDirection, $this->endDatefield);

    Call to method getCurrentUserId from undeclared class \App\User (Did you mean class \Tests\App\User)
    Open

                $userId = \App\User::getCurrentUserId();

    Reference to undeclared property \Vtiger_Record_Model->executeUser
    Open

                $userId = $recordModel->executeUser;

    Reference to undeclared property \VTCreateEventTask->assigned_user_id
    Open

                    $userId = $this->assigned_user_id;

    Reference to undeclared property \VTCreateEventTask->assigned_user_id
    Open

                    ->where(['id' => $this->assigned_user_id, 'status' => 'Active'])

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

            $textParser = \App\TextParser::getInstanceByModel($recordModel);

    Reference to undeclared property \VTCreateEventTask->endDays
    Open

            $endDate = $this->calculateDate($recordModel, $this->endDays, $this->endDirection, $this->endDatefield);

    Returning type string but convertToDBFormat() is declared to return \time
    Open

            return $dbInsertDateTime->format('H:i:s');

    Reference to undeclared property \VTCreateEventTask->assigned_user_id
    Open

            } elseif ('copyParentOwner' === $this->assigned_user_id) {

    Reference to undeclared property \VTCreateEventTask->status
    Open

                'activitystatus' => $this->status,

    Reference to undeclared property \VTCreateEventTask->assigned_user_id
    Open

            if ('currentUser' === $this->assigned_user_id) {

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

            if ('currentUser' === $this->assigned_user_id) {
                $userId = \App\User::getCurrentUserId();
            } elseif ('triggerUser' === $this->assigned_user_id) {
                $userId = $recordModel->executeUser;
            } elseif ('copyParentOwner' === $this->assigned_user_id) {
    Severity: Major
    Found in modules/com_vtiger_workflow/tasks/VTCreateEventTask.php and 1 other location - About 4 hrs to fix
    modules/com_vtiger_workflow/tasks/VTCreateTodoTask.php on lines 63..83

    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 178.

    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

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

        public static function conv12to24hour($timeStr)
        {
            $arr = [];
            preg_match('/(\d{1,2}):(\d{1,2})(am|pm)/', $timeStr, $arr);
            if ('am' == $arr[3]) {
    Severity: Major
    Found in modules/com_vtiger_workflow/tasks/VTCreateEventTask.php and 1 other location - About 2 hrs to fix
    modules/com_vtiger_workflow/tasks/VTCreateTodoTask.php on lines 193..203

    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 139.

    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

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

            if ($parentRecord = \App\Record::getParentRecord($id)) {
                $parentModuleName = \App\Record::getType($parentRecord);
                $field = \App\ModuleHierarchy::getMappingRelatedField($parentModuleName);
                if ($field) {
                    $fields[$field] = $parentRecord;
    Severity: Major
    Found in modules/com_vtiger_workflow/tasks/VTCreateEventTask.php and 1 other location - About 1 hr to fix
    modules/com_vtiger_workflow/tasks/VTCreateTodoTask.php on lines 160..173

    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 105.

    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 VTCreateEventTask 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 14 and the first side effect is on line 10.
    Open

    <?php

    Avoid variables with short names like $id. Configured minimum length is 3.
    Open

            $id = $recordModel->getId();

    ShortVariable

    Since: 0.2

    Detects when a field, local, or parameter has a very short name.

    Example

    class Something {
        private $q = 15; // VIOLATION - Field
        public static function main( array $as ) { // VIOLATION - Formal
            $r = 20 + $this->q; // VIOLATION - Local
            for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                $r += $this->q;
            }
        }
    }

    Source https://phpmd.org/rules/naming.html#shortvariable

    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

                'date_start' => $startDate,

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

            $newRecordModel = Vtiger_Record_Model::getCleanInstance('Calendar');

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

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

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

            $fields = [

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

                'taskpriority' => $this->priority,

    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 ($parentRecord = \App\Record::getParentRecord($id)) {

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

         * To convert time_start & time_end values to db format.

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

         * @param string $timeStr

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

            if (!\App\Module::isModuleActive('Calendar')) {

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

                $userId = Users::getActiveAdminUser();

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

            $endDate = $this->calculateDate($recordModel, $this->endDays, $this->endDirection, $this->endDatefield);

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

            if ($field) {

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

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

    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

         * Execute task.

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

                        ->where(['groupid' => $this->assigned_user_id])

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

                'subject' => $textParser->setContent($this->eventName)->parse()->getContent(),

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

                if ($field) {

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

            $relationModel = \Vtiger_Relation_Model::getInstance($recordModel->getModule(), $newRecordModel->getModule());

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

                $relationModel->addRelation($recordModel->getId(), $newRecordModel->getId());

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

            $arr = [];

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

            return ['startTime', 'endTime'];

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

        {

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

            $moduleName = $recordModel->getModuleName();

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

            $textParser = \App\TextParser::getInstanceByModel($recordModel);

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

            $id = $recordModel->getId();

    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

            preg_match('/\d\d\d\d-\d\d-\d\d/', $baseDate, $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

                if ($userExists) {

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

                'activitystatus' => $this->status,

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

                if ($parentRecord = \App\Record::getParentRecord($parentRecord)) {

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

            $newRecordModel->save();

    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

                        $userId = $this->assigned_user_id;

    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 time

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

            $date = new DateTime();

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

            preg_match('/(\d{1,2}):(\d{1,2})(am|pm)/', $timeStr, $arr);

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

            return ['eventType', 'eventName', 'description', 'sendNotification',

    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

                    ->exists();

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

                    }

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

            $field = \App\ModuleHierarchy::getMappingRelatedField($moduleName);

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

                $parentModuleName = \App\Record::getType($parentRecord);

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

                $days = 0;

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

        public static function convertToDBFormat($timeStr)

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

         */

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

            $userId = $recordModel->get('assigned_user_id');

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

            $startDate = $this->calculateDate($recordModel, $this->startDays, $this->startDirection, $this->startDatefield);

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

                'time_start' => self::convertToDBFormat($this->startTime),

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

                'time_end' => self::convertToDBFormat($this->endTime),

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

                'due_date' => $endDate,

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

                $fields[$field] = $id;

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

        }

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

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

    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 strftime('%Y-%m-%d', $baseDate + $days * 24 * 60 * 60 *

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

            $dbInsertDateTime = DateTimeField::convertToDBTimeZone($date->format('Y-m-d') . ' ' . $time);

    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

                $hours = ((int) $arr[1]) % 12 + 12;

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

        public function getTimeFieldList()

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

            if (null === $userId) {

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

            } elseif ('triggerUser' === $this->assigned_user_id) {

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

                $userId = $recordModel->get('assigned_user_id');

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

                    $parentModuleName = \App\Record::getType($parentRecord);

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

            if ('' == $days) {

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

                ('before' == strtolower($direction) ? -1 : 1));

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

        public static function conv12to24hour($timeStr)

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

        {

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

                $userExists = (new App\Db\Query())->from('vtiger_users')

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

        private function calculateDate($recordModel, $days, $direction, $datefield)

    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

         */

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

            if ('am' == $arr[3]) {

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

                $userId = \App\User::getCurrentUserId();

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

                    ->where(['id' => $this->assigned_user_id, 'status' => 'Active'])

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

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

                }

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

                'activitytype' => $this->eventType,

    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 $dbInsertDateTime->format('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

                'status', 'priority', 'assigned_user_id', ];

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

            } elseif ('copyParentOwner' === $this->assigned_user_id) {

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

                    $userId = $this->assigned_user_id;

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

                    }

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

            $newRecordModel->setData($fields);

    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

                'endTime', 'endDays', 'endDirection', 'endDatefield',

    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

                    $groupExist = (new App\Db\Query())->from('vtiger_groups')

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

            $baseDate = $recordModel->get($datefield);

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

            if ('' == $baseDate) {

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

            $time = \App\Fields\Time::sanitizeDbFormat($timeStr);

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

            return str_pad($hours, 2, '0', STR_PAD_LEFT) . ':' . str_pad($arr[2], 2, '0', STR_PAD_LEFT);

    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

                $userId = $recordModel->executeUser;

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

            } elseif (!empty($this->assigned_user_id)) { // Added to check if the user/group is active

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

                        ->exists();

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

            }

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

                'description' => $textParser->setContent($this->description)->parse()->getContent(),

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

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

            }

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

                'startTime', 'startDays', 'startDirection', 'startDatefield',

    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

        {

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

            if ('currentUser' === $this->assigned_user_id) {

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

                'assigned_user_id' => $userId,

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

                'duration_hours' => 0,

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

                $field = \App\ModuleHierarchy::getMappingRelatedField($parentModuleName);

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

                    $fields[$field] = $parentRecord;

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

                    $field = \App\ModuleHierarchy::getMappingRelatedField($parentModuleName);

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

                    if ($field) {

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

                        $fields[$field] = $parentRecord;

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

                $hours = ((int) $arr[1]) % 12;

    There are no issues that match your filters.

    Category
    Status