IlluminateAuthAdapter::byId()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4286
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Tymon\JWTAuth\Providers\Auth;
4
5
use Exception;
6
use Illuminate\Auth\AuthManager;
7
8
class IlluminateAuthAdapter implements AuthInterface
9
{
10
    /**
11
     * @var \Illuminate\Auth\AuthManager
12
     */
13
    protected $auth;
14
15
    /**
16
     * @param \Illuminate\Auth\AuthManager  $auth
17
     */
18 12
    public function __construct(AuthManager $auth)
19
    {
20 12
        $this->auth = $auth;
21 12
    }
22
23
    /**
24
     * Check a user's credentials
25
     *
26
     * @param  array  $credentials
27
     * @return bool
28
     */
29 3
    public function byCredentials(array $credentials = [])
30
    {
31 3
        return $this->auth->once($credentials);
32
    }
33
34
    /**
35
     * Authenticate a user via the id
36
     *
37
     * @param  mixed  $id
38
     * @return bool
39
     */
40 6
    public function byId($id)
41
    {
42
        try {
43 6
            return $this->auth->onceUsingId($id);
44 3
        } catch (Exception $e) {
45 3
            return false;
46
        }
47
    }
48
49
    /**
50
     * Get the currently authenticated user
51
     *
52
     * @return mixed
53
     */
54 3
    public function user()
55
    {
56 3
        return $this->auth->user();
57
    }
58
}
59