ContainerProxyConfig::withCollector()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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