AbstractConfigurator   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 18
c 1
b 0
f 0
dl 0
loc 79
ccs 18
cts 18
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A preCreateEditables() 0 3 1
A createEditables() 0 8 1
A getExpressionWrapper() 0 3 1
A postCreateEditables() 0 3 1
A getEditablesExpressionAttributes() 0 3 1
A evaluateExpressions() 0 11 1
A __construct() 0 7 2
1
<?php
2
3
namespace Khusseini\PimcoreRadBrickBundle\Configurator;
4
5
use Khusseini\PimcoreRadBrickBundle\ExpressionLanguage\ExpressionWrapper;
6
use Khusseini\PimcoreRadBrickBundle\RenderArgumentEmitter;
7
8
abstract class AbstractConfigurator implements IConfigurator
9
{
10
    /**
11
     * @var ExpressionWrapper
12
     */
13
    private $expressionWrapper;
14
15 34
    public function __construct(ExpressionWrapper $expressionWrapper = null)
16
    {
17 34
        if (!$expressionWrapper) {
18 34
            $expressionWrapper = new ExpressionWrapper();
19
        }
20
21 34
        $this->expressionWrapper = $expressionWrapper;
22 34
    }
23
24
    /**
25
     * @param array<array> $data
26
     */
27
    abstract public function doCreateEditables(
28
        RenderArgumentEmitter $emitter,
29
        string $name,
30
        ConfiguratorData $data
31
    ): void;
32
33
    /**
34
     * @return array<string>
35
     * @codeCoverageIgnore
36
     */
37
    public function getEditablesExpressionAttributes(): array
38
    {
39
        return [];
40
    }
41
42 7
    public function createEditables(
43
        RenderArgumentEmitter $emitter,
44
        string $name,
45
        ConfiguratorData $data
46
    ): void {
47 7
        $attributes = $this->getEditablesExpressionAttributes();
48 7
        $data = $this->evaluateExpressions($data, $attributes);
49 7
        $this->doCreateEditables($emitter, $name, $data);
50 7
    }
51
52
    /**
53
     * @codeCoverageIgnore
54
     */
55
    public function preCreateEditables(string $brickName, ConfiguratorData $data): void
56
    {
57
        return;
58
    }
59
60
    /**
61
     * @codeCoverageIgnore
62
     */
63
    public function postCreateEditables(string $brickName, ConfiguratorData $data, RenderArgumentEmitter $emitter): void
64
    {
65
        return;
66
    }
67
68
    /**
69
     * @param array<string> $attributes
70
     */
71 7
    protected function evaluateExpressions(ConfiguratorData $data, array $attributes): ConfiguratorData
72
    {
73
        $input = [
74 7
            'editable' => $data->getConfig(),
75 7
            'context' => $data->getContext()->toArray(),
76
        ];
77
78 7
        $config = $this->getExpressionWrapper()->evaluateExpressions($input, $attributes, '[context]');
79 7
        $data->setConfig($config['editable']);
80
81 7
        return $data;
82
    }
83
84 14
    protected function getExpressionWrapper(): ExpressionWrapper
85
    {
86 14
        return $this->expressionWrapper;
87
    }
88
}
89