Passed
Pull Request — master (#74)
by Rustam
02:35
created

ContainerProxyConfig::getCollector()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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