AbstractServiceConfig::validateConfig()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 8
cts 8
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WShafer\PSR11MonoLog\Config;
6
7
use WShafer\PSR11MonoLog\ConfigInterface;
8
use WShafer\PSR11MonoLog\Exception\MissingConfigException;
9
10 View Code Duplication
abstract class AbstractServiceConfig implements ConfigInterface
11
{
12
    protected $config = [];
13
14 21
    public function __construct(array $config)
15
    {
16 21
        $this->validateConfig($config);
17 21
        $this->config = $config;
18 21
    }
19
20 21
    protected function validateConfig($config)
21
    {
22 21
        if (empty($config)) {
23 3
            throw new MissingConfigException(
24 3
                'No config found'
25
            );
26
        }
27
28 21
        if (empty($config['type'])) {
29 3
            throw new MissingConfigException(
30 3
                'No config key of "type" found in adaptor config array.'
31
            );
32
        }
33 21
    }
34
35 3
    public function getType(): string
36
    {
37 3
        return $this->config['type'];
38
    }
39
40 6
    public function getOptions()
41
    {
42 6
        return $this->config['options'] ?? [];
43
    }
44
}
45