AuthController::logout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Signifly\Janitor\Http\Controllers;
4
5
use Illuminate\Http\JsonResponse;
6
use Illuminate\Http\Request;
7
use Illuminate\Routing\Controller;
8
use Signifly\Janitor\Contracts\Factory;
9
10
class AuthController extends Controller
11
{
12
    protected $proxy;
13
14
    public function __construct(Factory $proxy)
15
    {
16
        $this->proxy = $proxy->driver(config('janitor.default'));
17
    }
18
19
    public function login(Request $request)
20
    {
21
        $usernameField = $this->proxy->getUsernameField();
0 ignored issues
show
Bug introduced by
The method getUsernameField() does not exist on Signifly\Janitor\Contracts\Proxy. Since it exists in all sub-types, consider adding an abstract or default implementation to Signifly\Janitor\Contracts\Proxy. ( Ignorable by Annotation )

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

21
        /** @scrutinizer ignore-call */ 
22
        $usernameField = $this->proxy->getUsernameField();
Loading history...
22
23
        $request->validate([
24
            $usernameField => 'required',
25
            'password' => 'required',
26
        ]);
27
28
        $data = $this->proxy->attemptLogin(
29
            $request->input($usernameField),
30
            $request->input('password')
31
        );
32
33
        return new JsonResponse($data);
34
    }
35
36
    public function logout()
37
    {
38
        return new JsonResponse(['message' => 'Successfully logged out.']);
39
    }
40
41
    public function refresh(Request $request)
42
    {
43
        $data = $this->proxy->attemptRefresh(
44
            $request->input('refresh_token')
45
        );
46
47
        return new JsonResponse($data);
48
    }
49
}
50