Completed
Push — master ( 2dfb51...5c8a1a )
by Nikola
03:59
created

HandlerOptions::validate()   C

Complexity

Conditions 9
Paths 11

Size

Total Lines 24
Code Lines 12

Duplication

Lines 13
Ratio 54.17 %

Code Coverage

Tests 12
CRAP Score 9.0368

Importance

Changes 0
Metric Value
dl 13
loc 24
ccs 12
cts 13
cp 0.9231
rs 5.3563
c 0
b 0
f 0
cc 9
eloc 12
nc 11
nop 1
crap 9.0368
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MonologFactory\Options;
6
7
use Monolog\Formatter\FormatterInterface;
8
use MonologFactory\Exception\InvalidOptionsException;
9
10
final class HandlerOptions extends AbstractOptions
11
{
12 15
    public function getFormatter()
13
    {
14 15
        return $this->get('formatter', false);
15
    }
16
17 15
    public function getProcessors() : array
18
    {
19 15
        return $this->get('processors', []);
20
    }
21
    
22 16
    protected static function validate(array $options)
23
    {
24 16
        if (array_key_exists('formatter', $options)) {
25 8
            $formatter = $options['formatter'];
26
            
27 8
            if (! ($formatter instanceof FormatterInterface || is_array($formatter))) {
28 1
                throw InvalidOptionsException::forInvalidFormatter($formatter);
29
            }
30
        }
31
32 15 View Code Duplication
        if (array_key_exists('processors', $options)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33 1
            $processors = $options['processors'];
34
35 1
            if (! is_array($processors)) {
36
                throw InvalidOptionsException::forInvalidProcessors($options['processors']);
37
            }
38
39 1
            foreach ($processors as $processor) {
40 1
                if (! (is_callable($processor) || is_array($processor))) {
41 1
                    throw InvalidOptionsException::forInvalidProcessor($processor);
42
                }
43
            }
44
        }
45 15
    }
46
}
47