Total Complexity | 7 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | class Authentication |
||
14 | { |
||
15 | const NOT_FOUND = 0; |
||
16 | |||
17 | const INVALID = 1; |
||
18 | |||
19 | /** |
||
20 | * Authenticates the given credentials. |
||
21 | * |
||
22 | * @param \Rougin\Authsum\Checker\CheckerInterface $checker |
||
23 | * @param array $credentials |
||
24 | * @return mixed |
||
25 | */ |
||
26 | 49 | public function authenticate(CheckerInterface $checker, array $credentials) |
|
27 | { |
||
28 | 49 | if ($this->validate($credentials) === true) { |
|
29 | 38 | $matched = ($match = $checker->check($credentials)) !== false; |
|
30 | |||
31 | 38 | return ($matched) ? $this->success($match) : $this->error(); |
|
32 | } |
||
33 | |||
34 | 11 | return $this->error(self::INVALID); |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * Checks if the authentication has an occured error. |
||
39 | * |
||
40 | * @param integer $type |
||
41 | * @return mixed |
||
42 | */ |
||
43 | 24 | protected function error($type = self::NOT_FOUND) |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * Checks if the authentication is successful. |
||
50 | * |
||
51 | * @param mixed $match |
||
52 | * @return mixed |
||
53 | */ |
||
54 | 25 | protected function success($match) |
|
55 | { |
||
56 | 25 | return $match; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Validates the given credentials. |
||
61 | * |
||
62 | * @param array $credentials |
||
63 | * @return boolean |
||
64 | */ |
||
65 | 27 | protected function validate(array $credentials) |
|
70 | } |
||
71 | } |
||
72 |