ApiController::getMyTicketsUser()   B
last analyzed

Complexity

Conditions 6
Paths 19

Size

Total Lines 51
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 37
nc 19
nop 0
dl 0
loc 51
rs 8.6588
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Http\Controllers\Api\v1;
4
5
use App\Http\Controllers\Agent\helpdesk\TicketController as CoreTicketController;
6
use App\Http\Controllers\Controller;
7
//use Illuminate\Support\Facades\Request as Value;
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
8
use App\Http\Requests\helpdesk\TicketRequest;
9
use App\Model\helpdesk\Agent\Department;
10
use App\Model\helpdesk\Agent\Teams;
11
use App\Model\helpdesk\Manage\Help_topic;
12
use App\Model\helpdesk\Manage\Sla_plan;
13
use App\Model\helpdesk\Settings\System;
14
use App\Model\helpdesk\Ticket\Ticket_attachments;
15
use App\Model\helpdesk\Ticket\Ticket_source;
16
use App\Model\helpdesk\Ticket\Ticket_Thread;
17
use App\Model\helpdesk\Ticket\Tickets;
18
use App\Model\helpdesk\Utility\Priority;
19
use App\User;
20
use Exception;
21
use Illuminate\Http\Request;
22
use Illuminate\Pagination\LengthAwarePaginator;
23
use Illuminate\Support\Collection;
24
25
/**
26
 * -----------------------------------------------------------------------------
27
 * Api Controller
28
 * -----------------------------------------------------------------------------.
29
 *
30
 *
31
 * @author Vijay Sebastian <[email protected]>
32
 * @copyright (c) 2016, Ladybird Web Solution
33
 * @name Faveo HELPDESK
34
 *
35
 * @version v1
36
 */
