Completed
Push — master ( ab60f2...c901a1 )
by Ricardo
07:00
created

DirectoryController::update()   F

Complexity

Conditions 37
Paths > 20000

Size

Total Lines 190

Duplication

Lines 112
Ratio 58.95 %

Importance

Changes 0
Metric Value
dl 112
loc 190
rs 0
c 0
b 0
f 0
cc 37
nc 917112
nop 2

How to fix   Long Method    Complexity   

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 Fabrica\Http\Api;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Event;
7
8
use Fabrica\Http\Requests;
9
use Fabrica\Http\Api\Controller;
10
11
use Fabrica\Acl\Eloquent\Group;
12
use Cartalyst\Sentinel\Users\EloquentUser;
13
use Fabrica\ActiveDirectory\Eloquent\Directory;
14
use Fabrica\ActiveDirectory\LDAP;
15
16
use Fabrica\Events\DelGroupEvent;
17
use Fabrica\Events\DelUserEvent;
18
19
class DirectoryController extends Controller
20
{
21
    public function __construct()
22
    {
23
        $this->middleware('privilege:sys_admin');
24
        parent::__construct();
25
    }
26
27
    /**
28
     * Display a listing of the resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function index(Request $request)
33
    {
34
        $directories =  Directory::all()->toArray();
35
        foreach($directories as $k => $d)
36
        {
37
            if (isset($d['configs']) && $d['configs'] && isset($d['configs']['admin_password']))
38
            {
39
                unset($directories[$k]['configs']['admin_password']);
40
            }
41
        }
42
        return Response()->json([ 'ecode' => 0, 'data' => $directories ]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
43
    }
44
45
    /**
46
     * Store a newly created resource in storage.
47
     *
48
     * @param  \Illuminate\Http\Request  $request
49
     * @return \Illuminate\Http\Response
50
     */
51
    public function store(Request $request)
52
    {
53
        if (!($name = $request->input('name')))
54
        {
55
            throw new \UnexpectedValueException('the name can not be empty.', -10300);
56
        }
57
58
        $configs = [];
59
        if (!($host = $request->input('host')))
60
        {
61
            throw new \UnexpectedValueException('the host can not be empty.', -10301);
62
        }
63
        $configs['host'] = $host;
64
65
        if (!($port = $request->input('port')))
66
        {
67
            throw new \UnexpectedValueException('the port can not be empty.', -10302);
68
        }
69
        $configs['port'] = intval($port);
70
71
        $configs['encryption'] = $request->input('encryption') ?: '';
72
73
        if (!($admin_username = $request->input('admin_username')))
74
        {
75
            throw new \UnexpectedValueException('the username can not be empty.', -10303);
76
        }
77
        $configs['admin_username'] = $admin_username;
78
79
        if (!($admin_password = $request->input('admin_password')))
80
        {
81
            throw new \UnexpectedValueException('the user password can not be empty.', -10304);
82
        }
83
        $configs['admin_password'] = $admin_password;
84
85
        if (!($base_dn = $request->input('base_dn')))
86
        {
87
            throw new \UnexpectedValueException('the base_dn can not be empty.', -10305);
88
        }
89
        $configs['base_dn'] = $base_dn;
90
91
        $configs['additional_user_dn'] = $request->input('additional_user_dn') ?: '';
92
        $configs['additional_group_dn'] = $request->input('additional_group_dn') ?: '';
93
94
        if (!($user_object_class = $request->input('user_object_class')))
95
        {
96
            throw new \UnexpectedValueException('the user object class can not be empty.', -10306);
97
        }
98
        $configs['user_object_class'] = $user_object_class;
99
100
        if (!($user_object_filter = $request->input('user_object_filter')))
101
        {
102
            throw new \UnexpectedValueException('the user object filter can not be empty.', -10307);
103
        }
104
        $configs['user_object_filter'] = $user_object_filter;
105
106
        if (!($user_name_attr = $request->input('user_name_attr')))
107
        {
108
            throw new \UnexpectedValueException('the user name attributte can not be empty.', -10308);
109
        }
110
        $configs['user_name_attr'] = $user_name_attr;
111
112
        if (!($user_email_attr = $request->input('user_email_attr')))
113
        {
114
            throw new \UnexpectedValueException('the user email attributte can not be empty.', -10309);
115
        }
116
        $configs['user_email_attr'] = $user_email_attr;
117
118
119
        if (!($group_object_class = $request->input('group_object_class')))
120
        {
121
            throw new \UnexpectedValueException('the group object class can not be empty.', -10310);
122
        }
123
        $configs['group_object_class'] = $group_object_class;
124
125
        if (!($group_object_filter = $request->input('group_object_filter')))
126
        {
127
            throw new \UnexpectedValueException('the group object filter can not be empty.', -10311);
128
        }
129
        $configs['group_object_filter'] = $group_object_filter;
130
131
        if (!($group_name_attr = $request->input('group_name_attr')))
132
        {
133
            throw new \UnexpectedValueException('the group name attributte can not be empty.', -10312);
134
        }
135
        $configs['group_name_attr'] = $group_name_attr;
136
137
        if (!($group_membership_attr = $request->input('group_membership_attr')))
138
        {
139
            throw new \UnexpectedValueException('the group membership attributte can not be empty.', -10313);
140
        }
141
        $configs['group_membership_attr'] = $group_membership_attr;
142
143
        $directory = Directory::create([ 'name' => $name, 'type' => 'OpenLDAP', 'invalid_flag' => 0, 'configs' => $configs ]);
144
        return Response()->json([ 'ecode' => 0, 'data' => $directory ]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
145
    }
146
147
    /**
148
     * Display the specified resource.
149
     *
150
     * @param  int  $id
151
     * @return \Illuminate\Http\Response
152
     */
153 View Code Duplication
    public function show($id)
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...
154
    {
155
        $directory = Directory::find($id);
156
        if (!$directory)
157
        {
158
            throw new \UnexpectedValueException('the directory does not exist.', -10314);
159
        }
160
        return Response()->json([ 'ecode' => 0, 'data' => $directory ]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
161
    }
162
163
    /**
164
     * Update the specified resource in storage.
165
     *
166
     * @param  \Illuminate\Http\Request  $request
167
     * @param  int  $id
168
     * @return \Illuminate\Http\Response
169
     */
170
    public function update(Request $request, $id)
171
    {
172
        $directory = Directory::find($id);
173
        if (!$directory)
174
        {
175
            throw new \UnexpectedValueException('the directory does not exist.', -10314);
176
        }
177
178
        $updValues = [];
179
180
        $name = $request->input('name');
181 View Code Duplication
        if (isset($name))
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...
182
        {
183
            if (!$name)
184
            {
185
                throw new \UnexpectedValueException('the name can not be empty.', -10300);
186
            }
187
            $updValues['name'] = $name;
188
        }
189
190
        $configs = [];
191
192
        $host = $request->input('host');
193 View Code Duplication
        if (isset($host))
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...
194
        {
195
            if (!$host)
196
            {
197
                throw new \UnexpectedValueException('the host can not be empty.', -10301);
198
            }
199
            $configs['host'] = $host;
200
        }
201
202
        $port = $request->input('port'); 
203 View Code Duplication
        if (isset($port))
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...
204
        {
205
            if (!$port)
206
            {
207
                throw new \UnexpectedValueException('the port can not be empty.', -10302);
208
            }
209
            $configs['port'] = intval($port);
210
        }
211
212
        $encryption = $request->input('encryption');
213
        if (isset($encryption))
214
        {
215
            $configs['encryption'] = $encryption;
216
        }
217
218
        $admin_username = $request->input('admin_username');
219 View Code Duplication
        if (isset($admin_username))
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...
220
        {
221
            if (!$admin_username)
222
            {
223
                throw new \UnexpectedValueException('the username can not be empty.', -10303);
224
            }
225
            $configs['admin_username'] = $admin_username;
226
        }
227
228
        $admin_password = $request->input('admin_password');
229 View Code Duplication
        if (isset($admin_password))
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...
230
        {
231
            if (!$admin_password)
232
            {
233
                throw new \UnexpectedValueException('the user password can not be empty.', -10304);
234
            }
235
            $configs['admin_password'] = $admin_password;
236
        }
237
238
        $base_dn = $request->input('base_dn');
239 View Code Duplication
        if (isset($base_dn))
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...
240
        {
241
            if (!$base_dn)
242
            {
243
                throw new \UnexpectedValueException('the base_dn can not be empty.', -10305);
244
            }
245
            $configs['base_dn'] = $base_dn;
246
        }
247
248
        $additional_user_dn = $request->input('additional_user_dn');
249
        if (isset($additional_user_dn))
250
        {
251
            $configs['additional_user_dn'] = $additional_user_dn;
252
        }
253
254
        $additional_group_dn = $request->input('additional_group_dn');
255
        if (isset($additional_group_dn))
256
        {
257
            $configs['additional_group_dn'] = $additional_group_dn;
258
        }
259
260
        $user_object_class = $request->input('user_object_class');
261 View Code Duplication
        if (isset($user_object_class))
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...
262
        {
263
            if (!$user_object_class)
264
            {
265
                throw new \UnexpectedValueException('the user object class can not be empty.', -10306);
266
            }
267
            $configs['user_object_class'] = $user_object_class;
268
        }
269
270
        $user_object_filter = $request->input('user_object_filter');
271 View Code Duplication
        if (isset($user_object_filter))
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...
272
        {
273
            if (!$user_object_filter)
274
            {
275
                throw new \UnexpectedValueException('the user object filter can not be empty.', -10307);
276
            }
277
            $configs['user_object_filter'] = $user_object_filter;
278
        }
279
280
        $user_name_attr = $request->input('user_name_attr');
281 View Code Duplication
        if (isset($user_name_attr))
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...
282
        {
283
            if (!$user_name_attr)
284
            {
285
                throw new \UnexpectedValueException('the user name attributte can not be empty.', -10308);
286
            }
287
            $configs['user_name_attr'] = $user_name_attr;
288
        }
289
290
        $user_email_attr = $request->input('user_email_attr');
291 View Code Duplication
        if (isset($user_email_attr))
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...
292
        {
293
            if (!$user_email_attr)
294
            {
295
                throw new \UnexpectedValueException('the user email attributte can not be empty.', -10309);
296
            }
297
            $configs['user_email_attr'] = $user_email_attr;
298
        }
299
300
        $group_object_class = $request->input('group_object_class');
301 View Code Duplication
        if (isset($group_object_class))
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...
302
        {
303
            if (!$group_object_class)
304
            {
305
                throw new \UnexpectedValueException('the group object class can not be empty.', -10310);
306
            }
307
            $configs['group_object_class'] = $group_object_class;
308
        }
309
310
        $group_object_filter = $request->input('group_object_filter');
311 View Code Duplication
        if (isset($group_object_filter))
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...
312
        {
313
            if (!$group_object_filter)
314
            {
315
                throw new \UnexpectedValueException('the group object filter can not be empty.', -10311);
316
            }
317
            $configs['group_object_filter'] = $group_object_filter;
318
        }
319
320
        $group_name_attr = $request->input('group_name_attr');
321 View Code Duplication
        if (isset($group_name_attr))
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...
322
        {
323
            if (!$group_name_attr)
324
            {
325
                throw new \UnexpectedValueException('the group name attributte can not be empty.', -10312);
326
            }
327
            $configs['group_name_attr'] = $group_name_attr;
328
        }
329
330
        $group_membership_attr = $request->input('group_membership_attr');
331 View Code Duplication
        if (isset($group_membership_attr))
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...
332
        {
333
            if (!$group_membership_attr)
334
            {
335
                throw new \UnexpectedValueException('the group membership attributte can not be empty.', -10313);
336
            }
337
            $configs['group_membership_attr'] = $group_membership_attr;
338
        }
339
340
        if ($configs)
0 ignored issues
show
Bug Best Practice introduced by
The expression $configs of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
341
        {
342
            $updValues['configs'] = isset($directory->configs) ? array_merge($directory->configs ?: [], $configs) : $configs;
343
        }
344
345
        $invalid_flag = $request->input('invalid_flag');
346
        if (isset($invalid_flag))
347
        {
348
            $updValues['invalid_flag'] = intval($invalid_flag);
349
        }
350
        
351
        $directory->fill($updValues)->save();
352
353
        //if (isset($invalid_flag))
354
        //{
355
        //    EloquentUser::where('directory', $id)->update([ 'invalid_flag' => intval($invalid_flag) ]);
356
        //}
357
358
        return $this->show($id);
359
    }
360
361
    /**
362
     * Remove the specified resource from storage.
363
     *
364
     * @param  int  $id
365
     * @return \Illuminate\Http\Response
366
     */
367
    public function destroy($id)
368
    {
369
        ini_set('memory_limit', '-1');
370
        ini_set('max_execution_time', '0');
371
372
        $directory = Directory::find($id);
373
        if (!$directory)
374
        {
375
            throw new \UnexpectedValueException('the directory does not exist.', -10314);
376
        }
377
378
        // delete the related groups
379
        $groups = Group::where('directory', $id)->get();
380
        foreach ($groups as $group)
381
        {
382
            $group->delete();
383
            Event::fire(new DelGroupEvent($group->id));
384
        }
385
386
        $users = EloquentUser::where('directory', $id)->get();
387
        foreach ($users as $user)
388
        {
389
            $user->delete();
390
            Event::fire(new DelUserEvent($user->id));
391
        }
392
393
        Directory::destroy($id);
394
        return Response()->json([ 'ecode' => 0, 'data' => [ 'id' => $id ] ]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
395
    }
396
397
    /**
398
     * test the ldap.
399
     *
400
     * @param  int  $id
401
     * @return \Illuminate\Http\Response
402
     */
403
    public function test($id) 
404
    {
405
        ini_set('memory_limit', '-1');
406
        ini_set('max_execution_time', '0');
407
408
        $directory = Directory::find($id);
409
        if (!$directory)
410
        {
411
            throw new \UnexpectedValueException('the directory does not exist.', -10201);
412
        }
413
414
        $configs = [
415
            'default' => $directory->configs
416
        ];
417
418
        $ret = LDAP::test($configs);
419
        return Response()->json([ 'ecode' => 0, 'data' => array_pop($ret) ]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
420
    }
421
422
    /**
423
     * sync the users and group.
424
     *
425
     * @param  int  $id
426
     * @return \Illuminate\Http\Response
427
     */
428
    public function sync($id) 
429
    {
430
        ini_set('memory_limit', '-1');
431
        ini_set('max_execution_time', '0');
432
433
        $directory = Directory::find($id);
434
        if (!$directory)
435
        {
436
            throw new \UnexpectedValueException('the directory does not exist.', -10314);
437
        }
438
439
        $configs = [
440
            $id => $directory->configs
441
        ];
442
443
        $ret = LDAP::sync($configs);
444
        $sync_info = array_pop($ret);
445
        if (!$sync_info['connect'])
446
        {
447
            throw new \UnexpectedValueException('the connect server failed.', -10315);
448
        }
449
        else if (!$sync_info['user'])
450
        {
451
            throw new \UnexpectedValueException('the user sync failed.', -10316);
452
        }
453
        else if (!$sync_info['group'])
454
        {
455
            throw new \UnexpectedValueException('the group sync failed.', -10317);
456
        }
457
458
        return Response()->json([ 'ecode' => 0, 'data' => [ 'user' => $sync_info['user'], 'group' => $sync_info['group'] ] ]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
459
    }
460
}
461