Test Failed
Pull Request — master (#816)
by butschster
06:13 queued 32s
created

TelemetryConfig::geDriverConfig()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 17
rs 10
cc 4
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Telemetry\Config;
6
7
use Spiral\Core\Container\Autowire;
8
use Spiral\Core\InjectableConfig;
9
use Spiral\Telemetry\Exception\InvalidArgumentException;
10
use Spiral\Telemetry\TracerInterface;
11
12
final class TelemetryConfig extends InjectableConfig
13
{
14
    public const CONFIG = 'telemetry';
15
16
    protected array $config = [
17
        'default' => 'null',
18
        'drivers' => [],
19
    ];
20
21
    /**
22
     * Get default trace driver
23
     *
24
     * @throws InvalidArgumentException
25
     */
26
    public function getDefaultDriver(): string
27
    {
28
        if (!\is_string($this->config['default'])) {
29
            throw new InvalidArgumentException('Default trace driver config value must be a string');
30
        }
31
32
        return $this->config['default'];
33
    }
34
35
    /**
36
     * @param non-empty-string $name
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
37
     * @return class-string<TracerInterface>|Autowire
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<TracerInterface>|Autowire at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<TracerInterface>|Autowire.
Loading history...
38
     * @throws InvalidArgumentException
39
     */
40
    public function geDriverConfig(string $name): string|Autowire
41
    {
42
        if (!isset($this->config['drivers'][$name])) {
43
            throw new InvalidArgumentException(
44
                \sprintf('Config for trace `%s` is not defined.', $name)
45
            );
46
        }
47
48
        $driver = $this->config['drivers'][$name];
49
50
        if (!\is_string($driver) && $driver instanceof Autowire) {
51
            throw new InvalidArgumentException(
52
                \sprintf('Trace type value for `%s` must be a string or %s', $name, Autowire::class)
53
            );
54
        }
55
56
        return $driver;
57
    }
58
}
59