| Total Complexity | 6 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | abstract class AbstractElementBuilder implements ElementBuilderInterface |
||
| 19 | { |
||
| 20 | use TransformerBuilderTrait; |
||
| 21 | use ValidatorBuilderTrait; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var RegistryInterface |
||
| 25 | */ |
||
| 26 | private $registry; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var mixed |
||
| 30 | */ |
||
| 31 | private $value; |
||
| 32 | |||
| 33 | |||
| 34 | /** |
||
| 35 | * ElementBuilder constructor. |
||
| 36 | * |
||
| 37 | * @param RegistryInterface|null $registry |
||
| 38 | */ |
||
| 39 | 383 | public function __construct(RegistryInterface $registry = null) |
|
| 40 | { |
||
| 41 | 383 | $this->registry = $registry ?: new Registry(); |
|
| 42 | 383 | } |
|
| 43 | |||
| 44 | /** |
||
| 45 | * {@inheritdoc} |
||
| 46 | */ |
||
| 47 | 17 | final public function value($value) |
|
| 48 | { |
||
| 49 | 17 | $this->value = $value; |
|
| 50 | |||
| 51 | 17 | return $this; |
|
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * {@inheritdoc} |
||
| 56 | */ |
||
| 57 | 379 | final public function buildElement(): ElementInterface |
|
| 58 | { |
||
| 59 | 379 | $element = $this->createElement($this->buildValidator(), $this->buildTransformer()); |
|
| 60 | |||
| 61 | 379 | if ($this->value !== null) { |
|
| 62 | 17 | $element->import($this->value); |
|
| 63 | } |
||
| 64 | |||
| 65 | 379 | return $element; |
|
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Creates the element |
||
| 70 | * |
||
| 71 | * @param ValueValidatorInterface $validator |
||
| 72 | * @param TransformerInterface $transformer |
||
| 73 | * |
||
| 74 | * @return E |
||
| 75 | */ |
||
| 76 | abstract protected function createElement(ValueValidatorInterface $validator, TransformerInterface $transformer): ElementInterface; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * {@inheritdoc} |
||
| 80 | */ |
||
| 81 | 379 | final protected function registry(): RegistryInterface |
|
| 84 | } |
||
| 85 | } |
||
| 86 |