Passed
Push — master ( 72f8f4...a05bce )
by Jesús
07:47 queued 11s
created

GacelaConfigFile::setConfigReaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 5
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 Gacela\Framework\Config\GacelaFileConfig;
6
7
final class GacelaConfigFile
8
{
9
    /** @var list<GacelaConfigItem> */
10
    private array $configItems = [];
11
12
    /** @var array<class-string,class-string|callable> */
13
    private array $mappingInterfaces = [];
14
15 27
    public static function withDefaults(): self
16
    {
17 27
        return (new self())
18 27
            ->setConfigItems([GacelaConfigItem::withDefaults()]);
19
    }
20
21
    /**
22
     * @param list<GacelaConfigItem> $configItems
23
     */
24 29
    public function setConfigItems(array $configItems): self
25
    {
26 29
        $this->configItems = $configItems;
0 ignored issues
show
Documentation Bug introduced by
It seems like $configItems of type array is incompatible with the declared type Gacela\Framework\Config\GacelaFileConfig\list of property $configItems.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
28 29
        return $this;
29
    }
30
31
    /**
32
     * @return list<GacelaConfigItem>
33
     */
34 29
    public function getConfigItems(): array
35
    {
36 29
        return $this->configItems;
1 ignored issue
show
Bug Best Practice introduced by
The expression return $this->configItems returns the type array which is incompatible with the documented return type Gacela\Framework\Config\GacelaFileConfig\list.
Loading history...
37
    }
38
39
    /**
40
     * @param array<class-string,class-string|callable> $mappingInterfaces
41
     */
42 6
    public function setMappingInterfaces(array $mappingInterfaces): self
43
    {
44 6
        $this->mappingInterfaces = $mappingInterfaces;
45
46 6
        return $this;
47
    }
48
49
    /**
50
     * Map interfaces to concrete classes or callable (which will be resolved on runtime).
51
     * This is util to inject dependencies to Gacela services (such as Factories, for example) via their constructor.
52
     *
53
     * @return mixed
54
     */
55 2
    public function getMappingInterface(string $key)
56
    {
57 2
        return $this->mappingInterfaces[$key] ?? null;
58
    }
59
}
60