TicketWorkflowController::changeHelptopic()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Agent\helpdesk;
4
5
// controllers
6
use App\Http\Controllers\Controller;
7
// models
8
use App\Model\helpdesk\Agent\Department;
9
use App\Model\helpdesk\Agent\Teams;
10
use App\Model\helpdesk\Email\Emails;
11
use App\Model\helpdesk\Manage\Help_topic;
12
use App\Model\helpdesk\Manage\Sla_plan;
13
use App\Model\helpdesk\Ticket\Ticket_Priority;
14
use App\Model\helpdesk\Ticket\Ticket_Status;
15
use App\Model\helpdesk\Workflow\WorkflowAction;
16
use App\Model\helpdesk\Workflow\WorkflowName;
17
use App\Model\helpdesk\Workflow\WorkflowRules;
18
use App\User;
19
20
/**
21
 * TicketWorkflowController.
22
 *
23
 * @author      Ladybird <[email protected]>
24
 */
25
class TicketWorkflowController extends Controller
26
{
27
    /**
28
     * constructor
29
     * Create a new controller instance.
30
     *
31
     * @param type TicketController $TicketController
32
     */
33
    public function __construct(TicketController $TicketController)
34
    {
35
        $this->TicketController = $TicketController;
0 ignored issues
show
Bug introduced by
The property TicketController does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
    }
37
38
    /**
39
     * This is the core function from where the workflow is applied.
40
     *
41
     * @return type response
42
     */
43
    public function workflow($fromaddress, $fromname, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $collaborator, $dept, $assign, $team_assign, $ticket_status, $form_data, $auto_response)
44
    {
45
        $contact_details = ['email' => $fromaddress, 'email_name' => $fromname, 'subject' => $subject, 'message' => $body];
46
        $ticket_settings_details = ['help_topic' => $helptopic, 'sla' => $sla, 'priority' => $priority, 'source' => $source, 'dept' => $dept, 'assign' => $assign, 'team' => $team_assign, 'status' => $ticket_status, 'reject' => false];
47
        // get all the workflow common to the entire system which includes any type of ticket creation where the execution order of the workflow should be starting with ascending order
48
        $workflows = WorkflowName::where('target', '=', 'A-0')->where('status', '=', '1')->orderBy('order', 'asc')->get();
49
        foreach ($workflows as $workflow) {
50
            // checking if any workflow defined in the system
51
            if ($workflow) {
52
                // get all the rules of workflow which has a foreign key of those workflow which are applied to creating any ticket from any source
53
                $worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflow->id)->get();
54
                foreach ($worklfow_rules as $worklfow_rule) {
55
                    // checking for the workflow rules to which workflow rule type it is
56
                    if ($worklfow_rule->matching_scenario == 'email') {
57
                        if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
                            $ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
59
                        }
60
                    } elseif ($worklfow_rule->matching_scenario == 'email_name') {
61
                        if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
                            $ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
63
                        }
64
                    } elseif ($worklfow_rule->matching_scenario == 'subject') {
65
                        if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
66
                            $ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
67
                        }
68
                    } elseif ($worklfow_rule->matching_scenario == 'message') {
69
                        if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
70
                            $ticket_settings_details = $this->applyActionCondition($workflow->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
71
                        }
72
                    }
73
                }
74
            }
75
        }
76
        if ($source == 1) {
77
            // get all the workflow which are applied to ticket generated via webforms and in ascending order
78
            $workflows_webs = WorkflowName::where('target', '=', 'A-1')->where('status', '=', '1')->orderBy('order', 'asc')->get();
79
            foreach ($workflows_webs as $workflows_web) {
80
                if ($workflows_web) {
81
                    $worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflows_web->id)->get();
82
                    foreach ($worklfow_rules as $worklfow_rule) {
83
                        if ($worklfow_rule) {
84
                            // checking for the workflow rules to which workflow rule type it is
85
                            if ($worklfow_rule->matching_scenario == 'email') {
86
                                if ($this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
87
                                    $ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
88
                                }
89
                            } elseif ($worklfow_rule->matching_scenario == 'email_name') {
90
                                if ($this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
91
                                    $ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
92
                                }
93
                            } elseif ($worklfow_rule->matching_scenario == 'subject') {
94
                                if ($this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
95
                                    $ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
96
                                }
97
                            } elseif ($worklfow_rule->matching_scenario == 'message') {
98
                                if ($this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
99
                                    $ticket_settings_details = $this->applyActionCondition($workflows_web->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
100
                                }
101
                            }
102
                        }
103
                    }
104
                }
105
            }
106
        }
