YetiForceCompany/YetiForceCRM

View on GitHub
modules/Vtiger/models/WorkflowTrigger.php

Summary

Maintainability
A
3 hrs
Test Coverage
F
0%

Method getTreeWorkflows has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

     public static function getTreeWorkflows(string $moduleName, int $recordId): array
     {
         \Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
         $tree = [];
         $workflowModuleName = 'Settings:Workflows';
Severity: Minor
Found in modules/Vtiger/models/WorkflowTrigger.php - About 1 hr to fix

    Function getTreeWorkflows has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

         public static function getTreeWorkflows(string $moduleName, int $recordId): array
         {
             \Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
             $tree = [];
             $workflowModuleName = 'Settings:Workflows';
    Severity: Minor
    Found in modules/Vtiger/models/WorkflowTrigger.php - About 55 mins 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

    Function execute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

         public static function execute(string $moduleName, int $record, $userId, array $actions = [])
         {
             \Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
             $recordModel = \Vtiger_Record_Model::getInstanceById($record, $moduleName);
             if ($userId) {
    Severity: Minor
    Found in modules/Vtiger/models/WorkflowTrigger.php - About 45 mins 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

    Missing class import via use statement (line '30', column '15').
    Open

             $wfs = new VTWorkflowManager();

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

             $workflows = (new VTWorkflowManager())->getWorkflowsForModule($moduleName, VTWorkflowManager::$TRIGGER);

    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 '\Vtiger_Loader' in method 'getTreeWorkflows'.
    Open

             \Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');

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

                     if (!$workflow->params || !($params = \App\Json::decode($workflow->params)) || empty($params['showTasks']) || empty($params['enableTasks'])) {

    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 'Settings_Workflows_Record_Model' in method 'getTreeWorkflows'.
    Open

                 $workflowRecord = Settings_Workflows_Record_Model::getInstanceFromWorkflowObject($workflow);

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\Language' in method 'getTreeWorkflows'.
    Open

                         'text' => ' ' . \App\Language::translate($task->getTaskObject()->summary, $workflowModuleName),

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

             $recordModel = Vtiger_Record_Model::getInstanceById($recordId);

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

    Source https://phpmd.org/rules/cleancode.html#staticaccess

    Avoid using static access to class '\App\Language' in method 'getTreeWorkflows'.
    Open

                     'text' => ' ' . \App\Language::translate($workflow->description, $workflowModuleName),

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

         public static function execute(string $moduleName, int $record, $userId, array $actions = [])
         {
             \Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');
             $recordModel = \Vtiger_Record_Model::getInstanceById($record, $moduleName);
             if ($userId) {

    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 '\Vtiger_Loader' in method 'execute'.
    Open

             \Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');

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

                 $params = $workflow->params ? \App\Json::decode($workflow->params) : [];

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

             $recordModel = \Vtiger_Record_Model::getInstanceById($record, $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

    Define a constant instead of duplicating this literal "category" 4 times.
    Open

                     'type' => 'category',

    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 \Workflow->id
    Open

                     'record_id' => $workflow->id,

    Reference to undeclared property \Workflow->params
    Open

                 $params = $workflow->params ? \App\Json::decode($workflow->params) : [];

    Reference to undeclared property \Workflow->description
    Open

                     'text' => ' ' . \App\Language::translate($workflow->description, $workflowModuleName),

    Argument 2 (executionCondition) is int but \VTWorkflowManager::getWorkflowsForModule() takes false|string defined at /code/modules/com_vtiger_workflow/VTWorkflowManager.php:180
    Open

             $workflows = (new VTWorkflowManager())->getWorkflowsForModule($moduleName, VTWorkflowManager::$TRIGGER);

    Reference to instance property params from undeclared class \A
    Open

                     if (!$workflow->params || !($params = \App\Json::decode($workflow->params)) || empty($params['showTasks']) || empty($params['enableTasks'])) {

    Call to method performTasks from undeclared class \A
    Open

                     $workflow->performTasks($recordModel, $tasks);
    Severity: Critical
    Found in modules/Vtiger/models/WorkflowTrigger.php by phan

    Reference to undeclared property \Workflow->id
    Open

                     'id' => $workflow->id,

    Reference to undeclared property \Vtiger_Record_Model->executeUser
    Open

                 $recordModel->executeUser = $userId;

    Call to method evaluate from undeclared class \A
    Open

                 if ($workflow->evaluate($recordModel)) {
    Severity: Critical
    Found in modules/Vtiger/models/WorkflowTrigger.php by phan

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

     class Vtiger_WorkflowTrigger_Model

    The class Vtiger_WorkflowTrigger_Model is not named in CamelCase.
    Open

     class Vtiger_WorkflowTrigger_Model
     {
         /**
          * Function executes workflow tasks.
          *

    CamelCaseClassName

    Since: 0.2

    It is considered best practice to use the CamelCase notation to name classes.

    Example

    class class_name {
    }

    Source

    Expected 0 spaces before opening brace; 1 found
    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 (!$workflow->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

                         'record_id' => $task->getId(),

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

                         'parent' => $workflowRecord->getId(),

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

                         'category' => ['checked' => false]

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

             foreach ($actions as $id => $tasks) {

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

                 $workflow = $wfs->retrieve($id);

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

             \Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');

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

             $recordModel = Vtiger_Record_Model::getInstanceById($recordId);

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

                     continue;

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

             }

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

          * @param int    $userId

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

             $recordModel = \Vtiger_Record_Model::getInstanceById($record, $moduleName);

    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 ($workflows as $workflow) {

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

                 $workflowRecord = Settings_Workflows_Record_Model::getInstanceFromWorkflowObject($workflow);

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

                         'id' => ++$index,

    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 $tree;

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

             $tree = [];

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

         public static function execute(string $moduleName, int $record, $userId, array $actions = [])

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

                 if ($workflow->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

                     'record_id' => $workflow->id,

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

                     'state' => ['selected' => false, 'disabled' => false, 'loaded' => true, 'opened' => false],

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

                 $params = $workflow->params ? \App\Json::decode($workflow->params) : [];

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

                         'type' => 'category',

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

                 }

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

          * Function executes workflow tasks.

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

          *

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

                     $workflow->performTasks($recordModel, $tasks);

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

                         $tasks = null;

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

                     'parent' => '#',

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

                         'state' => ['selected' => false, 'disabled' => empty($params['enableTasks'])],

    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

                     'category' => ['checked' => 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

          * @param int    $record

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

          */

    Line exceeds 120 characters; contains 158 characters
    Open

                     if (!$workflow->params || !($params = \App\Json::decode($workflow->params)) || empty($params['showTasks']) || empty($params['enableTasks'])) {

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

                         'attr' => 'task',

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

                 $recordModel->executeUser = $userId;

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

                     }

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

             $index = max(array_column($workflows, '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

                 if (empty($params['showTasks'])) {

    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 int    $recordId

    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

                     'attr' => 'record',

    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 string $moduleName

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

             $wfs = new VTWorkflowManager();

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

             $workflows = (new VTWorkflowManager())->getWorkflowsForModule($moduleName, VTWorkflowManager::$TRIGGER);

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

                     'type' => 'category',

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

                 ];

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

                     $tree[] = [

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

          *

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

             $workflowModuleName = 'Settings:Workflows';

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

                     'text' => ' ' . \App\Language::translate($workflow->description, $workflowModuleName),

    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

         public static function getTreeWorkflows(string $moduleName, int $recordId): array

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

                 $tree[] = [

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

                     'id' => $workflow->id,

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

             if ($userId) {

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

                     if (!$workflow->params || !($params = \App\Json::decode($workflow->params)) || empty($params['showTasks']) || empty($params['enableTasks'])) {

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

          * @param string $moduleName

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

                 foreach ($workflowRecord->getTasks() as $task) {

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

          * @param array  $actions

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

         {

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

             \Vtiger_Loader::includeOnce('~~modules/com_vtiger_workflow/include.php');

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

          * Gets workflow action tree.

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

                         'text' => ' ' . \App\Language::translate($task->getTaskObject()->summary, $workflowModuleName),

    Line indented incorrectly; expected 0 spaces, found 1
    Open

     class Vtiger_WorkflowTrigger_Model

    Line indented incorrectly; expected 0 spaces, found 1
    Open

     }

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

     class Vtiger_WorkflowTrigger_Model

    There are no issues that match your filters.

    Category
    Status