Passed
Pull Request — master (#931)
by butschster
12:18
created

TokenStorageScope   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 4
c 1
b 0
f 0
dl 0
loc 35
ccs 8
cts 8
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 3 1
A load() 0 3 1
A delete() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Auth;
6
7
use Spiral\Auth\Exception\TokenStorageException;
8
use Spiral\Core\Container\SingletonInterface;
9
10
final class TokenStorageScope implements TokenStorageInterface, SingletonInterface
11
{
12 68
    public function __construct(
13
        private readonly TokenStorageInterface $tokenStorage
14
    ) {
15 68
    }
16
17
    /**
18
     * Load token by id, must return null if token not found.
19
     *
20
     * @throws TokenStorageException
21
     */
22 1
    public function load(string $id): ?TokenInterface
23
    {
24 1
        return $this->tokenStorage->load($id);
25
    }
26
27
    /**
28
     * Create token based on the payload provided by actor provider.
29
     *
30
     * @throws TokenStorageException
31
     */
32 1
    public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface
33
    {
34 1
        return $this->tokenStorage->create($payload, $expiresAt);
35
    }
36
37
    /**
38
     * Delete token from the persistent storage.
39
     *
40
     * @throws TokenStorageException
41
     */
42 1
    public function delete(TokenInterface $token): void
43
    {
44 1
        $this->tokenStorage->delete($token);
45
    }
46
}
47