Passed
Push — suggestion ( e78e97 )
by Sergei
03:35
created

ContainerConfig::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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