Completed
Push — master ( 6d1d70...5b3b49 )
by Westin
02:51
created

ChannelChangerFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 7
dl 0
loc 82
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 12 1
A getMainConfig() 0 9 2
A getHandlerManager() 0 16 2
A getFormatterManager() 0 15 2
A getProcessorManager() 0 15 2
1
<?php
2
3
namespace WShafer\PSR11MonoLog\Service;
4
5
use Psr\Container\ContainerInterface;
6
use WShafer\PSR11MonoLog\Config\MainConfigFactory;
7
use WShafer\PSR11MonoLog\Formatter\FormatterMapper;
8
use WShafer\PSR11MonoLog\Processor\ProcessorMapper;
9
10
class ChannelChangerFactory
11
{
12
    protected $config = null;
13
14
    protected $handlerManager = null;
15
16
    protected $processManager = null;
17
18
    protected $formatterManager = null;
19
20
    public function __invoke(ContainerInterface $container)
21
    {
22
        $config = $this->getMainConfig($container);
23
        $handlerManager = $this->getHandlerManager($container);
24
        $processorManager = $this->getProcessorManager($container);
25
26
        return new ChannelChanger(
27
            $config,
28
            $handlerManager,
29
            $processorManager
30
        );
31
    }
32
33
    public function getMainConfig(ContainerInterface $container)
34
    {
35
        if (!$this->config) {
36
            $factory = new MainConfigFactory();
37
            $this->config = $factory($container);
38
        }
39
40
        return $this->config;
41
    }
42
43
    public function getHandlerManager(ContainerInterface $container)
44
    {
45
        if ($this->handlerManager) {
46
            return $this->handlerManager;
47
        }
48
49
        $config = $this->getMainConfig($container);
50
        $this->handlerManager = new HandlerManager(
51
            $config,
52
            new FormatterMapper(),
53
            $container
54
        );
55
56
        $this->handlerManager->setFormatterManager($this->getFormatterManager($container));
57
        return $this->handlerManager;
58
    }
59
60
    public function getFormatterManager(ContainerInterface $container)
61
    {
62
        if (!$this->formatterManager) {
63
            return $this->formatterManager;
64
        }
65
66
        $config = $this->getMainConfig($container);
67
        $this->formatterManager = new FormatterManager(
68
            $config,
69
            new FormatterMapper(),
70
            $container
71
        );
72
73
        return $this->formatterManager;
74
    }
75
76
    public function getProcessorManager(ContainerInterface $container)
77
    {
78
        if (!$this->processManager) {
79
            return $this->processManager;
80
        }
81
82
        $config = $this->getMainConfig($container);
83
        $this->processManager = new ProcessorManager(
84
            $config,
85
            new ProcessorMapper(),
86
            $container
87
        );
88
89
        return $this->processManager;
90
    }
91
}
92