Passed
Push — master ( 4ada59...3080fc )
by Bruno
09:58
created

Renderable_date::editable()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 5
eloc 14
c 1
b 1
f 0
nc 9
nop 3
dl 0
loc 22
rs 9.4888
1
<?php declare(strict_types=1);
2
3
namespace Formularium\Frontend\HTMLValidation\Renderable;
4
5
use Formularium\Datatype\Datatype_date;
6
use Formularium\Field;
7
use Formularium\HTMLNode;
8
use Formularium\Validator\Max;
9
use Formularium\Validator\Min;
10
11
class Renderable_date extends Renderable_string
12
{
13
    public function editable($value, Field $field, HTMLNode $previous): HTMLNode
14
    {
15
        $element = parent::editable($value, $field, $previous);
16
        $input = $element->get('input')[0];
17
        $input->setAttribute('type', 'date');
18
19
        $min = $field->getValidatorOption(Min::class);
20
        if ($min) {
21
            if ($min === 'now') {
22
                $min = Datatype_date::fromString($min);
23
            }
24
            $input->setAttribute('min', $min);
25
        }
26
        $max = $field->getValidatorOption(Max::class);
27
        if ($max) {
28
            if ($max === 'now') {
29
                $max = Datatype_date::fromString($max);
30
            }
31
            $input->setAttribute('max', $max);
32
        }
33
34
        return $element;
35
    }
36
}
37