ProcessorFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 49
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A make() 0 6 1
A validateProcessorClass() 0 6 2
1
<?php
2
3
namespace leinonen\Yii2Monolog\Factories;
4
5
class ProcessorFactory
6
{
7
    /**
8
     * @var GenericStrategyBasedFactory
9
     */
10
    private $genericFactory;
11
12
    /**
13
     * Initializes a new ProcessorFactory.
14
     *
15
     * @param GenericStrategyBasedFactory $genericFactory
16
     */
17 11
    public function __construct(GenericStrategyBasedFactory $genericFactory)
18
    {
19 11
        $this->genericFactory = $genericFactory;
20 11
    }
21
22
    /**
23
     * Makes a new Processor from the given processor class and config.
24
     *
25
     * @param string $processorClass
26
     * @param array $config
27
     *
28
     * @return callable
29
     *
30
     * @throws \InvalidArgumentException
31
     * @throws \yii\base\InvalidConfigException
32
     */
33 8
    public function make(string $processorClass, array $config = []): callable
34
    {
35 8
        $this->validateProcessorClass($processorClass);
36
37 7
        return $this->genericFactory->makeWithStrategy($processorClass, $config);
38
    }
39
40
    /**
41
     * Validates the given processor class.
42
     *
43
     * @param $processorClass
44
     *
45
     * @throws \InvalidArgumentException
46
     */
47 8
    private function validateProcessorClass(string $processorClass)
48
    {
49 8
        if (! (new \ReflectionClass($processorClass))->hasMethod('__invoke')) {
50 1
            throw new \InvalidArgumentException("{$processorClass} isn't callable. All processor classes must implement the __invoke method.");
51
        }
52 7
    }
53
}
54