Passed
Pull Request — master (#19)
by
unknown
04:36 queued 02:12
created

YiiSentryConfig::getLogLevel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Sentry;
6
7
use InvalidArgumentException;
8
9
final class YiiSentryConfig
10
{
11 2
    public function __construct(protected array $config)
12
    {
13
    }
14
15
    /**
16
     * Check if a DSN was set in the config.
17
     *
18
     * @return bool
19
     */
20
    public function hasDsnSet(): bool
21
    {
22
        $config = $this->getUserConfig();
23
24
        return !empty($config['options']['dsn']);
25
    }
26
27
    /**
28
     * Retrieve the user configuration.
29
     *
30
     * @return array
31
     */
32 2
    public function getUserConfig(): array
33
    {
34 2
        $config = $this->config;
35
36 2
        return empty($config) ? [] : $config;
37
    }
38
39
    public function getOptions(): array
40
    {
41
        return empty($this->config['options'])
42
            ? []
43
            : (is_array($this->config['options'])
44
                ? $this->config['options']
45
                : throw  new InvalidArgumentException('options must be an array'));
46
    }
47
48 2
    public function getTracing(): array
49
    {
50 2
        return empty($this->config['tracing'])
51 2
            ? []
52
            : (is_array($this->config['tracing'])
53
                ? $this->config['tracing']
54 2
                : throw  new InvalidArgumentException('tracing must be an array'));
55
    }
56
57
    public function getLogLevel(): ?string
58
    {
59
        return isset($this->config['log_level']) ? (string)$this->config['log_level'] : null;
60
    }
61
62
    /**
63
     * @return array
64
     */
65 2
    public function getIntegrations(): array
66
    {
67 2
        return empty($this->config['integrations'])
68 2
            ? []
69
            : (is_array($this->config['integrations'])
70
                ? $this->config['integrations']
71 2
                : throw  new InvalidArgumentException('integrations must be an array'));
72
    }
73
74
    /**
75
     * Checks if the config is set in such a way that performance tracing could be enabled.
76
     *
77
     * Because of `traces_sampler` being dynamic we can never be 100% confident but that is also not important.
78
     *
79
     * @return bool
80
     */
81 2
    public function couldHavePerformanceTracingEnabled(): bool
82
    {
83 2
        $config = $this->getUserConfig();
84
85 2
        return !empty($config['options']['traces_sample_rate'])
86 2
            || !empty($config['options']['traces_sampler']);
87
    }
88
}
89