Passed
Push — feature/gacela-config-callable ( f0c396...2ecc53 )
by Chema
04:10
created

GacelaConfig::getConfigBuilder()   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 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Bootstrap;
6
7
use Gacela\Framework\Config\ConfigReaderInterface;
8
use Gacela\Framework\Config\GacelaConfigBuilder\ConfigBuilder;
9
use Gacela\Framework\Config\GacelaConfigBuilder\MappingInterfacesBuilder;
10
use Gacela\Framework\Config\GacelaConfigBuilder\SuffixTypesBuilder;
11
12
final class GacelaConfig
13
{
14
    private ConfigBuilder $configBuilder;
15
16
    private SuffixTypesBuilder $suffixTypesBuilder;
17
18
    private MappingInterfacesBuilder $mappingInterfacesBuilder;
19
20
    /** @var array<string,mixed> */
21
    private array $externalServices;
22
23
    /**
24
     * @param array<string,mixed> $externalServices
25
     */
26 14
    public function __construct(array $externalServices = [])
27
    {
28 14
        $this->externalServices = $externalServices;
29 14
        $this->configBuilder = new ConfigBuilder();
30 14
        $this->suffixTypesBuilder = new SuffixTypesBuilder();
31 14
        $this->mappingInterfacesBuilder = new MappingInterfacesBuilder();
32
    }
33
34 14
    public function getConfigBuilder(): ConfigBuilder
35
    {
36 14
        return $this->configBuilder;
37
    }
38
39 14
    public function getSuffixTypesBuilder(): SuffixTypesBuilder
40
    {
41 14
        return $this->suffixTypesBuilder;
42
    }
43
44 14
    public function getMappingInterfacesBuilder(): MappingInterfacesBuilder
45
    {
46 14
        return $this->mappingInterfacesBuilder;
47
    }
48
49
    /**
50
     * @param string $path define the path where Gacela will read all the config files
51
     * @param string $pathLocal define the path where Gacela will read the local config file
52
     * @param class-string<ConfigReaderInterface>|ConfigReaderInterface|null $reader Define the reader class which will read and parse the config files
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<ConfigReade...figReaderInterface|null at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<ConfigReaderInterface>|ConfigReaderInterface|null.
Loading history...
53
     */
54 5
    public function addAppConfig(string $path, string $pathLocal = '', $reader = null): self
55
    {
56 5
        $this->configBuilder->add($path, $pathLocal, $reader);
57
58 5
        return $this;
59
    }
60
61 3
    public function addSuffixTypeFacade(string $suffix): self
62
    {
63 3
        $this->suffixTypesBuilder->addFacade($suffix);
64
65 3
        return $this;
66
    }
67
68 3
    public function addSuffixTypeFactory(string $suffix): self
69
    {
70 3
        $this->suffixTypesBuilder->addFactory($suffix);
71
72 3
        return $this;
73
    }
74
75 3
    public function addSuffixTypeConfig(string $suffix): self
76
    {
77 3
        $this->suffixTypesBuilder->addConfig($suffix);
78
79 3
        return $this;
80
    }
81
82 4
    public function addSuffixTypeDependencyProvider(string $suffix): self
83
    {
84 4
        $this->suffixTypesBuilder->addDependencyProvider($suffix);
85
86 4
        return $this;
87
    }
88
89
    /**
90
     * @param class-string $key
1 ignored issue
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
91
     * @param class-string|object|callable $value
92
     */
93 10
    public function mapInterface(string $key, $value): self
94
    {
95 10
        $this->mappingInterfacesBuilder->bind($key, $value);
96
97 10
        return $this;
98
    }
99
100
    /**
101
     * @return array<string,mixed>
102
     */
103 14
    public function getExternalServices(): array
104
    {
105 14
        return $this->externalServices;
106
    }
107
108
    /**
109
     * @return mixed
110
     */
111 5
    public function getExternalService(string $key)
112
    {
113 5
        return $this->externalServices[$key];
114
    }
115
116
    /**
117
     * @param mixed $value
118
     */
119 2
    public function addExternalService(string $key, $value): self
120
    {
121 2
        $this->externalServices[$key] = $value;
122
123 2
        return $this;
124
    }
125
}
126