107 View Code Duplication
        if ($source == 2) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
            // get all the workflow which are applied to ticket generated via emails and in ascending order
109
            $workflows_emails = WorkflowName::where('target', '=', 'A-2')->where('status', '=', '1')->orderBy('order', 'asc')->get();
110
            foreach ($workflows_emails as $workflows_email) {
111
                if ($workflows_email) {
112
                    $worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflows_email->id)->get();
113
                    foreach ($worklfow_rules as $worklfow_rule) {
114
                        if ($worklfow_rule) {
115
                            // checking for the workflow rules to which workflow rule type it is
116
                            if ($worklfow_rule->matching_scenario == 'email') {
117
                                if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
118
                                    $ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
119
                                }
120
                            } elseif ($worklfow_rule->matching_scenario == 'email_name') {
121
                                if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
122
                                    $ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
123
                                }
124
                            } elseif ($worklfow_rule->matching_scenario == 'subject') {
125
                                if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
126
                                    $ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
127
                                }
128
                            } elseif ($worklfow_rule->matching_scenario == 'message') {
129
                                if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
130
                                    $ticket_settings_details = $this->applyActionCondition($workflows_email->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
131
                                }
132
                            }
133
                        }
134
                    }
135
                }
136
            }
137
        }
138 View Code Duplication
        if ($source == 4) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
139
            // get all the workflow which are applied to ticket generated via API and in ascending order
140
            $workflows_apis = WorkflowName::where('target', '=', 'A-4')->where('status', '=', '1')->orderBy('order', 'asc')->get();
