Passed
Push — feature/gacela-config-callable ( 8c5325...d8cdb8 )
by Chema
08:46
created

GacelaConfig::getExternalServices()   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
    /**
35
     * @param string $path define the path where Gacela will read all the config files
36
     * @param string $pathLocal define the path where Gacela will read the local config file
37
     * @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...
38
     */
39 5
    public function addAppConfig(string $path, string $pathLocal = '', $reader = null): self
40
    {
41 5
        $this->configBuilder->add($path, $pathLocal, $reader);
42
43 5
        return $this;
44
    }
45
46 2
    public function addSuffixTypeFacade(string $suffix): self
47
    {
48 2
        $this->suffixTypesBuilder->addFacade($suffix);
49
50 2
        return $this;
51
    }
52
53 2
    public function addSuffixTypeFactory(string $suffix): self
54
    {
55 2
        $this->suffixTypesBuilder->addFactory($suffix);
56
57 2
        return $this;
58
    }
59
60 2
    public function addSuffixTypeConfig(string $suffix): self
61
    {
62 2
        $this->suffixTypesBuilder->addConfig($suffix);
63
64 2
        return $this;
65
    }
66
67 3
    public function addSuffixTypeDependencyProvider(string $suffix): self
68
    {
69 3
        $this->suffixTypesBuilder->addDependencyProvider($suffix);
70
71 3
        return $this;
72
    }
73
74
    /**
75
     * @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...
76
     * @param class-string|object|callable $value
77
     */
78 9
    public function addMappingInterface(string $key, $value): self
79
    {
80 9
        $this->mappingInterfacesBuilder->bind($key, $value);
81
82 9
        return $this;
83
    }
84
85
    /**
86
     * @return mixed
87
     */
88 4
    public function getExternalService(string $key)
89
    {
90 4
        return $this->externalServices[$key];
91
    }
92
93
    /**
94
     * @param mixed $value
95
     */
96 2
    public function addExternalService(string $key, $value): self
97
    {
98 2
        $this->externalServices[$key] = $value;
99
100 2
        return $this;
101
    }
102
103
    /**
104
     * @internal
105
     *
106
     * @return array{
107
     *     external-services:array<string,mixed>,
108
     *     config-builder:ConfigBuilder,
109
     *     suffix-types-builder:SuffixTypesBuilder,
110
     *     mapping-interfaces-builder:MappingInterfacesBuilder,
111
     * }
112
     */
113 14
    public function build(): array
114
    {
115
        return [
116 14
            'external-services' => $this->externalServices,
117 14
            'config-builder' => $this->configBuilder,
118 14
            'suffix-types-builder' => $this->suffixTypesBuilder,
119 14
            'mapping-interfaces-builder' => $this->mappingInterfacesBuilder,
120
        ];
121
    }
122
}
123