RainAuthAdapter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Autumn\JWTAuth\Classes;
4
5
use October\Rain\Auth\AuthException;
6
use RainLab\User\Classes\AuthManager;
7
use Tymon\JWTAuth\Providers\Auth\AuthInterface;
8
9
class RainAuthAdapter implements AuthInterface
10
{
11
    /**
12
     * @var \RainLab\User\Classes\AuthManager
13
     */
14
    protected $auth;
15
16
    public function __construct()
17
    {
18
        $this->auth = AuthManager::instance();
19
    }
20
21
    /**
22
     * Check a user's credentials.
23
     *
24
     * @param array $credentials
25
     *
26
     * @return mixed
27
     */
28
    public function byCredentials(array $credentials = [])
29
    {
30
        try {
31
            $user = $this->auth->findUserByCredentials($credentials);
32
            $this->auth->setUser($user);
33
34
            return $user;
35
        } catch (AuthException $e) {
0 ignored issues
show
Bug introduced by
The class October\Rain\Auth\AuthException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
36
            return false;
37
        }
38
    }
39
40
    /**
41
     * Authenticate a user via the id.
42
     *
43
     * @param mixed $id
44
     *
45
     * @return bool
46
     */
47
    public function byId($id)
48
    {
49
        if (! is_null($user = $this->auth->findUserById($id))) {
50
            $this->auth->setUser($user);
51
52
            return true;
53
        }
54
55
        return false;
56
    }
57
58
    /**
59
     * Get the currently authenticated user.
60
     *
61
     * @return \RainLab\User\Models\User
62
     */
63
    public function user()
64
    {
65
        return $this->auth->getUser();
66
    }
67
}
68