Passed
Push — master ( 3b8ce4...b46cbf )
by Alexander
03:01
created

ContainerConfig::getDefinitions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Di;
6
7
/**
8
 * Container configuration.
9
 */
10
final class ContainerConfig implements ContainerConfigInterface
11
{
12
    private array $definitions = [];
13
    private array $providers = [];
14
    private array $tags = [];
15
    private bool $validate = true;
16
    private array $delegates = [];
17
18 96
    private function __construct()
19
    {
20 96
    }
21
22 96
    public static function create(): self
23
    {
24 96
        return new self();
25
    }
26
27
    /**
28
     * @param array $definitions Definitions to put into container.
29
     *
30
     * @return self
31
     */
32 89
    public function withDefinitions(array $definitions): self
33
    {
34 89
        $new = clone $this;
35 89
        $new->definitions = $definitions;
36 89
        return $new;
37
    }
38
39 96
    public function getDefinitions(): array
40
    {
41 96
        return $this->definitions;
42
    }
43
44
    /**
45
     * @param array $providers Service providers to get definitions from.
46
     *
47
     * @return self
48
     */
49 6
    public function withProviders(array $providers): self
50
    {
51 6
        $new = clone $this;
52 6
        $new->providers = $providers;
53 6
        return $new;
54
    }
55
56 90
    public function getProviders(): array
57
    {
58 90
        return $this->providers;
59
    }
60
61
    /**
62
     * @param array $tags Tagged service IDs. The structure is `['tagID' => ['service1', 'service2']]`.
63
     *
64
     * @return self
65
     */
66 2
    public function withTags(array $tags): self
67
    {
68 2
        $new = clone $this;
69 2
        $new->tags = $tags;
70 2
        return $new;
71
    }
72
73 96
    public function getTags(): array
74
    {
75 96
        return $this->tags;
76
    }
77
78
    /**
79
     * @param bool $validate Whether definitions should be validated immediately.
80
     *
81
     * @return self
82
     */
83 1
    public function withValidate(bool $validate): self
84
    {
85 1
        $new = clone $this;
86 1
        $new->validate = $validate;
87 1
        return $new;
88
    }
89
90 96
    public function shouldValidate(): bool
91
    {
92 96
        return $this->validate;
93
    }
94
95
    /**
96
     * @param array $delegates Container delegates. Each delegate is a callable in format
97
     * `function (ContainerInterface $container): ContainerInterface`. The container instance returned is used
98
     * in case a service can not be found in primary container.
99
     *
100
     * @return self
101
     */
102 1
    public function withDelegates(array $delegates): self
103
    {
104 1
        $new = clone $this;
105 1
        $new->delegates = $delegates;
106 1
        return $new;
107
    }
108
109 89
    public function getDelegates(): array
110
    {
111 89
        return $this->delegates;
112
    }
113
}
114