These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use Illuminate\Contracts\Auth\Authenticatable; |
||
4 | |||
5 | if (! function_exists('can_impersonate')) { |
||
6 | |||
7 | /** |
||
8 | * Check whether the current user is authorized to impersonate. |
||
9 | * |
||
10 | * @param null $guard |
||
11 | * @return bool |
||
12 | */ |
||
13 | View Code Duplication | function can_impersonate(string $guard = null): bool |
|
0 ignored issues
–
show
|
|||
14 | { |
||
15 | $guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); |
||
16 | |||
17 | return app('auth')->guard($guard)->check() |
||
18 | && app('auth')->guard($guard)->user()->canImpersonate(); |
||
19 | } |
||
20 | } |
||
21 | |||
22 | if (! function_exists('can_be_impersonated')) { |
||
23 | |||
24 | /** |
||
25 | * Check whether the specified user can be impersonated. |
||
26 | * |
||
27 | * @param Authenticatable $user |
||
28 | * @param string|null $guard |
||
29 | * @return bool |
||
30 | */ |
||
31 | function can_be_impersonated(Authenticatable $user, string $guard = null): bool |
||
32 | { |
||
33 | $guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); |
||
34 | |||
35 | return app('auth')->guard($guard)->check() |
||
36 | && app('auth')->guard($guard)->user()->id != $user->id |
||
37 | && $user->canBeImpersonated(); |
||
38 | } |
||
39 | } |
||
40 | |||
41 | if (! function_exists('is_impersonating')) { |
||
42 | |||
43 | /** |
||
44 | * Check whether the current user is being impersonated. |
||
45 | * |
||
46 | * @param string|null $guard |
||
47 | * @return bool |
||
48 | */ |
||
49 | View Code Duplication | function is_impersonating(string $guard = null): bool |
|
0 ignored issues
–
show
This function 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...
|
|||
50 | { |
||
51 | $guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); |
||
52 | |||
53 | return app('auth')->guard($guard)->check() |
||
54 | && app('auth')->guard($guard)->user()->isImpersonated(); |
||
55 | } |
||
56 | } |
||
57 |
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.