Passed
Push — refactor/setup-gacela-2 ( 32146e...7c89ce )
by Chema
04:06
created

PropertyMerger   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A mergeConfigKeyValues() 0 4 1
A __construct() 0 3 1
A mergeProjectNamespaces() 0 4 1
A mergeExternalServices() 0 4 1
A mergeGacelaConfigsToExtend() 0 8 1
A mergePlugins() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Bootstrap\Setup;
6
7
use Gacela\Framework\Bootstrap\SetupGacela;
8
use ReflectionMethod;
9
10
use function array_merge;
11
use function array_unique;
12
13
/**
14
 * Merges individual properties into a SetupGacela instance.
15
 */
16
final class PropertyMerger
17
{
18
    public function __construct(
19
        private readonly SetupGacela $setup,
20
    ) {
21
    }
22
23
    /**
24
     * @param array<string,class-string|object|callable> $list
25
     */
26
    public function mergeExternalServices(array $list): void
27
    {
28
        $current = $this->setup->externalServices();
29
        $this->setup->setExternalServices(array_merge($current, $list));
30
    }
31
32
    /**
33
     * @param list<string> $list
34
     */
35
    public function mergeProjectNamespaces(array $list): void
36
    {
37
        $current = $this->setup->getProjectNamespaces();
38
        $this->setup->setProjectNamespaces(array_merge($current, $list));
39
    }
40
41
    /**
42
     * @param array<string,mixed> $list
43
     */
44
    public function mergeConfigKeyValues(array $list): void
45
    {
46
        $current = $this->setup->getConfigKeyValues();
47
        $this->setup->setConfigKeyValues(array_merge($current, $list));
48
    }
49
50
    /**
51
     * @param list<class-string> $list
52
     */
53
    public function mergeGacelaConfigsToExtend(array $list): void
54
    {
55
        $current = $this->setup->getGacelaConfigsToExtend();
56
57
        // Use reflection to call private method setGacelaConfigsToExtend
58
        $method = new ReflectionMethod($this->setup, 'setGacelaConfigsToExtend');
59
        $method->setAccessible(true);
60
        $method->invoke($this->setup, array_unique(array_merge($current, $list)));
61
    }
62
63
    /**
64
     * @param list<class-string|callable> $list
65
     */
66
    public function mergePlugins(array $list): void
67
    {
68
        $current = $this->setup->getPlugins();
69
70
        // Use reflection to call private method setPlugins
71
        $method = new ReflectionMethod($this->setup, 'setPlugins');
72
        $method->setAccessible(true);
73
        $method->invoke($this->setup, array_merge($current, $list));
74
    }
75
}
76