Passed
Pull Request — 2.x (#586)
by Bekzat
04:25
created

ImpersonateController::stopImpersonate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
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