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

HandlerOptions::getProcessors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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