37
class ApiController extends Controller
38
{
39
    public $user;
40
    public $request;
41
    public $ticket;
42
    public $model;
43
    public $thread;
44
    public $attach;
45
    public $ticketRequest;
46
    public $faveoUser;
47
    public $team;
48
    public $setting;
49
    public $helptopic;
50
    public $slaPlan;
51
    public $department;
52
    public $priority;
53
    public $source;
54
55
    /**
56
     * @param Request $request
57
     */
58
    public function __construct(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
59
    {
60
        $this->request = $request;
61
62
        $this->middleware('jwt.auth');
63
        $this->middleware('api', ['except' => 'GenerateApiKey']);
64
        try {
65
            $user = \JWTAuth::parseToken()->authenticate();
66
            $this->user = $user;
67
        } catch (\Tymon\JWTAuth\Exceptions\TokenExpiredException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
68
        } catch (\Tymon\JWTAuth\Exceptions\JWTException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
69
        }
70
71
        $ticket = new TicketController();
72
        $this->ticket = $ticket;
73
74
        $model = new Tickets();
75
        $this->model = $model;
76
77
        $thread = new Ticket_Thread();
78
        $this->thread = $thread;
79
80
        $attach = new Ticket_attachments();
81
        $this->attach = $attach;
82
83
        $ticketRequest = new TicketRequest();
84
        $this->ticketRequest = $ticketRequest;
85
86
        $faveoUser = new User();
87
        $this->faveoUser = $faveoUser;
88
89
        $faveoUser = new User();
90
        $this->user = $faveoUser;
91
92
        $team = new Teams();
93
        $this->team = $team;
94
95
        $setting = new System();
96
        $this->setting = $setting;
97
98
        $helptopic = new Help_topic();
99
        $this->helptopic = $helptopic;
100
101
        $slaPlan = new Sla_plan();
102
        $this->slaPlan = $slaPlan;
103
104
        $priority = new Priority();
105
        $this->priority = $priority;
106
107
        $department = new Department();
108
        $this->department = $department;
109
110
        $source = new Ticket_source();
111
        $this->source = $source;
112
    }
113
114
    /**
115
     * Create Tickets.
116
     *
117
     * @method POST
118
     *
119
     * @param user_id,subject,body,helptopic,sla,priority,dept
120
     *
121
     * @return json
122
     */
123
    public function createTicket(\App\Http\Requests\helpdesk\CreateTicketRequest $request, \App\Model\helpdesk\Utility\CountryCode $code)
124
    {
125
        try {
126
            $user_id = $this->request->input('user_id');
0 ignored issues
show
Unused Code introduced by
$user_id 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...
127
128
            $subject = $this->request->input('subject');
0 ignored issues
show
Unused Code introduced by
$subject 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...
129
            $body = $this->request->input('body');
0 ignored issues
show
Unused Code introduced by
$body 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
            $helptopic = $this->request->input('helptopic');
0 ignored issues
show
Unused Code introduced by
$helptopic 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...
131
            $sla = $this->request->input('sla');
0 ignored issues
show
Unused Code introduced by
$sla 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...
132
            $priority = $this->request->input('priority');
0 ignored issues
show
Unused Code introduced by
$priority 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...
133
            $header = $this->request->input('cc');
134
            $dept = $this->request->input('dept');
0 ignored issues
show
Unused Code introduced by
$dept 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...
135
136
            $assignto = $this->request->input('assignto');
0 ignored issues
show
Unused Code introduced by
$assignto 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...
137
            $form_data = $this->request->input('form_data');
0 ignored issues
show
Unused Code introduced by
$form_data 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...
138
            $source = $this->request->input('source');
0 ignored issues
show
Unused Code introduced by
$source 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...
139
            $attach = $this->request->input('attachments');
0 ignored issues
show
Unused Code introduced by
$attach 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...
140
            $headers = [];
0 ignored issues
show
Unused Code introduced by
$headers 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...
141
            if ($header) {
142
                $headers = explode(',', $header);
0 ignored issues
show
Unused Code introduced by
$headers 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...
143
            }
144
            //return $headers;
145
            /*
146
             * return s ticket number
147
             */
148
            $PhpMailController = new \App\Http\Controllers\Common\PhpMailController();
149
            $NotificationController = new \App\Http\Controllers\Common\NotificationController();
150
            $core = new CoreTicketController($PhpMailController, $NotificationController);
151
            $response = $core->post_newticket($request, $code, true);
152
            //$response = $this->ticket->createTicket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $attach);
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
153
            //return $response;
154
            /*
155
             * return ticket details
156
             */
157
            //dd($response);
158
            //$result = $this->thread->where('id', $response)->first();
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% 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...
159
            //$result = $this->attach($result->id,$file);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
160
            return response()->json(compact('response'));
161
        } catch (\Exception $e) {
162
            $error = $e->getMessage();
163
            $line = $e->getLine();
164
            $file = $e->getFile();
165
166
            return response()->json(compact('error', 'file', 'line'));
167
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
168
            $error = $e->getMessage();
169
170
            return response()->json(compact('error'))
171
                            ->header('Authenticate: xBasic realm', 'fake');
172
        }
173
    }
174
175
    /**
176
     * Reply for the ticket.
177
     *
178
     * @param TicketRequest $request
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
179
     *
180
     * @return json
181
     */
182
    public function ticketReply()
183
    {
184
        //dd($this->request->all());
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
185
        try {
186
            $v = \Validator::make($this->request->all(), [
187
                        'ticket_ID'     => 'required|exists:tickets,id',
188
                        'reply_content' => 'required',
189
            ]);
190
            if ($v->fails()) {
191
                $error = $v->errors();
192
193
                return response()->json(compact('error'));
194
            }
195
            $attach = $this->request->input('attachments');
196
            $result = $this->ticket->reply($this->thread, $this->request, $this->attach, $attach);
0 ignored issues
show
Bug introduced by
It seems like $attach defined by $this->request->input('attachments') on line 195 can also be of type array; however, App\Http\Controllers\Api...cketController::reply() does only seem to accept string, 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...
197
            $result = $result->join('users', 'ticket_thread.user_id', '=', 'users.id')
198
                    ->select('ticket_thread.*', 'users.first_name as first_name')
199
                    ->first();
200
201
            return response()->json(compact('result'));
202
        } catch (\Exception $e) {
203
            $error = $e->getMessage();
204
            $line = $e->getLine();
205
            $file = $e->getFile();
206
207
            return response()->json(compact('error', 'file', 'line'));
208
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
209
            $error = $e->getMessage();
210
211
            return response()->json(compact('error'));
212
        }
213
    }
214
215
    /**
216
     * Edit a ticket.
217
     *
218
     * @return json
219
     */
220
    public function editTicket()
221
    {
222
        try {
223
            $v = \Validator::make($this->request->all(), [
224
                        'ticket_id'       => 'required|exists:tickets,id',
225
                        'subject'         => 'required',
226
                        'sla_plan'        => 'required|exists:sla_plan,id',
227
                        'help_topic'      => 'required|exists:help_topic,id',
228
                        'ticket_source'   => 'required|exists:ticket_source,id',
229
                        'ticket_priority' => 'required|exists:ticket_priority,priority_id',
230
            ]);
231
            if ($v->fails()) {
232
                $error = $v->errors();
233
234
                return response()->json(compact('error'));
235
            }
236
            $ticket_id = $this->request->input('ticket_id');
237
            $result = $this->ticket->ticketEditPost($ticket_id, $this->thread, $this->model);
0 ignored issues
show
Documentation introduced by
$ticket_id is of type string|array, but the function expects a object<App\Http\Controllers\Api\v1\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
238
239
            return response()->json(compact('result'));
240
        } catch (\Exception $e) {
241
            $error = $e->getMessage();
242
            $line = $e->getLine();
243
            $file = $e->getFile();
244
245
            return response()->json(compact('error', 'file', 'line'));
246
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
247
            $error = $e->getMessage();
248
249
            return response()->json(compact('error'));
250
        }
251
    }
252
253
    /**
254
     * Delete The Ticket.
255
     *
256
     * @return json
257
     */
258
    public function deleteTicket()
259
    {
260
        try {
261
            $v = \Validator::make($this->request->all(), [
262
                        'ticket_id' => 'required|exists:tickets,id',
263
            ]);
264
            if ($v->fails()) {
265
                $error = $v->errors();
266
267
                return response()->json(compact('error'));
268
            }
269
            $id = $this->request->input('ticket_id');
270
271
            $result = $this->ticket->delete($id, $this->model);
272
273
            return response()->json(compact('result'));
274
        } catch (\Exception $e) {
275
            $error = $e->getMessage();
276
            $line = $e->getLine();
277
            $file = $e->getFile();
278
279
            return response()->json(compact('error', 'file', 'line'));
280
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
281
            $error = $e->getMessage();
282
283
            return response()->json(compact('error'));
284
        }
285
    }
286
287
    /**
288
     * Get all opened tickets.
289
     *
290
     * @return json
291
     */
292
    public function openedTickets()
293
    {
294
        try {
295
            //            $result = $this->model->where('status', '=', 1)->where('isanswered', '=', 0)->where('assigned_to', '=', null)->orderBy('id', 'DESC')->get();
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% 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...
296
//            return response()->json(compact('result'));
297
298
            $result = $this->user->join('tickets', function ($join) {
0 ignored issues
show
Documentation Bug introduced by
The method join does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
299
                $join->on('users.id', '=', 'tickets.user_id')
300
                        ->where('isanswered', '=', 0)->where('status', '=', 1)->whereNull('assigned_to');
301
            })
302
                    ->join('department', 'department.id', '=', 'tickets.dept_id')
303
                    ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
304
                    ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
305
                    ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id')
306
                    ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status')
307
                    ->join('ticket_thread', function ($join) {
308
                        $join->on('tickets.id', '=', 'ticket_thread.ticket_id')
309
                        ->whereNotNull('title');
310
                    })
311
                    ->select('first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
312
                    ->orderBy('ticket_thread.updated_at', 'desc')
313
                    ->groupby('tickets.id')
314
                    ->distinct()
315
                    ->paginate(10)
316
                    ->toJson();
317
318
            return $result;
319
        } catch (\Exception $e) {
320
            $error = $e->getMessage();
321
            $line = $e->getLine();
322
            $file = $e->getFile();
323
324
            return response()->json(compact('error', 'file', 'line'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(...ror', 'file', 'line')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...ntroller::openedTickets of type App\Http\Controllers\Api\v1\json.

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...
325
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
326
            $error = $e->getMessage();
327
328
            return response()->json(compact('error'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(compact('error')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...ntroller::openedTickets of type App\Http\Controllers\Api\v1\json.

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...
329
        }
330
    }
331
332
    /**
333
     * Get Unsigned Tickets.
334
     *
335
     * @return json
336
     */
337 View Code Duplication
    public function unassignedTickets()
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...
338
    {
339
        try {
340
            //dd('sdhjbc');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
341
//            $result = $this->model->where('assigned_to', '=', null)->where('status', '1')->orderBy('id', 'DESC')->get();
342
//            return response()->json(compact('result'));
343
            $user = \JWTAuth::parseToken()->authenticate();
344
            $unassigned = $this->user->join('tickets', function ($join) {
0 ignored issues
show
Documentation Bug introduced by
The method join does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
345
                $join->on('users.id', '=', 'tickets.user_id')
346
                        ->whereNull('assigned_to')->where('status', '=', 1);
347
            })
348
                    ->join('department', 'department.id', '=', 'tickets.dept_id')
349
                    ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
350
                    ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
351
                    ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id')
352
                    ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status')
353
                    ->join('ticket_thread', function ($join) {
354
                        $join->on('tickets.id', '=', 'ticket_thread.ticket_id')
355
                        ->whereNotNull('title');
356
                    })
357
                    ->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
358
                    ->where(function ($query) use ($user) {
359
                        if ($user->role != 'admin') {
360
                            $query->where('tickets.dept_id', '=', $user->primary_dpt);
361
                        }
362
                    })
363
                    ->orderBy('updated_at', 'desc')
364
                    ->groupby('tickets.id')
365
                    ->distinct()
366
                    ->paginate(10)
367
                    ->toJson();
368
369
            return $unassigned;
370
        } catch (\Exception $e) {
371
            $error = $e->getMessage();
372
            $line = $e->getLine();
373
            $file = $e->getFile();
374
375
            return response()->json(compact('error', 'file', 'line'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(...ror', 'file', 'line')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...ller::unassignedTickets of type App\Http\Controllers\Api\v1\json.

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...
376
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
377
            $error = $e->getMessage();
378
379
            return response()->json(compact('error'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(compact('error')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...ller::unassignedTickets of type App\Http\Controllers\Api\v1\json.

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...
380
        }
381
    }
382
383
    /**
384
     * Get closed Tickets.
385
     *
386
     * @return json
387
     */
388 View Code Duplication
    public function closeTickets()
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...
389
    {
390
        try {
391
            //            $result = $this->model->where('status', '>', 1)->where('status', '<', 4)->orderBy('id', 'DESC')->get();
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
392
//            return response()->json(compact('result'));
393
            $user = \JWTAuth::parseToken()->authenticate();
394
            $result = $this->user->join('tickets', function ($join) {
0 ignored issues
show
Documentation Bug introduced by
The method join does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
395
                $join->on('users.id', '=', 'tickets.user_id')
396
                        ->where('status', '=', 3)->orWhere('status', '=', 2);
397
            })
398
                    ->join('department', 'department.id', '=', 'tickets.dept_id')
399
                    ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
400
                    ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
401
                    ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id')
402
                    ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status')
403
                    ->join('ticket_thread', function ($join) {
404
                        $join->on('tickets.id', '=', 'ticket_thread.ticket_id')
405
                        ->whereNotNull('title');
406
                    })
407
                    ->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
408
                    ->where(function ($query) use ($user) {
409
                        if ($user->role != 'admin') {
410
                            $query->where('tickets.dept_id', '=', $user->primary_dpt);
411
                        }
412
                    })
413
                    ->orderBy('updated_at', 'desc')
414
                    ->groupby('tickets.id')
415
                    ->distinct()
416
                    ->paginate(10)
417
                    ->toJson();
418
419
            return $result;
420
        } catch (\Exception $e) {
421
            $error = $e->getMessage();
422
            $line = $e->getLine();
423
            $file = $e->getFile();
424
425
            return response()->json(compact('error', 'file', 'line'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(...ror', 'file', 'line')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...ontroller::closeTickets of type App\Http\Controllers\Api\v1\json.

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...
426
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
427
            $error = $e->getMessage();
428
429
            return response()->json(compact('error'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(compact('error')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...ontroller::closeTickets of type App\Http\Controllers\Api\v1\json.

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...
430
        }
431
    }
432
433
    /**
434
     * Get All agents.
435
     *
436
     * @return json
437
     */
438
    public function getAgents()
439
    {
440
        try {
441
            $result = $this->faveoUser->where('role', 'agent')->orWhere('role', 'admin')->where('active', 1)->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
442
443
            return response()->json(compact('result'));
444
        } catch (Exception $e) {
445
            $error = $e->getMessage();
446
            $line = $e->getLine();
447
            $file = $e->getFile();
448
449
            return response()->json(compact('error', 'file', 'line'));
450
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
451
            $error = $e->getMessage();
452
453
            return response()->json(compact('error'));
454
        }
455
    }
456
457
    /**
458
     * Get All Teams.
459
     *
460
     * @return json
461
     */
462 View Code Duplication
    public function getTeams()
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...
463
    {
464
        try {
465
            $result = $this->team->get();
0 ignored issues
show
Documentation Bug introduced by
The method get does not exist on object<App\Model\helpdesk\Agent\Teams>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
466
467
            return response()->json(compact('result'));
468
        } catch (Exception $e) {
469
            $error = $e->getMessage();
470
            $line = $e->getLine();
471
            $file = $e->getFile();
472
473
            return response()->json(compact('error', 'file', 'line'));
474
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
475
            $error = $e->getMessage();
476
477
            return response()->json(compact('error'));
478
        }
479
    }
480
481
    /**
482
     * To assign a ticket.
483
     *
484
     * @return json
485
     */
486
    public function assignTicket()
487
    {
488
        try {
489
            $v = \Validator::make($this->request->all(), [
490
                        'ticket_id' => 'required',
491
                        'user'      => 'required',
492
            ]);
493
            if ($v->fails()) {
494
                $error = $v->errors();
495
496
                return response()->json(compact('error'));
497
            }
498
            $id = $this->request->input('ticket_id');
499
            $response = $this->ticket->assign($id);
0 ignored issues
show
Documentation introduced by
$id is of type string|array, but the function expects a object<App\Http\Controllers\Api\v1\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
500 View Code Duplication
            if ($response == 1) {
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...
501
                $result = 'success';
502
503
                return response()->json(compact('result'));
504
            } else {
505
                return response()->json(compact('response'));
506
            }
507
        } catch (Exception $e) {
508
            $error = $e->getMessage();
509
            $line = $e->getLine();
510
            $file = $e->getFile();
511
512
            return response()->json(compact('error', 'file', 'line'));
513
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
514
            $error = $e->getMessage();
515
516
            return response()->json(compact('error'));
517
        }
518
    }
519
520
    /**
521
     * Get all customers.
522
     *
523
     * @return json
524
     */
525
    public function getCustomers()
526
    {
527
        try {
528
            $v = \Validator::make($this->request->all(), [
529
                        'search' => 'required',
530
            ]);
531
            if ($v->fails()) {
532
                $error = $v->errors();
533
534
                return response()->json(compact('error'));
535
            }
536
            $search = $this->request->input('search');
537
            $result = $this->faveoUser->where('first_name', 'like', '%'.$search.'%')->orWhere('last_name', 'like', '%'.$search.'%')->orWhere('user_name', 'like', '%'.$search.'%')->orWhere('email', 'like', '%'.$search.'%')->get();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
538
539
            return response()->json(compact('result'))
540
                            ->header('X-Header-One', 'Header Value');
541
        } catch (Exception $e) {
542
            $error = $e->getMessage();
543
            $line = $e->getLine();
544
            $file = $e->getFile();
545
546
            return response()->json(compact('error', 'file', 'line'));
547
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
548
            $error = $e->getMessage();
549
550
            return response()->json(compact('error'))
551
                            ->header('X-Header-One', 'Header Value');
552
        }
553
    }
554
555
    /**
556
     * Get all customers having client_id, client_picture, client_name, client_email, client_phone.
557
     *
558
     * @return json
559
     */
560
    public function getCustomersWith()
561
    {
562
        try {
563
            $users = $this->user
0 ignored issues
show
Documentation Bug introduced by
The method leftJoin does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
564
                    ->leftJoin('user_assign_organization', 'user_assign_organization.user_id', '=', 'users.id')
565
                    ->leftJoin('organization', 'organization.id', '=', 'user_assign_organization.org_id')
566
                    ->where('role', 'user')
567
                    ->select('users.id', 'user_name', 'first_name', 'last_name', 'email', 'phone_number', 'users.profile_pic', 'organization.name AS company', 'users.active')
568
                    ->paginate(10)
569
                    ->toJson();
570
571
            //dd($users);
572
            return $users;
573
        } catch (\Exception $e) {
574
            $error = $e->getMessage();
575
            $line = $e->getLine();
576
            $file = $e->getFile();
577
578
            return response()->json(compact('error', 'file', 'line'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(...ror', 'file', 'line')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...oller::getCustomersWith of type App\Http\Controllers\Api\v1\json.

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...
579
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
580
            $error = $e->getMessage();
581
582
            return response()->json(compact('error'))
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(...xBasic realm', 'fake'); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...oller::getCustomersWith of type App\Http\Controllers\Api\v1\json.

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...
583
                            ->header('Authenticate: xBasic realm', 'fake');
584
        }
585
    }
586
587
    /**
588
     * Get a customer by id.
589
     *
590
     * @return json
591
     */
592
    public function getCustomer()
593
    {
594
        try {
595
            $v = \Validator::make($this->request->all(), [
596
                        'user_id' => 'required',
597
            ]);
598
            if ($v->fails()) {
599
                $error = $v->errors();
600
601
                return response()->json(compact('error'));
602
            }
603
            $id = $this->request->input('user_id');
604
            $result = $this->faveoUser->where('id', $id)->where('role', 'user')->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
605
606
            return response()->json(compact('result'));
607
        } catch (Exception $e) {
608
            $error = $e->getMessage();
609
            $line = $e->getLine();
610
            $file = $e->getFile();
611
612
            return response()->json(compact('error', 'file', 'line'));
613
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
614
            $error = $e->getMessage();
615
616
            return response()->json(compact('error'));
617
        }
618
    }
619
620
    /**
621
     * Search tickets.
622
     *
623
     * @return json
624
     */
625
    public function searchTicket()
626
    {
627
        try {
628
            $v = \Validator::make($this->request->all(), [
629
                        'search' => 'required',
630
            ]);
631
            if ($v->fails()) {
632
                $error = $v->errors();
633
634
                return response()->json(compact('error'));
635
            }
636
            $search = $this->request->input('search');
637
            $result = $this->thread->select('ticket_id')->where('title', 'like', '%'.$search.'%')->orWhere('body', 'like', '%'.$search.'%')->get();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Model\helpdesk\Ticket\Ticket_Thread>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
638
639
            return response()->json(compact('result'));
640
        } catch (Exception $e) {
641
            $error = $e->getMessage();
642
            $line = $e->getLine();
643
            $file = $e->getFile();
644
645
            return response()->json(compact('error', 'file', 'line'));
646
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
647
            $error = $e->getMessage();
648
649
            return response()->json(compact('error'));
650
        }
651
    }
652
653
    /**
654
     * Get threads of a ticket.
655
     *
656
     * @return json
657
     */
658
    public function ticketThreads()
659
    {
660
        try {
661
            $v = \Validator::make($this->request->all(), [
662
                        'id' => 'required',
663
            ]);
664
            if ($v->fails()) {
665
                $error = $v->errors();
666
667
                return response()->json(compact('error'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(compact('error')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...ntroller::ticketThreads of type App\Http\Controllers\Api\v1\json.

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...
668
            }
669
            $id = $this->request->input('id');
670
            $result = $this->user
0 ignored issues
show
Documentation Bug introduced by
The method leftjoin does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
671
                    ->leftjoin('ticket_thread', 'ticket_thread.user_id', '=', 'users.id')
672
                    ->select('ticket_thread.id', 'ticket_id', 'user_id', 'poster', 'source', 'title', 'body', 'is_internal', 'format', 'ip_address', 'ticket_thread.created_at', 'ticket_thread.updated_at', 'users.first_name', 'users.last_name', 'users.user_name', 'users.email', 'users.profile_pic')
673
                    ->where('ticket_id', $id)
674
                    ->get()
675
                    ->toJson();
676
677
            return $result;
678
        } catch (\Exception $e) {
679
            $error = $e->getMessage();
680
            $line = $e->getLine();
681
            $file = $e->getFile();
682
683
            return response()->json(compact('error', 'file', 'line'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(...ror', 'file', 'line')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...ntroller::ticketThreads of type App\Http\Controllers\Api\v1\json.

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...
684
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
685
            $error = $e->getMessage();
686
687
            return response()->json(compact('error'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(compact('error')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...ntroller::ticketThreads of type App\Http\Controllers\Api\v1\json.

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...
688
        }
689
    }
690
691
    /**
692
     * Check the url is valid or not.
693
     *
694
     * @return json
695
     */
696
    public function checkUrl()
697
    {
698
        //dd($this->request);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% 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...
699
        try {
700
            $v = \Validator::make($this->request->all(), [
701
                        'url' => 'required|url',
702
            ]);
703
            if ($v->fails()) {
704
                $error = $v->errors();
705
706
                return response()->json(compact('error'));
707
            }
708
709
            $url = $this->request->input('url');
710
            if (!str_is('*/', $url)) {
0 ignored issues
show
Bug introduced by
It seems like $url defined by $this->request->input('url') on line 709 can also be of type array; however, str_is() does only seem to accept string, 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...
711
                $url = str_finish($url, '/');
0 ignored issues
show
Bug introduced by
It seems like $url can also be of type array; however, str_finish() does only seem to accept string, 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...
712
            }
713
714
            $url = $url.'/api/v1/helpdesk/check-url?api_key='.$this->request->input('api_key').'&token='.\Config::get('app.token');
715
            $result = $this->CallGetApi($url);
0 ignored issues
show
Documentation introduced by
$url is of type string, but the function expects a object<App\Http\Controllers\Api\v1\type>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
716
            //dd($result);
717
            return response()->json(compact('result'));
718
        } catch (\Exception $ex) {
719
            $error = $e->getMessage();
0 ignored issues
show
Bug introduced by
The variable $e seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
720
721
            return response()->json(compact('error'));
722
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
723
            $error = $e->getMessage();
724
725
            return response()->json(compact('error'));
726
        }
727
    }
728
729
    /**
730
     * Success for currect url.
731
     *
732
     * @return string
733
     */
734
    public function urlResult()
735
    {
736
        return 'success';
737
    }
738
739
    /**
740
     * Call curl function for Get Method.
741
     *
742
     * @param type $url
743
     *
744
     * @return type int|string|json
745
     */
746 View Code Duplication
    public function callGetApi($url)
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...
747
    {
748
        $curl = curl_init($url);
749
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
750
        curl_setopt($curl, CURLOPT_URL, $url);
751
        curl_setopt($curl, CURLOPT_HEADER, 0);
752
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
753
        $response = curl_exec($curl);
754
755
        if (curl_errno($curl)) {
756
            echo 'error:'.curl_error($curl);
757
        }
758
759
        return $response;
760
        curl_close($curl);
0 ignored issues
show
Unused Code introduced by
curl_close($curl); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
761
    }
762
763
    /**
764
     * Call curl function for POST Method.
765
     *
766
     * @param type $url
767
     * @param type $data
768
     *
769
     * @return type int|string|json
770
     */
771 View Code Duplication
    public function callPostApi($url, $data)
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...
772
    {
773
        $curl = curl_init($url);
774
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
775
        curl_setopt($curl, CURLOPT_URL, $url);
776
        curl_setopt($curl, CURLOPT_HEADER, 0);
777
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
778
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
779
        $response = curl_exec($curl);
780
781
        if (curl_errno($curl)) {
782
            echo 'error:'.curl_error($curl);
783
        }
784
785
        return $response;
786
        curl_close($curl);
0 ignored issues
show
Unused Code introduced by
curl_close($curl); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
787
    }
788
789
    /**
790
     * To generate api string.
791
     *
792
     * @return type | json
793
     */
794
    public function generateApiKey()
795
    {
796
        try {
797
            $set = $this->setting->where('id', '1')->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Settings\System>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
798
            //dd($set);
799
            if ($set->api_enable == 1) {
800
                $key = str_random(32);
801
                $set->api_key = $key;
802
                $set->save();
803
                $result = $set->api_key;
804
805
                return response()->json(compact('result'));
806
            } else {
807
                $result = 'please enable api';
808
809
                return response()->json(compact('result'));
810
            }
811
        } catch (\Exception $e) {
812
            $error = $e->getMessage();
813
            $line = $e->getLine();
814
            $file = $e->getFile();
815
816
            return response()->json(compact('error', 'file', 'line'));
817
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
818
            $error = $e->getMessage();
819
820
            return response()->json(compact('error'));
821
        }
822
    }
823
824
    /**
825
     * Get help topics.
826
     *
827
     * @return json
828
     */
829 View Code Duplication
    public function getHelpTopic()
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...
830
    {
831
        try {
832
            $result = $this->helptopic->get();
0 ignored issues
show
Documentation Bug introduced by
The method get does not exist on object<App\Model\helpdesk\Manage\Help_topic>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
833
834
            return response()->json(compact('result'));
835
        } catch (\Exception $e) {
836
            $error = $e->getMessage();
837
            $line = $e->getLine();
838
            $file = $e->getFile();
839
840
            return response()->json(compact('error', 'file', 'line'));
841
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
842
            $error = $e->getMessage();
843
844
            return response()->json(compact('error'));
845
        }
846
    }
847
848
    /**
849
     * Get Sla plans.
850
     *
851
     * @return json
852
     */
853 View Code Duplication
    public function getSlaPlan()
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...
854
    {
855
        try {
856
            $result = $this->slaPlan->get();
0 ignored issues
show
Documentation Bug introduced by
The method get does not exist on object<App\Model\helpdesk\Manage\Sla_plan>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
857
858
            return response()->json(compact('result'));
859
        } catch (\Exception $e) {
860
            $error = $e->getMessage();
861
            $line = $e->getLine();
862
            $file = $e->getFile();
863
864
            return response()->json(compact('error', 'file', 'line'));
865
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
866
            $error = $e->getMessage();
867
868
            return response()->json(compact('error'));
869
        }
870
    }
871
872
    /**
873
     * Get priorities.
874
     *
875
     * @return json
876
     */
877 View Code Duplication
    public function getPriority()
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...
878
    {
879
        try {
880
            $result = $this->priority->get();
0 ignored issues
show
Documentation Bug introduced by
The method get does not exist on object<App\Model\helpdesk\Utility\Priority>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
881
882
            return response()->json(compact('result'));
883
        } catch (\Exception $e) {
884
            $error = $e->getMessage();
885
            $line = $e->getLine();
886
            $file = $e->getFile();
887
888
            return response()->json(compact('error', 'file', 'line'));
889
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
890
            $error = $e->getMessage();
891
892
            return response()->json(compact('error'));
893
        }
894
    }
895
896
    /**
897
     * Get departments.
898
     *
899
     * @return json
900
     */
901 View Code Duplication
    public function getDepartment()
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...
902
    {
903
        try {
904
            $result = $this->department->get();
0 ignored issues
show
Documentation Bug introduced by
The method get does not exist on object<App\Model\helpdesk\Agent\Department>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
905
906
            return response()->json(compact('result'));
907
        } catch (\Exception $e) {
908
            $error = $e->getMessage();
909
            $line = $e->getLine();
910
            $file = $e->getFile();
911
912
            return response()->json(compact('error', 'file', 'line'));
913
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
914
            $error = $e->getMessage();
915
916
            return response()->json(compact('error'));
917
        }
918
    }
919
920
    /**
921
     * Getting the tickets.
922
     *
923
     * @return type json
924
     */
925
    public function getTickets()
926
    {
927
        try {
928
            $tickets = $this->model->orderBy('created_at', 'desc')->paginate(10);
0 ignored issues
show
Documentation Bug introduced by
The method orderBy does not exist on object<App\Model\helpdesk\Ticket\Tickets>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
929
            $tickets->toJson();
930
931
            return $tickets;
932
        } catch (\Exception $e) {
933
            $error = $e->getMessage();
934
            $line = $e->getLine();
935
            $file = $e->getFile();
936
937
            return response()->json(compact('error', 'file', 'line'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(...ror', 'file', 'line')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...iController::getTickets of type App\Http\Controllers\Api\v1\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...
938
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
939
            $error = $e->getMessage();
940
941
            return response()->json(compact('error'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(compact('error')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api...iController::getTickets of type App\Http\Controllers\Api\v1\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...
942
        }
943
    }
944
945
    /**
946
     * Fetching the Inbox details.
947
     *
948
     * @return type json
949
     */
950 View Code Duplication
    public function inbox()
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...
951
    {
952
        try {
953
            $user = \JWTAuth::parseToken()->authenticate();
954
            $inbox = $this->user->join('tickets', function ($join) {
0 ignored issues
show
Documentation Bug introduced by
The method join does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
955
                $join->on('users.id', '=', 'tickets.user_id')
956
                        ->where('status', '=', 1);
957
            })
958
                    ->join('department', 'department.id', '=', 'tickets.dept_id')
959
                    ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
960
                    ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
961
                    ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id')
962
                    ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status')
963
                    ->join('ticket_thread', function ($join) {
964
                        $join->on('tickets.id', '=', 'ticket_thread.ticket_id')
965
                        ->whereNotNull('ticket_thread.title');
966
                    })
967
                    ->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'ticket_thread.title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name', 'department.id as department_id', 'users.primary_dpt as user_dpt')
968
                    ->where(function ($query) use ($user) {
969
                        if ($user->role != 'admin') {
970
                            $query->where('tickets.dept_id', '=', $user->primary_dpt);
971
                        }
972
                    })
973
                    ->orderBy('updated_at', 'desc')
974
                    ->groupby('tickets.id')
975
                    ->distinct()
976
                    ->paginate(10)
977
                    ->toJson();
978
979
            return $inbox;
980
        } catch (\Exception $ex) {
981
            $error = $ex->getMessage();
982
            $line = $ex->getLine();
983
            $file = $ex->getFile();
984
985
            return response()->json(compact('error', 'file', 'line'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(...ror', 'file', 'line')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api\v1\ApiController::inbox of type App\Http\Controllers\Api\v1\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...
986
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
987
            $error = $e->getMessage();
988
989
            return response()->json(compact('error'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return response()->json(compact('error')); (Illuminate\Http\JsonResponse) is incompatible with the return type documented by App\Http\Controllers\Api\v1\ApiController::inbox of type App\Http\Controllers\Api\v1\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...
990
        }
991
    }
992
993
    /**
994
     * Create internal note.
995
     *
996
     * @return type json
997
     */
998
    public function internalNote()
999
    {
1000
        try {
1001
            $v = \Validator::make($this->request->all(), [
1002
                        'userid'   => 'required|exists:users,id',
1003
                        'ticketid' => 'required|exists:tickets,id',
1004
                        'body'     => 'required',
1005
            ]);
1006
            if ($v->fails()) {
1007
                $error = $v->errors();
1008
1009
                return response()->json(compact('error'));
1010
            }
1011
            $userid = $this->request->input('userid');
1012
            $ticketid = $this->request->input('ticketid');
1013
1014
            $body = $this->request->input('body');
1015
            $thread = $this->thread->create(['ticket_id' => $ticketid, 'user_id' => $userid, 'is_internal' => 1, 'body' => $body]);
1016
1017
            return response()->json(compact('thread'));
1018
        } catch (\Exception $ex) {
1019
            $error = $e->getMessage();
0 ignored issues
show
Bug introduced by
The variable $e seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1020
            $line = $e->getLine();
0 ignored issues
show
Bug introduced by
The variable $e seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1021
            $file = $e->getFile();
0 ignored issues
show
Bug introduced by
The variable $e seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
1022
1023
            return response()->json(compact('error', 'file', 'line'));
1024
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
1025
            $error = $e->getMessage();
1026
1027
            return response()->json(compact('error'));
1028
        }
1029
    }
1030
1031 View Code Duplication
    public function getTrash()
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...
1032
    {
1033
        try {
1034
            $user = \JWTAuth::parseToken()->authenticate();
1035
            $trash = $this->user->join('tickets', function ($join) {
0 ignored issues
show
Documentation Bug introduced by
The method join does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1036
                $join->on('users.id', '=', 'tickets.user_id')
1037
                        ->where('status', '=', 5);
1038
            })
1039
                    ->join('department', 'department.id', '=', 'tickets.dept_id')
1040
                    ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
1041
                    ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
1042
                    ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id')
1043
                    ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status')
1044
                    ->join('ticket_thread', function ($join) {
1045
                        $join->on('tickets.id', '=', 'ticket_thread.ticket_id')
1046
                        ->whereNotNull('title');
1047
                    })
1048
                    ->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
1049
                    ->where(function ($query) use ($user) {
1050
                        if ($user->role != 'admin') {
1051
                            $query->where('tickets.dept_id', '=', $user->primary_dpt);
1052
                        }
1053
                    })
1054
                    ->orderBy('updated_at', 'desc')
1055
                    ->groupby('tickets.id')
1056
                    ->distinct()
1057
                    ->paginate(10)
1058
                    ->toJson();
1059
1060
            return $trash;
1061
        } catch (\Exception $e) {
1062
            $error = $e->getMessage();
1063
            $line = $e->getLine();
1064
            $file = $e->getFile();
1065
1066
            return response()->json(compact('error', 'file', 'line'));
1067
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
1068
            $error = $e->getMessage();
1069
1070
            return response()->json(compact('error'));
1071
        }
1072
    }
1073
1074
    public function getMyTicketsAgent()
1075
    {
1076
        try {
1077
            $v = \Validator::make($this->request->all(), [
1078
                        'user_id' => 'required|exists:users,id',
1079
            ]);
1080
            if ($v->fails()) {
1081
                $error = $v->errors();
1082
1083
                return response()->json(compact('error'));
1084
            }
1085
            $id = $this->request->input('user_id');
1086 View Code Duplication
            if ($this->user->where('id', $id)->first()->role == 'user') {
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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...
1087
                $error = 'This user is not an Agent or Admin';
1088
1089
                return response()->json(compact('error'));
1090
            }
1091
            //$user = \JWTAuth::parseToken()->authenticate();
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% 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...
1092
            $result = $this->user->join('tickets', function ($join) use ($id) {
0 ignored issues
show
Documentation Bug introduced by
The method join does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1093
                $join->on('users.id', '=', 'tickets.assigned_to')
1094
                        ->where('status', '=', 1);
1095
                        //->where('user_id', '=', $id);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
1096
            })
1097
                    ->join('department', 'department.id', '=', 'tickets.dept_id')
1098
                    ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
1099
                    ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
1100
                    ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id')
1101
                    ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status')
1102
                    ->join('ticket_thread', function ($join) {
1103
                        $join->on('tickets.id', '=', 'ticket_thread.ticket_id')
1104
                        ->whereNotNull('title');
1105
                    })
1106
                    ->where('users.id', $id)
1107
                    ->select(\DB::raw('max(ticket_thread.updated_at) as updated_at'), 'user_name', 'first_name', 'last_name', 'email', 'profile_pic', 'ticket_number', 'tickets.id', 'title', 'tickets.created_at', 'department.name as department_name', 'ticket_priority.priority as priotity_name', 'sla_plan.name as sla_plan_name', 'help_topic.topic as help_topic_name', 'ticket_status.name as ticket_status_name')
1108
//                    ->where(function($query) use($user) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
1109
//                        if ($user->role != 'admin') {
1110
//                            $query->where('tickets.dept_id', '=', $user->primary_dpt);
1111
//                        }
1112
//                    })
1113
                    ->orderBy('updated_at', 'desc')
1114
                    ->groupby('tickets.id')
1115
                    ->distinct()
1116
                    ->paginate(10)
1117
                    ->toJson();
1118
1119
            return $result;
1120
        } catch (\Exception $e) {
1121
            $error = $e->getMessage();
1122
            $line = $e->getLine();
1123
            $file = $e->getFile();
1124
1125
            return response()->json(compact('error', 'file', 'line'));
1126
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
1127
            $error = $e->getMessage();
1128
1129
            return response()->json(compact('error'));
1130
        }
1131
    }
1132
1133
    public function getMyTicketsUser()
1134
    {
1135
        try {
1136
            $v = \Validator::make($this->request->all(), [
1137
                        'user_id' => 'required|exists:users,id',
1138
            ]);
1139
            if ($v->fails()) {
1140
                $error = $v->errors();
1141
1142
                return response()->json(compact('error'));
1143
            }
1144
            $id = $this->request->input('user_id');
1145
            if ($this->user->where('id', $id)->first()->role == 'admin' || $this->user->where('id', $id)->first()->role == 'agent') {
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1146
                $error = 'This is not a client';
1147
1148
                return response()->json(compact('error'));
1149
            }
1150
            $result = $this->user->join('tickets', function ($join) use ($id) {
0 ignored issues
show
Documentation Bug introduced by
The method join does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1151
                $join->on('users.id', '=', 'tickets.user_id')
1152
                        ->where('user_id', '=', $id);
1153
            })
1154
                    ->join('department', 'department.id', '=', 'tickets.dept_id')
1155
                    ->join('ticket_priority', 'ticket_priority.priority_id', '=', 'tickets.priority_id')
1156
                    ->join('sla_plan', 'sla_plan.id', '=', 'tickets.sla')
1157
                    ->join('help_topic', 'help_topic.id', '=', 'tickets.help_topic_id')
1158
                    ->join('ticket_status', 'ticket_status.id', '=', 'tickets.status')
1159
                    ->join('ticket_thread', function ($join) {
1160
                        $join->on('tickets.id', '=', 'ticket_thread.ticket_id')
1161
                        ->whereNotNull('title');
1162
                    })
1163
                    ->select('ticket_number', 'tickets.id', 'title', 'ticket_status.name as ticket_status_name')
1164
                    ->orderBy('ticket_thread.updated_at', 'desc')
1165
                    ->groupby('tickets.id')
1166
                    ->distinct()
1167
                    ->get()
1168
                    // ->paginate(10)
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
1169
                    ->toJson();
1170
1171
            return $result;
1172
        } catch (\Exception $e) {
1173
            $error = $e->getMessage();
1174
            $line = $e->getLine();
1175
            $file = $e->getFile();
1176
1177
            return response()->json(compact('error', 'file', 'line'));
1178
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
1179
            $error = $e->getMessage();
1180
1181
            return response()->json(compact('error'));
1182
        }
1183
    }
1184
1185
    public function getTicketById()
1186
    {
1187
        try {
1188
            $v = \Validator::make($this->request->all(), [
1189
                        'id' => 'required|exists:tickets,id',
1190
            ]);
1191
            if ($v->fails()) {
1192
                $error = $v->errors();
1193
1194
                return response()->json(compact('error'));
1195
            }
1196
            $id = $this->request->input('id');
1197 View Code Duplication
            if (!$this->model->where('id', $id)->first()) {
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\helpdesk\Ticket\Tickets>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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...
1198
                $error = 'There is no Ticket as ticket id: '.$id;
1199
1200
                return response()->json(compact('error'));
1201
            }
1202
            $query = $this->user->join('tickets', function ($join) use ($id) {
0 ignored issues
show
Documentation Bug introduced by
The method join does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1203
                $join->on('users.id', '=', 'tickets.user_id')
1204
                        ->where('tickets.id', '=', $id);
1205
            });
1206
1207
            $response = $this->differenciateHelpTopic($query)
1208
            ->leftJoin('department', 'tickets.dept_id', '=', 'department.id')
1209
            ->leftJoin('ticket_priority', 'tickets.priority_id', '=', 'ticket_priority.priority_id')
1210
            ->leftJoin('ticket_status', 'tickets.status', '=', 'ticket_status.id')
1211
            ->leftJoin('sla_plan', 'tickets.sla', '=', 'sla_plan.id')
1212
            ->leftJoin('ticket_source', 'tickets.source', '=', 'ticket_source.id');
1213
            //$select = 'users.email','users.user_name','users.first_name','users.last_name','tickets.id','ticket_number','num_sequence','user_id','priority_id','sla','max_open_ticket','captcha','status','lock_by','lock_at','source','isoverdue','reopened','isanswered','is_deleted', 'closed','is_transfer','transfer_at','reopened_at','duedate','closed_at','last_message_at';
0 ignored issues
show
Unused Code Comprehensibility introduced by
94% 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...
1214
1215
            $result = $response->addSelect(
1216
                    'users.email',
1217
                    'users.user_name',
1218
                    'users.first_name',
1219
                    'users.last_name',
1220
                    'tickets.id',
1221
                    'ticket_number',
1222
                    'user_id',
1223
                    'ticket_priority.priority_id',
1224
                    'ticket_priority.priority as priority_name',
1225
                    'department.name as dept_name',
1226
                    'ticket_status.name as status_name',
1227
                    'sla_plan.name as sla_name',
1228
                    'ticket_source.name as source_name',
1229
                    'sla_plan.id as sla',
1230
                    'ticket_status.id as status',
1231
                    'lock_by',
1232
                    'lock_at',
1233
                    'ticket_source.id as source',
1234
                    'isoverdue',
1235
                    'reopened',
1236
                    'isanswered',
1237
                    'is_deleted',
1238
                    'closed',
1239
                    'reopened_at',
1240
                    'duedate',
1241
                    'closed_at',
1242
                    'tickets.created_at',
1243
                    'tickets.updated_at')->first();
1244
1245
            return response()->json(compact('result'));
1246
        } catch (\Exception $e) {
1247
            $error = $e->getMessage();
1248
            $line = $e->getLine();
1249
            $file = $e->getFile();
1250
1251
            return response()->json(compact('error', 'file', 'line'));
1252
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
1253
            $error = $e->getMessage();
1254
1255
            return response()->json(compact('error'));
1256
        }
1257
    }
1258
1259
    public function createPagination($array, $perPage)
1260
    {
1261
        try {
1262
            //Get current page form url e.g. &page=6
1263
            $currentPage = LengthAwarePaginator::resolveCurrentPage();
1264
1265
            //Create a new Laravel collection from the array data
1266
            $collection = new Collection($array);
1267
1268
            //Slice the collection to get the items to display in current page
1269
            $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();
1270
1271
            //Create our paginator and pass it to the view
1272
            $paginatedResults = new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);
1273
1274
            return $paginatedResults;
1275
        } catch (\Exception $e) {
1276
            $error = $e->getMessage();
1277
            $line = $e->getLine();
1278
            $file = $e->getFile();
1279
1280
            return response()->json(compact('error', 'file', 'line'));
1281
        } catch (\TokenExpiredException $e) {
0 ignored issues
show
Bug introduced by
The class TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
1282
            $error = $e->getMessage();
1283
1284
            return response()->json(compact('error'));
1285
        }
1286
    }
1287
1288
    public function collaboratorSearch()
1289
    {
1290
        $this->validate($this->request, ['term' => 'required']);
1291
        try {
1292
            $emails = $this->ticket->autosearch();
1293
            //return $emails;
1294
            $user = new User();
1295
            if (count($emails) > 0) {
1296
                foreach ($emails as $key => $email) {
1297
                    $user_model = $user->where('email', $email)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1298
                    //return $user_model;
1299
                    $users[$key]['name'] = $user_model->first_name.' '.$user_model->last_name;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$users was never initialized. Although not strictly required by PHP, it is generally a good practice to add $users = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1300
                    $users[$key]['email'] = $email;
1301
                    $users[$key]['avatar'] = $this->avatarUrl($email);
1302
                }
1303
            }
1304
            //return $users;
1305
1306
            return response()->json(compact('users'));
1307
        } catch (\Exception $e) {
1308
            $error = $e->getMessage();
1309
            $line = $e->getLine();
1310
            $file = $e->getFile();
1311
1312
            return response()->json(compact('error', 'file', 'line'));
1313
        }
1314
    }
1315
1316 View Code Duplication
    public function avatarUrl($email)
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...
1317
    {
1318
        try {
1319
            $user = new User();
1320
            $user = $user->where('email', $email)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1321
            if ($user->profile_pic) {
1322
                $url = url('uploads/profilepic/'.$user->profile_pic);
1323
            } else {
1324
                $url = \Gravatar::src($email);
1325
            }
1326
1327
            return $url;
1328
        } catch (\Exception $ex) {
1329
            //return $ex->getMessage();
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
1330
            throw new \Exception($ex->getMessage());
1331
        }
1332
    }
1333
1334 View Code Duplication
    public function addCollaboratorForTicket()
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...
1335
    {
1336
        try {
1337
            $v = \Validator::make(\Input::get(), [
0 ignored issues
show
Bug introduced by
The call to get() misses a required argument $key.

This check looks for function calls that miss required arguments.

Loading history...
1338
                        'email'     => 'required|email|unique:users',
1339
                        'ticket_id' => 'required',
1340
                            ]
1341
            );
1342
            if ($v->fails()) {
1343
                $error = $v->messages();
1344
1345
                return response()->json(compact('error'));
1346
            }
1347
            $collaborator = $this->ticket->useradd();
1348
1349
            return response()->json(compact('collaborator'));
1350
        } catch (\Exception $e) {
1351
            $error = $e->getMessage();
1352
            $line = $e->getLine();
1353
            $file = $e->getFile();
1354
1355
            return response()->json(compact('error', 'file', 'line'));
1356
        } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $ex) {
0 ignored issues
show
Bug introduced by
The class App\Http\Controllers\Api...s\TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
1357
            $error = $e->getMessage();
1358
            $line = $e->getLine();
1359
            $file = $e->getFile();
1360
1361
            return response()->json(compact('error', 'file', 'line'));
1362
        }
1363
    }
1364
1365 View Code Duplication
    public function getCollaboratorForTicket()
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...
1366
    {
1367
        try {
1368
            $v = \Validator::make(\Input::get(), [
0 ignored issues
show
Bug introduced by
The call to get() misses a required argument $key.

This check looks for function calls that miss required arguments.

Loading history...
1369
                        'ticket_id' => 'required',
1370
                            ]
1371
            );
1372
            if ($v->fails()) {
1373
                $error = $v->messages();
1374
1375
                return response()->json(compact('error'));
1376
            }
1377
            $collaborator = $this->ticket->getCollaboratorForTicket();
1378
1379
            return response()->json(compact('collaborator'));
1380
        } catch (\Exception $e) {
1381
            $error = $e->getMessage();
1382
            $line = $e->getLine();
1383
            $file = $e->getFile();
1384
1385
            return response()->json(compact('error', 'file', 'line'));
1386
        } catch (Tymon\JWTAuth\Exceptions\TokenExpiredException $ex) {
0 ignored issues
show
Bug introduced by
The class App\Http\Controllers\Api...s\TokenExpiredException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
1387
            $error = $e->getMessage();
1388
            $line = $e->getLine();
1389
            $file = $e->getFile();
1390
1391
            return response()->json(compact('error', 'file', 'line'));
1392
        }
1393
    }
1394
1395
    public function deleteCollaborator()
1396
    {
1397
        try {
1398
            $v = \Validator::make(\Input::get(), [
0 ignored issues
show
Bug introduced by
The call to get() misses a required argument $key.

This check looks for function calls that miss required arguments.

Loading history...
1399
                        'ticketid' => 'required',
1400
                        'email'    => 'required',
1401
                            ]
1402
            );
1403
            if ($v->fails()) {
1404
                $result = $v->messages();
1405
1406
                return response()->json(compact('result'));
1407
            }
1408
            $collaborator = $this->ticket->userremove();
1409
1410
            return response()->json(compact('collaborator'));
1411
        } catch (\Exception $ex) {
1412
            $error = $e->getMessage();
0 ignored issues
show
Bug introduced by
The variable $e does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
1413
            $line = $e->getLine();
1414
            $file = $e->getFile();
1415
1416
            return response()->json(compact('error', 'file', 'line'));
1417
        }
1418
    }
1419
1420
    public function dependency()
1421
    {
1422
        try {
1423
            $department = $this->department->select('name', 'id')->get()->toArray();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Model\helpdesk\Agent\Department>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1424
            $sla = $this->slaPlan->select('name', 'id')->get()->toArray();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Model\helpdesk\Manage\Sla_plan>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1425
            $staff = $this->user->where('role', 'agent')->select('email', 'id')->get()->toArray();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\User>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1426
            $team = $this->team->select('name', 'id')->get()->toArray();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Model\helpdesk\Agent\Teams>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1427
            $priority = \DB::table('ticket_priority')->select('priority', 'priority_id')->get();
1428
            $helptopic = $this->helptopic->select('topic', 'id')->get()->toArray();
0 ignored issues
show
Documentation Bug introduced by
The method select does not exist on object<App\Model\helpdesk\Manage\Help_topic>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
1429
            $status = \DB::table('ticket_status')->select('name', 'id')->get();
1430
            $source = \DB::table('ticket_source')->select('name', 'id')->get();
1431
            $result = ['departments' => $department, 'sla' => $sla, 'staffs' => $staff, 'teams' => $team,
1432
                'priorities'         => $priority, 'helptopics' => $helptopic, 'status' => $status, 'sources' => $source, ];
1433
1434
            return response()->json(compact('result'));
1435
        } catch (\Exception $e) {
1436
            $error = $e->getMessage();
1437
            $line = $e->getLine();
1438
            $file = $e->getFile();
1439
1440
            return response()->json(compact('error', 'file', 'line'));
1441
        }
1442
    }
1443
1444
    public function differenciateHelpTopic($query)
1445
    {
1446
        $ticket = $query->first();
1447
        $check = 'department';
1448
        if ($ticket) {
1449
            if ($ticket->dept_id && $ticket->help_topic_id) {
1450
                return $this->getSystem($check, $query);
1451
            }
1452
            if (!$ticket->dept_id && $ticket->help_topic_id) {
1453
                return $query->select('tickets.help_topic_id');
1454
            }
1455
            if ($ticket->dept_id && !$ticket->help_topic_id) {
1456
                return $query->select('tickets.dept_id');
1457
            }
1458
        }
1459
1460
        return $query;
1461
    }
1462
1463
    public function getSystem($check, $query)
1464
    {
1465
        switch ($check) {
1466
            case 'department':
1467
                return $query->select('tickets.dept_id');
1468
            case 'helpTopic':
1469
                return $query->select('tickets.help_topic_id');
1470
            default:
1471
                return $query->select('tickets.dept_id');
1472
        }
1473
    }
1474
1475
    /**
1476
     * Register a user with username and password.
1477
     *
1478
     * @param Request $request
1479
     *
1480
     * @return type json
1481
     */
1482
    public function register(Request $request)
1483
    {
1484
        try {
1485
            $v = \Validator::make($request->all(), [
1486
                        'email'    => 'required|email|unique:users',
1487
                        'password' => 'required|min:6',
1488
            ]);
1489
            if ($v->fails()) {
1490
                $error = $v->errors();
1491
1492
                return response()->json(compact('error'));
1493
            }
1494
            $auth = $this->user;
1495
            $email = $request->input('email');
1496
            $username = $request->input('email');
1497
            $password = \Hash::make($request->input('password'));
1498
            $role = $request->input('role');
1499
            if ($auth->role == 'agent') {
0 ignored issues
show
Documentation introduced by
The property role does not exist on object<App\User>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1500
                $role = 'user';
1501
            }
1502
            $user = new User();
1503
            $user->password = $password;
0 ignored issues
show
Documentation introduced by
The property password does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1504
            $user->user_name = $username;
0 ignored issues
show
Documentation introduced by
The property user_name does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1505
            $user->email = $email;
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1506
            $user->role = $role;
0 ignored issues
show
Documentation introduced by
The property role does not exist on object<App\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
1507
            $user->save();
1508
1509
            return response()->json(compact('user'));
1510
        } catch (\Exception $e) {
1511
            $error = $e->getMessage();
1512
1513
            return response()->json(compact('error'));
1514
        }
1515
    }
1516
}
1517