AuthEventListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 4
Bugs 1 Features 0
Metric Value
c 4
b 1
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace AuthService;
4
5
use AuthService\Contracts\AuthEventListenerInterface;
6
use AuthService\Contracts\AuthServiceConfigInterface;
7
use Illuminate\Routing\Redirector;
8
9
class AuthEventListener implements AuthEventListenerInterface
10
{
11
    /**
12
     * Redirector instance.
13
     *
14
     * @var \Illuminate\Routing\Redirector
15
     */
16
    protected $redirector;
17
18
    /**
19
     * AuthServiceConfig instance.
20
     *
21
     * @var \AuthService\Contracts\AuthServiceConfigInterface
22
     */
23
    protected $config;
24
25
    /**
26
     * Create a new instance of AuthEventListener class.
27
     *
28
     * @param \Illuminate\Routing\Redirector $redirector
29
     * @param \AuthService\Contracts\AuthServiceConfigInterface $config
30
     */
31 5
    public function __construct(Redirector $redirector, AuthServiceConfigInterface $config)
32
    {
33 5
        $this->redirector = $redirector;
34 5
        $this->config = $config;
35 5
    }
36
37
    /**
38
     * Get redirector instance.
39
     *
40
     * @return \Illuminate\Routing\Redirector
41
     */
42 4
    public function redirector()
43
    {
44 4
        return $this->redirector;
45
    }
46
47
    /**
48
     * Get AuthServiceConfig instance.
49
     *
50
     * @return \AuthService\Contracts\AuthServiceConfigInterface
51
     */
52 4
    public function config()
53
    {
54 4
        return $this->config;
55
    }
56
57
    /**
58
     * User has logged in successfully.
59
     *
60
     * @return \Illuminate\Http\RedirectResponse
61
     */
62 1
    public function userHasLoggedIn()
63
    {
64 1
        return $this->redirector()
65 1
            ->intended($this->config()->afterLoginSuccessPath());
66
    }
67
68
    /**
69
     * User has failed to login.
70
     *
71
     * @return \Illuminate\Http\RedirectResponse
72
     */
73 1
    public function userHasFailedToLogIn()
74
    {
75 1
        return $this->redirector()
76 1
            ->back()
77 1
            ->exceptInput('password')
78 1
            ->withErrors([$this->config()->loginFailedMessage()]);
79
    }
80
81
    /**
82
     * User has logged out successfully.
83
     *
84
     * @return \Illuminate\Http\RedirectResponse
85
     */
86 1
    public function userHasLoggedOut()
87
    {
88 1
        return $this->redirector()
89 1
            ->to($this->config()->afterLogoutSuccessPath());
90
    }
91
}
92