GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Authenticator::logout()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\LittleGateKeeper;
4
5
use Illuminate\Session\Store as Session;
6
7
class Authenticator
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $username;
13
14
    /**
15
     * @var string
16
     */
17
    protected $password;
18
19
    /**
20
     * @var string
21
     */
22
    protected $sessionKey;
23
24
    /**
25
     * @var \Illuminate\Session\Store
26
     */
27
    protected $session;
28
29
    /**
30
     * @param  string $username
31
     * @param  string $password
32
     * @param  string $sessionKey
33
     * @param  \Illuminate\Session\Store $session
34
     */
35
    public function __construct($username, $password, $sessionKey, Session $session)
36
    {
37
        $this->username   = $username;
38
        $this->password   = $password;
39
        $this->sessionKey = $sessionKey;
40
        $this->session    = $session;
41
    }
42
43
    /**
44
     * @return bool
45
     */
46
    public function isAuthenticated()
47
    {
48
        return $this->session->has($this->sessionKey);
49
    }
50
51
    /**
52
     * @param  array $credentials
53
     * @return bool
54
     */
55
    public function attempt($credentials)
56
    {
57
        $valid = $this->validateCredentials($credentials);
58
59
        if ($valid) {
60
            $this->login();
61
            return true;
62
        }
63
64
        return false;
65
    }
66
67
    /**
68
     * @param  array $credentials  Format: ['username' => '...', 'password' => '...']
69
     * @return bool
70
     */
71
    protected function validateCredentials($credentials)
72
    {
73
        if (!isset($credentials['username']) || !isset($credentials['password'])) {
74
            return false;
75
        }
76
77
        return ($credentials['username'] === $this->username && $credentials['password'] === $this->password);
78
    }
79
80
    protected function login()
81
    {
82
        $this->session->put($this->sessionKey, true);
83
    }
84
85
    public function logout()
86
    {
87
        $this->session->forget($this->sessionKey);
88
    }
89
}
90