Test Failed
Pull Request — master (#133)
by Rustam
03:14
created

ContainerProxyConfig   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 24
eloc 43
dl 0
loc 141
rs 10
c 0
b 0
f 0

20 Methods

Rating   Name   Duplication   Size   Complexity  
A getDecoratedServiceConfig() 0 3 1
A hasCollector() 0 3 1
A hasDecoratedServiceCallableConfig() 0 3 2
A withDispatcher() 0 6 1
A __construct() 0 14 1
A hasDispatcher() 0 3 1
A withProxyCachePath() 0 6 1
A getDispatcher() 0 3 1
A getCollector() 0 3 1
A withDecoratedServices() 0 6 1
A getIsActive() 0 3 1
A getDecoratedServices() 0 3 1
A withLogLevel() 0 6 1
A hasDecoratedServiceArrayConfigWithStringKeys() 0 3 2
A getProxyCachePath() 0 3 1
A hasDecoratedService() 0 3 2
A getLogLevel() 0 3 1
A withCollector() 0 6 1
A hasDecoratedServiceArrayConfig() 0 3 2
A activate() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\Collector;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
9
use function in_array;
10
use function is_callable;
11
12
final class ContainerProxyConfig
13
{
14
    private int $logLevel;
15
16
    private array $decoratedServices;
17
18
    private bool $active;
19
20
    private ?EventDispatcherInterface $dispatcher;
21
22
    private ?ServiceCollector $collector;
23
24
    private ?string $proxyCachePath;
25
26
    public function __construct(
27
        bool $active = false,
28
        array $decoratedServices = [],
29
        EventDispatcherInterface $dispatcher = null,
30
        ServiceCollector $collector = null,
31
        string $proxyCachePath = null,
32
        int $logLevel = 0
33
    ) {
34
        $this->active = $active;
35
        $this->decoratedServices = $decoratedServices;
36
        $this->dispatcher = $dispatcher;
37
        $this->collector = $collector;
38
        $this->proxyCachePath = $proxyCachePath;
39
        $this->logLevel = $logLevel;
40
    }
41
42
    public function activate(): self
43
    {
44
        $config = clone $this;
45
        $config->active = true;
46
47
        return $config;
48
    }
49
50
    public function withDispatcher(EventDispatcherInterface $dispatcher): self
51
    {
52
        $config = clone $this;
53
        $config->dispatcher = $dispatcher;
54
55
        return $config;
56
    }
57
58
    public function withLogLevel(int $logLevel): self
59
    {
60
        $config = clone $this;
61
        $config->logLevel = $logLevel;
62
63
        return $config;
64
    }
65
66
    public function withProxyCachePath(string $proxyCachePath): self
67
    {
68
        $config = clone $this;
69
        $config->proxyCachePath = $proxyCachePath;
70
71
        return $config;
72
    }
73
74
    public function withCollector(ServiceCollector $collector): self
75
    {
76
        $config = clone $this;
77
        $config->collector = $collector;
78
79
        return $config;
80
    }
81
82
    public function withDecoratedServices(array $decoratedServices): self
83
    {
84
        $config = clone $this;
85
        $config->decoratedServices = array_merge($this->decoratedServices, $decoratedServices);
86
87
        return $config;
88
    }
89
90
    public function getIsActive(): bool
91
    {
92
        return $this->active;
93
    }
94
95
    public function getLogLevel(): int
96
    {
97
        return $this->logLevel;
98
    }
99
100
    public function getDecoratedServices(): array
101
    {
102
        return $this->decoratedServices;
103
    }
104
105
    public function getDispatcher(): ?EventDispatcherInterface
106
    {
107
        return $this->dispatcher;
108
    }
109
110
    public function getCollector(): ?ServiceCollector
111
    {
112
        return $this->collector;
113
    }
114
115
    public function getProxyCachePath(): ?string
116
    {
117
        return $this->proxyCachePath;
118
    }
119
120
    public function getDecoratedServiceConfig($service)
121
    {
122
        return $this->decoratedServices[$service];
123
    }
124
125
    public function hasDecoratedService(string $service): bool
126
    {
127
        return isset($this->decoratedServices[$service]) || in_array($service, $this->decoratedServices, true);
128
    }
129
130
    public function hasDecoratedServiceArrayConfigWithStringKeys(string $service): bool
131
    {
132
        return $this->hasDecoratedServiceArrayConfig($service) && !isset($this->decoratedServices[$service][0]);
133
    }
134
135
    public function hasDecoratedServiceArrayConfig(string $service): bool
136
    {
137
        return isset($this->decoratedServices[$service]) && is_array($this->decoratedServices[$service]);
138
    }
139
140
    public function hasDecoratedServiceCallableConfig(string $service): bool
141
    {
142
        return isset($this->decoratedServices[$service]) && is_callable($this->decoratedServices[$service]);
143
    }
144
145
    public function hasDispatcher(): bool
146
    {
147
        return $this->dispatcher !== null;
148
    }
149
150
    public function hasCollector(): bool
151
    {
152
        return $this->collector !== null;
153
    }
154
}
155