Passed
Branch master (3daac1)
by Vincent
07:53
created

LeafRootElement   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 16
eloc 21
c 1
b 0
f 0
dl 0
loc 142
ccs 32
cts 36
cp 0.8889
rs 10

16 Methods

Rating   Name   Duplication   Size   Complexity  
A error() 0 3 1
A container() 0 3 1
A root() 0 3 1
A view() 0 3 1
A patch() 0 5 1
A setContainer() 0 3 1
A __construct() 0 3 1
A constraintGroups() 0 3 1
A submit() 0 5 1
A httpValue() 0 3 1
A value() 0 3 1
A valid() 0 3 1
A getPropertyAccessor() 0 3 1
A getValidator() 0 3 1
A import() 0 5 1
A submitButton() 0 3 1
1
<?php
2
3
namespace Bdf\Form\Leaf;
4
5
use BadMethodCallException;
6
use Bdf\Form\Button\ButtonInterface;
7
use Bdf\Form\Child\ChildInterface;
8
use Bdf\Form\Child\Http\HttpFieldPath;
9
use Bdf\Form\ElementInterface;
10
use Bdf\Form\Error\FormError;
11
use Bdf\Form\RootElementInterface;
12
use Bdf\Form\View\ElementViewInterface;
13
use Symfony\Component\PropertyAccess\PropertyAccessor;
14
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
15
use Symfony\Component\Validator\Constraint;
16
use Symfony\Component\Validator\Validator\ValidatorInterface;
17
use Symfony\Component\Validator\ValidatorBuilder;
18
19
/**
20
 * Wrap a leaf element for create a root element
21
 * Useful for create a singleton form
22
 */
23
final class LeafRootElement implements RootElementInterface
24
{
25
    /**
26
     * @var ElementInterface
27
     */
28
    private $element;
29
30
31
    /**
32
     * LeafRootElement constructor.
33
     *
34
     * @param ElementInterface $element
35
     */
36 134
    public function __construct(ElementInterface $element)
37
    {
38 134
        $this->element = $element;
39 134
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function submit($data): ElementInterface
45
    {
46 1
        $this->element->submit($data);
47
48 1
        return $this;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function patch($data): ElementInterface
55
    {
56 1
        $this->element->patch($data);
57
58 1
        return $this;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 1
    public function import($entity): ElementInterface
65
    {
66 1
        $this->element->import($entity);
67
68 1
        return $this;
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 1
    public function value()
75
    {
76 1
        return $this->element->value();
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 1
    public function httpValue()
83
    {
84 1
        return $this->element->httpValue();
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90 1
    public function valid(): bool
91
    {
92 1
        return $this->element->valid();
93
    }
94
95
    /**
96
     * {@inheritdoc}
97
     */
98 1
    public function error(): FormError
99
    {
100 1
        return $this->element->error();
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106 1
    public function container(): ?ChildInterface
107
    {
108 1
        return null;
109
    }
110
111
    /**
112
     * {@inheritdoc}
113
     */
114
    public function setContainer(ChildInterface $container): ElementInterface
115
    {
116
        throw new BadMethodCallException('Cannot set a container on a root element');
117
    }
118
119
    /**
120
     * {@inheritdoc}
121
     */
122 1
    public function root(): RootElementInterface
123
    {
124 1
        return $this;
125
    }
126
127
    /**
128
     * {@inheritdoc}
129
     */
130
    public function view(?HttpFieldPath $field = null): ElementViewInterface
131
    {
132
        return $this->element->view($field);
133
    }
134
135
    /**
136
     * {@inheritdoc}
137
     */
138 1
    public function submitButton(): ?ButtonInterface
139
    {
140 1
        return null;
141
    }
142
143
    /**
144
     * {@inheritdoc}
145
     */
146 114
    public function getValidator(): ValidatorInterface
147
    {
148 114
        return (new ValidatorBuilder())->getValidator();
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154 3
    public function getPropertyAccessor(): PropertyAccessorInterface
155
    {
156 3
        return new PropertyAccessor();
157
    }
158
159
    /**
160
     * {@inheritdoc}
161
     */
162 114
    public function constraintGroups(): array
163
    {
164 114
        return [Constraint::DEFAULT_GROUP];
165
    }
166
}
167