SimpleElementView::__sleep()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Bdf\Form\Leaf\View;
4
5
use Bdf\Form\Choice\ChoiceView;
6
use Bdf\Form\Leaf\LeafElement;
7
use Bdf\Form\View\ElementViewTrait;
8
use Bdf\Form\View\FieldViewInterface;
9
use Bdf\Form\View\FieldViewRendererInterface;
10
use Bdf\Form\View\FieldViewTrait;
11
12
/**
13
 * View for simple input fields
14
 *
15
 * @see LeafElement::view()
16
 */
17
final class SimpleElementView implements FieldViewInterface
18
{
19
    use ElementViewTrait;
20
    use FieldViewTrait;
21
22
    /**
23
     * SimpleElementView constructor.
24
     *
25
     * @param string $type
26
     * @param string $name
27
     * @param mixed $value
28
     * @param string|null $error
29
     * @param bool $required
30
     * @param array $constraints
31
     * @param ChoiceView[]|null $choices
32
     */
33 70
    public function __construct(string $type, string $name, $value, ?string $error, bool $required, array $constraints, ?array $choices = null)
34
    {
35 70
        $this->type = $type;
36 70
        $this->name = $name;
37 70
        $this->value = $value;
38 70
        $this->error = $error;
39 70
        $this->required = $required;
40 70
        $this->constraints = $constraints;
41 70
        $this->choices = $choices;
42 70
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 36
    protected function defaultRenderer(): FieldViewRendererInterface
48
    {
49 36
        return $this->choices ? SelectHtmlRenderer::instance() : SimpleFieldHtmlRenderer::instance();
50
    }
51
52
    /**
53
     * Ignore property "attributes"
54
     *
55
     * @return array
56
     */
57 1
    public function __sleep(): array
58
    {
59 1
        return ['type', 'name', 'value', 'error', 'required', 'constraints', 'choices'];
60
    }
61
}
62