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

TokenStorageScope::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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