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

AuthConfig   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultTransport() 0 3 1
A getTransports() 0 3 1
A getDefaultStorage() 0 3 1
A getStorage() 0 9 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