Passed
Push — codex/improve-performance ( d67640...dc9870 )
by Chema
09:24 queued 04:08
created

PropertyMerger::mergeConfigKeyValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Bootstrap\Setup;
6
7
use Gacela\Framework\Bootstrap\SetupGacela;
8
9
use function array_merge;
10
use function array_unique;
11
12
/**
13
 * Merges individual properties into a SetupGacela instance.
14
 */
15
final class PropertyMerger
16
{
17
    public function __construct(
18
        private readonly SetupGacela $setup,
19
    ) {
20
    }
21
22
    /**
23
     * @param array<string,class-string|object|callable> $list
24
     */
25
    public function mergeExternalServices(array $list): void
26
    {
27
        $current = $this->setup->externalServices();
28
        $this->setup->setExternalServices(array_merge($current, $list));
29
    }
30
31
    /**
32
     * @param list<string> $list
33
     */
34
    public function mergeProjectNamespaces(array $list): void
35
    {
36
        $current = $this->setup->getProjectNamespaces();
37
        $this->setup->setProjectNamespaces(array_merge($current, $list));
38
    }
39
40
    /**
41
     * @param array<string,mixed> $list
42
     */
43
    public function mergeConfigKeyValues(array $list): void
44
    {
45
        $current = $this->setup->getConfigKeyValues();
46
        $this->setup->setConfigKeyValues(array_merge($current, $list));
47
    }
48
49
    /**
50
     * @param list<class-string> $list
51
     */
52
    public function mergeGacelaConfigsToExtend(array $list): void
53
    {
54
        $current = $this->setup->getGacelaConfigsToExtend();
55
        /** @var list<class-string> $merged */
56
        $merged = array_values(array_unique(array_merge($current, $list)));
57
        $this->setup->setGacelaConfigsToExtend($merged);
0 ignored issues
show
Bug introduced by
$merged of type Gacela\Framework\Bootstrap\Setup\list is incompatible with the type array|null expected by parameter $list of Gacela\Framework\Bootstr...GacelaConfigsToExtend(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        $this->setup->setGacelaConfigsToExtend(/** @scrutinizer ignore-type */ $merged);
Loading history...
58
    }
59
60
    /**
61
     * @param list<class-string|callable> $list
62
     */
63
    public function mergePlugins(array $list): void
64
    {
65
        $current = $this->setup->getPlugins();
66
        $this->setup->setPlugins(array_merge($current, $list));
67
    }
68
}
69