Passed
Pull Request — 2.x (#586)
by Bekzat
05:24 queued 25s
created

ImpersonateController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 36
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A stopImpersonate() 0 4 1
A impersonate() 0 8 2
1
<?php
2
3
namespace A17\Twill\Http\Controllers\Admin;
4
5
use A17\Twill\Repositories\UserRepository;
6
use Illuminate\Auth\AuthManager;
7
8
class ImpersonateController extends Controller
9
{
10
    /**
11
     * @var AuthManager
12
     */
13
    protected $authManager;
14
15
    public function __construct(AuthManager $authManager)
16
    {
17
        parent::__construct();
18
19
        $this->authManager = $authManager;
20
    }
21
22
    /**
23
     * @param int $id
24
     * @param UserRepository $users
25
     * @return \Illuminate\Http\RedirectResponse
26
     */
27
    public function impersonate($id, UserRepository $users)
28
    {
29
        if ($this->authManager->guard('twill_users')->user()->can('impersonate')) {
30
            $user = $users->getById($id);
31
            $this->authManager->guard('twill_users')->user()->setImpersonating($user->id);
0 ignored issues
show
Bug introduced by
The method setImpersonating() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
            $this->authManager->guard('twill_users')->user()->/** @scrutinizer ignore-call */ setImpersonating($user->id);
Loading history...
32
        }
33
34
        return back();
35
    }
36
37
    /**
38
     * @return \Illuminate\Http\RedirectResponse
39
     */
40
    public function stopImpersonate()
41
    {
42
        $this->authManager->guard('twill_users')->user()->stopImpersonating();
0 ignored issues
show
Bug introduced by
The method stopImpersonating() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        $this->authManager->guard('twill_users')->user()->/** @scrutinizer ignore-call */ stopImpersonating();
Loading history...
43
        return back();
44
    }
45
}
46