Completed
Push — master ( 4881a6...a1d3b0 )
by Nikola
01:14
created

AbstractOptions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A fromArray() 0 6 1
A toArray() 0 4 1
A validate() 0 3 1
A get() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MonologFactory\Options;
6
7
abstract class AbstractOptions
8
{
9
    /** @var array */
10
    protected $options;
11
    
12 29
    protected function __construct(array $options)
13
    {
14 29
        $this->options = $options;
15 29
    }
16
    
17 33
    public static function fromArray(array $options)
18
    {
19 33
        static::validate($options);
20
21 29
        return new static($options);
22
    }
23
24 22
    public function toArray(): array
25
    {
26 22
        return $this->options;
27
    }
28
29 13
    protected static function validate(array $options): void
30
    {
31 13
    }
32
33 23
    final protected function get(string $key, $default = null)
34
    {
35 23
        return array_key_exists($key, $this->options)
36 17
            ? $this->options[$key]
37 23
            : $default;
38
    }
39
}
40