141
            foreach ($workflows_apis as $workflows_api) {
142
                if ($workflows_api) {
143
                    $worklfow_rules = WorkflowRules::where('workflow_id', '=', $workflows_api->id)->get();
144
                    foreach ($worklfow_rules as $worklfow_rule) {
145
                        if ($worklfow_rule) {
146
                            // checking for the workflow rules to which workflow rule type it is
147
                            if ($worklfow_rule->matching_scenario == 'email') {
148
                                if ($rule_condition = $this->checkRuleCondition($contact_details['email'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
149
                                    $ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
150
                                }
151
                            } elseif ($worklfow_rule->matching_scenario == 'email_name') {
152
                                if ($rule_condition = $this->checkRuleCondition($contact_details['email_name'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
153
                                    $ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
154
                                }
155
                            } elseif ($worklfow_rule->matching_scenario == 'subject') {
156
                                if ($rule_condition = $this->checkRuleCondition($contact_details['subject'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
157
                                    $ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
158
                                }
159
                            } elseif ($worklfow_rule->matching_scenario == 'message') {
160
                                if ($rule_condition = $this->checkRuleCondition($contact_details['message'], $worklfow_rule->matching_relation, $worklfow_rule->matching_value) == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
Unused Code introduced by
$rule_condition is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
161
                                    $ticket_settings_details = $this->applyActionCondition($workflows_api->id, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,?,{"help_to...:"?","reject":"false"}>; however, App\Http\Controllers\Age...:applyActionCondition() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
162
                                }
163
                            }
164
                        }
165
                    }
166
                }
167
            }
168
        }
169
170
        //dd($form_data);
171
        if ($ticket_settings_details['reject'] == true) {
172
            return ['0' => false, '1' => false];
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array('0' => false, '1' => false); (array<string,false>) is incompatible with the return type documented by App\Http\Controllers\Age...lowController::workflow of type App\Http\Controllers\Agent\helpdesk\type.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
173
        } else {
174
            $create_ticket = $this->TicketController->create_user($contact_details['email'], $contact_details['email_name'], $contact_details['subject'], $contact_details['message'], $phone, $phonecode, $mobile_number, $ticket_settings_details['help_topic'], $ticket_settings_details['sla'], $ticket_settings_details['priority'], $source, $collaborator, $ticket_settings_details['dept'], $ticket_settings_details['assign'], $form_data, $auto_response, $ticket_settings_details['status']);
175
176
            return $create_ticket;
177
        }
178
    }
179
180
    /**
181
     * function to check the rules applied to the ticket workflow.
182
     *
183
     * @param type $to_check
184
     * @param type $condition
185
     * @param type $statement
186
     *
187
     * @return type boolean
188
     */
189
    public function checkRuleCondition($to_check, $condition, $statement)
190
    {
191
        if ($condition == 'equal') {
192
            $return = $this->checkEqual($statement, $to_check);
193
        } elseif ($condition == 'not_equal') {
194
            $return = $this->checkNotEqual($statement, $to_check);
195
        } elseif ($condition == 'contains') {
196
            $return = $this->checkContains($statement, $to_check);
197
        } elseif ($condition == 'dn_contain') {
198
            $return = $this->checkDoNotContain($statement, $to_check);
199
        } elseif ($condition == 'starts') {
200
            $return = $this->checkStarts($statement, $to_check);
201
        } elseif ($condition == 'ends') {
202
            $return = $this->checkEnds($statement, $to_check);
203
        }
204
//        elseif($condition == 'match') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
205
//
206
//        } elseif($condition == 'not_match') {
207
//
208
//        }
209
        return $return;
0 ignored issues
show
Bug introduced by
The variable $return does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
210
    }
211
212
    /**
213
     * function to check if the equal functions are applied.
214
     *
215
     * @param type $statement
216
     * @param type $to_check
217
     *
218
     * @return bool
219
     */
220
    public function checkEqual($statement, $to_check)
221
    {
222
        if ($statement == $to_check) {
223
            return true;
224
        } else {
225
            return false;
226
        }
227
    }
228
229
    /**
230
     * function to check if the not-equal functions are applied.
231
     *
232
     * @param type $statement
233
     * @param type $to_check
234
     *
235
     * @return bool
236
     */
237
    public function checkNotEqual($statement, $to_check)
238
    {
239
        if ($statement != $to_check) {
240
            return true;
241
        } else {
242
            return false;
243
        }
244
    }
245
246
    /**
247
     * function to check if the contains functions are applied.
248
     *
249
     * @param type $statement
250
     * @param type $to_check
251
     *
252
     * @return bool
253
     */
254
    public function checkContains($statement, $to_check)
255
    {
256
        if (strpos($to_check, $statement) !== false) {
257
            return true;
258
        } else {
259
            return false;
260
        }
261
    }
262
263
    /**
264
     * function to check if the do not contain functions are applied.
265
     *
266
     * @param type $statement
267
     * @param type $to_check
268
     *
269
     * @return bool
270
     */
271
    public function checkDoNotContain($statement, $to_check)
272
    {
273
        if (strpos($to_check, $statement) == false) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos($to_check, $statement) of type integer to the boolean false. If you are specifically checking for 0, consider using something more explicit like === 0 instead.
Loading history...
274
            return true;
275
        } else {
276
            return false;
277
        }
278
    }
279
280
    /**
281
     * function to check if the start functions are applied.
282
     *
283
     * @param type $statement
284
     * @param type $to_check
285
     *
286
     * @return bool
287
     */
288 View Code Duplication
    public function checkStarts($statement, $to_check)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
289
    {
290
        if (substr($to_check, 0, strlen($statement)) == $statement) {
291
            return true;
292
        } else {
293
            return false;
294
        }
295
    }
296
297
    /**
298
     * function to check if the ends functions are applied.
299
     *
300
     * @param type $statement
301
     * @param type $to_check
302
     *
303
     * @return bool
304
     */
305 View Code Duplication
    public function checkEnds($statement, $to_check)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
306
    {
307
        $to_check = strip_tags($to_check);
308
        if (substr($to_check, -strlen($statement)) == $statement) {
309
            return true;
310
        } else {
311
            return false;
312
        }
313
    }
314
315
//    function startsWith($to_check, $statement) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
316
//        // search backwards starting from haystack length characters from the end
317
//        return $statement === "" || strrpos($to_check, $statement, -strlen($to_check)) !== false;
318
//    }
319
320
//    function endsWith($to_check, $statement) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
321
//        // search forward starting from end minus needle length characters
322
//        return $statement === "" || (($temp = strlen($to_check) - strlen($statement)) >= 0 && strpos($to_check, $statement, $temp) !== false);
323
//    }
324
325
    /**
326
     * function to apply the action to a ticket.
327
     *
328
     * @param type $workflow_id
329
     * @param type $ticket_settings_details
330
     *
331
     * @return type array
332
     */
333
    public function applyActionCondition($workflow_id, $ticket_settings_details)
334
    {
335
        $workflow_actions = WorkflowAction::where('workflow_id', '=', $workflow_id)->get();
336
        foreach ($workflow_actions as $workflow_action) {
337
            if ($workflow_action->condition == 'reject') {
338
                $ticket_settings_details = $this->rejectTicket($ticket_settings_details);
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->rejectTicket($ticket_settings_details); of type array<string,boolean> adds the type array<string,boolean> to the return on line 356 which is incompatible with the return type documented by App\Http\Controllers\Age...r::applyActionCondition of type App\Http\Controllers\Agent\helpdesk\type.
Loading history...
339
            } elseif ($workflow_action->condition == 'department') {
340
                $ticket_settings_details = $this->changeDepartment($workflow_action, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,boolean,{"reject":"boolean"}>; however, App\Http\Controllers\Age...ler::changeDepartment() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
341
            } elseif ($workflow_action->condition == 'priority') {
342
                $ticket_settings_details = $this->changePriority($workflow_action, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,boolean,{"reject":"boolean"}>; however, App\Http\Controllers\Age...oller::changePriority() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
343
            } elseif ($workflow_action->condition == 'sla') {
344
                $ticket_settings_details = $this->changeSla($workflow_action, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,boolean,{"reject":"boolean"}>; however, App\Http\Controllers\Age...Controller::changeSla() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
345
            } elseif ($workflow_action->condition == 'team') {
346
                $ticket_settings_details = $this->changeTeam($workflow_action, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,boolean,{"reject":"boolean"}>; however, App\Http\Controllers\Age...ontroller::changeTeam() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
347
            } elseif ($workflow_action->condition == 'agent') {
348
                $ticket_settings_details = $this->changeAgent($workflow_action, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,boolean,{"reject":"boolean"}>; however, App\Http\Controllers\Age...ntroller::changeAgent() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
349
            } elseif ($workflow_action->condition == 'helptopic') {
350
                $ticket_settings_details = $this->changeHelptopic($workflow_action, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,boolean,{"reject":"boolean"}>; however, App\Http\Controllers\Age...ller::changeHelptopic() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
351
            } elseif ($workflow_action->condition == 'status') {
352
                $ticket_settings_details = $this->changeStatus($workflow_action, $ticket_settings_details);
0 ignored issues
show
Bug introduced by
It seems like $ticket_settings_details can also be of type array<string,boolean,{"reject":"boolean"}>; however, App\Http\Controllers\Age...troller::changeStatus() does only seem to accept object<App\Http\Controllers\Agent\helpdesk\type>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
353
            }
354
        }
355
356
        return $ticket_settings_details;
357
    }
358
359
    /**
360
     * function to reject ticket.
361
     *
362
     * @param array $ticket_settings_details
363
     *
364
     * @return type array
365
     */
366
    public function rejectTicket($ticket_settings_details)
367
    {
368
        $ticket_settings_details['reject'] = true;
369
370
        return $ticket_settings_details;
371
    }
372
373
    /**
374
     * function to change the department of a ticket.
375
     *
376
     * @param type $workflow_action
377
     * @param type $ticket_settings_details
378
     *
379
     * @return type array
380
     */
381 View Code Duplication
    public function changeDepartment($workflow_action, $ticket_settings_details)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
382
    {
383
        $dept = Department::where('id', '=', $workflow_action->action)->first();
384
        if ($dept == null) {
385
            return $ticket_settings_details;
386
        } else {
387
            $ticket_settings_details['dept'] = $dept->id;
388
389
            return $ticket_settings_details;
390
        }
391
    }
392
393
    /**
394
     * function to change the priority of a ticket.
395
     *
396
     * @param type $workflow_action
397
     * @param type $ticket_settings_details
398
     *
399
     * @return type array
400
     */
401 View Code Duplication
    public function changePriority($workflow_action, $ticket_settings_details)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
402
    {
403
        $priority = Ticket_Priority::where('priority_id', '=', $workflow_action->action)->first();
404
        if ($priority == null) {
405
            return $ticket_settings_details;
406
        } else {
407
            $ticket_settings_details['priority'] = $priority->priority_id;
408
409
            return $ticket_settings_details;
410
        }
411
    }
412
413
    /**
414
     * function to change the SLA of a ticket.
415
     *
416
     * @param type $workflow_action
417
     * @param type $ticket_settings_details
418
     *
419
     * @return type array
420
     */
421 View Code Duplication
    public function changeSla($workflow_action, $ticket_settings_details)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
422
    {
423
        $sla_plan = Sla_plan::where('id', '=', $workflow_action->action)->first();
424
        if ($sla_plan == null) {
425
            return $ticket_settings_details;
426
        } else {
427
            $ticket_settings_details['sla'] = $sla_plan->id;
428
429
            return $ticket_settings_details;
430
        }
431
    }
432
433
    /**
434
     * function to assign tean to a ticket.
435
     *
436
     * @param type $workflow_action
437
     * @param type $ticket_settings_details
438
     *
439
     * @return type array
440
     */
441 View Code Duplication
    public function changeTeam($workflow_action, $ticket_settings_details)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
442
    {
443
        $team = Teams::where('id', '=', $workflow_action->action)->first();
444
        if ($team == null) {
445
            return $ticket_settings_details;
446
        } else {
447
            $ticket_settings_details['team'] = $team->id;
448
449
            return $ticket_settings_details;
450
        }
451
    }
452
453
    /**
454
     * function to assing a ticket to an agent.
455
     *
456
     * @param type $workflow_action
457
     * @param type $ticket_settings_details
458
     *
459
     * @return type array
460
     */
461
    public function changeAgent($workflow_action, $ticket_settings_details)
462
    {
463
        $agent = User::where('id', '=', $workflow_action->action)->where('role', '!=', 'user')->first();
464
        if ($agent == null) {
465
            return $ticket_settings_details;
466
        } else {
467
            $ticket_settings_details['assign'] = $agent->id;
468
469
            return $ticket_settings_details;
470
        }
471
    }
472
473
    /**
474
     * function to change the helptopic of a ticket.
475
     *
476
     * @param type $workflow_action
477
     * @param type $ticket_settings_details
478
     *
479
     * @return type array
480
     */
481 View Code Duplication
    public function changeHelptopic($workflow_action, $ticket_settings_details)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
482
    {
483
        $help_topic = Help_topic::where('id', '=', $workflow_action->action)->first();
484
        if ($help_topic == null) {
485
            return $ticket_settings_details;
486
        } else {
487
            $ticket_settings_details['help_topic'] = $help_topic->id;
488
489
            return $ticket_settings_details;
490
        }
491
    }
492
493
    /**
494
     * function to change the status of a ticket.
495
     *
496
     * @param type $workflow_action
497
     * @param type $ticket_settings_details
498
     *
499
     * @return type array
500
     */
501 View Code Duplication
    public function changeStatus($workflow_action, $ticket_settings_details)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
502
    {
503
        $status = Ticket_Status::where('id', '=', $workflow_action->action)->first();
504
        if ($status == null) {
505
            return $ticket_settings_details;
506
        } else {
507
            $ticket_settings_details['status'] = $status->id;
508
509
            return $ticket_settings_details;
510
        }
511
    }
512
}
513