Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Auth | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
authenticate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
logout | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * Jingga |
4 | * |
5 | * PHP Version 8.1 |
6 | * |
7 | * @package phpOMS\Auth |
8 | * @copyright Dennis Eichhorn |
9 | * @license OMS License 2.0 |
10 | * @version 1.0.0 |
11 | * @link https://jingga.app |
12 | */ |
13 | declare(strict_types=1); |
14 | |
15 | namespace phpOMS\Auth; |
16 | |
17 | use phpOMS\DataStorage\Session\SessionInterface; |
18 | |
19 | /** |
20 | * Auth class. |
21 | * |
22 | * Responsible for authenticating and initializing the connection |
23 | * |
24 | * @package phpOMS\Auth |
25 | * @license OMS License 2.0 |
26 | * @link https://jingga.app |
27 | * @since 1.0.0 |
28 | */ |
29 | final class Auth |
30 | { |
31 | /** |
32 | * Constructor. |
33 | * |
34 | * @since 1.0.0 |
35 | * @codeCoverageIgnore |
36 | */ |
37 | private function __construct() |
38 | { |
39 | } |
40 | |
41 | /** |
42 | * Authenticates user. |
43 | * |
44 | * @param SessionInterface $session Session |
45 | * |
46 | * @return int Returns the user id |
47 | * |
48 | * @since 1.0.0 |
49 | */ |
50 | public static function authenticate(SessionInterface $session) : int |
51 | { |
52 | $uid = $session->get('UID'); |
53 | |
54 | return (int) (empty($uid) ? 0 : $uid); |
55 | } |
56 | |
57 | /** |
58 | * Logout the given user. |
59 | * |
60 | * @param SessionInterface $session Session |
61 | * |
62 | * @return void |
63 | * |
64 | * @since 1.0.0 |
65 | */ |
66 | public static function logout(SessionInterface $session) : void |
67 | { |
68 | $session->remove('UID'); |
69 | } |
70 | } |