AMethods::getNextMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

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
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace kalanis\kw_auth\Methods;
4
5
6
use kalanis\kw_accounts\AccountsException;
7
use kalanis\kw_accounts\Interfaces\IAuth;
8
use kalanis\kw_accounts\Interfaces\IUser;
9
use kalanis\kw_auth\AuthException;
10
11
12
/**.
13
 * Class AMethods
14
 * @package kalanis\kw_auth\AuthMethods
15
 * Chain of responsibility for authentication
16
 */
17
abstract class AMethods
18
{
19
    protected ?IAuth $authenticator = null;
20
    protected ?AMethods $nextOne = null;
21
    protected ?IUser $loggedUser = null;
22
23 25
    public function __construct(?IAuth $authenticator, ?AMethods $nextOne)
24
    {
25 25
        $this->authenticator = $authenticator;
26 25
        $this->nextOne = $nextOne;
27 25
    }
28
29
    /**
30
     * @param \ArrayAccess<string, string|int|float> $credentials
31
     * @throws AccountsException
32
     * @throws AuthException
33
     */
34
    abstract public function process(\ArrayAccess $credentials): void;
35
36
    abstract public function remove(): void;
37
38 20
    public function isAuthorized(): bool
39
    {
40 20
        return !empty($this->loggedUser);
41
    }
42
43 3
    public function getLoggedUser(): ?IUser
44
    {
45 3
        return $this->loggedUser;
46
    }
47
48 2
    public function getNextMethod(): ?AMethods
49
    {
50 2
        return $this->nextOne;
51
    }
52
}
53