Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
1 / 1
Date
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
4 / 4
5
100.00% covered (success)
100.00%
1 / 1
 control
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 value
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 structure
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 shape
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Field;
6
7use Celema\Sire\Shape;
8use Cosray\Validation\Shapes;
9use Cosray\Value\Date as DateValue;
10
11class Date extends Field
12{
13    public function control(): Control
14    {
15        return Control::date();
16    }
17
18    public function value(): DateValue
19    {
20        return new DateValue($this->owner, $this, $this->valueContext);
21    }
22
23    public function structure(mixed $value = null): array
24    {
25        return $this->getSimpleStructure('date', $value);
26    }
27
28    public function shape(): Shape
29    {
30        $shape = Shapes::create();
31        $this->addType($shape);
32
33        $value = $shape->add('value', $this->zxxShape('string', $this->validators));
34
35        if (!$this->isRequired()) {
36            $value->optional()->nullable();
37        }
38
39        $this->addMeta($shape);
40
41        return $shape;
42    }
43}