Passed
Push — refactor/setup-gacela-2 ( 32146e )
by Chema
05:11
created

BuilderExecutor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A buildSuffixTypes() 0 6 1
A buildBindings() 0 12 1
A buildAppConfig() 0 6 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\Bootstrap\Setup;
6
7
use Gacela\Framework\Config\GacelaConfigBuilder\AppConfigBuilder;
8
use Gacela\Framework\Config\GacelaConfigBuilder\BindingsBuilder;
9
use Gacela\Framework\Config\GacelaConfigBuilder\SuffixTypesBuilder;
10
11
/**
12
 * Handles execution of builder methods for SetupGacela.
13
 */
14
final class BuilderExecutor
15
{
16
    public function __construct(
17
        private readonly Properties $properties,
18
    ) {
19
    }
20
21
    public function buildAppConfig(AppConfigBuilder $parentBuilder): AppConfigBuilder
22
    {
23
        $builder = $this->properties->appConfigBuilder ?? $parentBuilder;
24
        ($this->properties->appConfigFn)($builder);
25
26
        return $builder;
27
    }
28
29
    /**
30
     * @param array<string,class-string|object|callable> $externalServices
31
     */
32
    public function buildBindings(
33
        BindingsBuilder $parentBuilder,
34
        array $externalServices,
35
    ): BindingsBuilder {
36
        $builder = $this->properties->bindingsBuilder ?? $parentBuilder;
37
38
        ($this->properties->bindingsFn)(
39
            $builder,
40
            array_merge($this->properties->externalServices ?? [], $externalServices)
41
        );
42
43
        return $builder;
44
    }
45
46
    public function buildSuffixTypes(SuffixTypesBuilder $parentBuilder): SuffixTypesBuilder
47
    {
48
        $builder = $this->properties->suffixTypesBuilder ?? $parentBuilder;
49
        ($this->properties->suffixTypesFn)($builder);
50
51
        return $builder;
52
    }
53
}
54