Passed
Push — master ( a6d59a...971523 )
by butschster
16:28 queued 13s
created

AuthConfig::getStorage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Auth\Config;
6
7
use Spiral\Auth\TokenStorageInterface;
8
use Spiral\Auth\Exception\InvalidArgumentException;
9
use Spiral\Core\Container\Autowire;
10
use Spiral\Core\InjectableConfig;
11
12
/**
13
 * Manages auth http transport configuration.
14
 */
15
final class AuthConfig extends InjectableConfig
16
{
17
    // Configuration source.
18
    public const CONFIG = 'auth';
19
20
    protected array $config = [
21
        'defaultTransport' => 'cookie',
22
        'defaultStorage' => 'session',
23
        'storages' => [],
24
        'transports' => [],
25
    ];
26
27 266
    public function getDefaultTransport(): string
28
    {
29 266
        return $this->config['defaultTransport'];
30
    }
31
32
    /**
33
     * @return Autowire[]
34
     */
35 266
    public function getTransports(): array
36
    {
37 266
        return \array_map([Autowire::class, 'wire'], $this->config['transports']);
38
    }
39
40
    /**
41
     * @return TokenStorageInterface|class-string<TokenStorageInterface>|Autowire
0 ignored issues
show
Documentation Bug introduced by
The doc comment TokenStorageInterface|cl...rageInterface>|Autowire at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in TokenStorageInterface|class-string<TokenStorageInterface>|Autowire.
Loading history...
42
     * @throws InvalidArgumentException
43
     */
44 274
    public function getStorage(string $name): TokenStorageInterface|string|Autowire
45
    {
46 274
        if (!isset($this->config['storages'][$name])) {
47 2
            throw new InvalidArgumentException(
48 2
                \sprintf('Token storage `%s` is not defined.', $name)
49
            );
50
        }
51
52 272
        return $this->config['storages'][$name];
53
    }
54
55 268
    public function getDefaultStorage(): string
56
    {
57 268
        return $this->config['defaultStorage'];
58
    }
59
}
60