SessionAuthBackend   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 3 1
1
<?php
2
3
namespace Koded\Framework\Auth;
4
5
use function Koded\Session\session;
6
use function password_hash;
7
8
/**
9
 * A basic authentication storage that uses the
10
 * PHP session for the user object.
11
 *
12
 * The format of the credentials session key is:
13
 *
14
 *  `<type>.<password_hash(credentials)>`
15
 *
16
 * Example: Bearer.a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
17
 * Example: Token.$2y$10$FRmWYon7sMY4lZKW2D3NZueT3iUAsQj.MjfOSbukrBpLI9Qce11JO
18
 */
19
class SessionAuthBackend implements AuthBackend
20
{
21
    public function __invoke(string $type, string $credentials): ?object
22
    {
23
        return session()->get($type . '.' . password_hash($credentials, PASSWORD_DEFAULT));
24
    }
25
}
26