Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
20.00% covered (danger)
20.00%
2 / 10
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Number
20.00% covered (danger)
20.00%
2 / 10
50.00% covered (danger)
50.00%
2 / 4
17.80
0.00% covered (danger)
0.00%
0 / 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
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 shape
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Field;
6
7use Celema\Sire\Shape;
8use Cosray\Validation\Shapes;
9use Cosray\Value\Number as NumberValue;
10
11class Number extends Field
12{
13    public function control(): Control
14    {
15        return Control::number();
16    }
17
18    public function value(): NumberValue
19    {
20        return new NumberValue($this->owner, $this, $this->valueContext);
21    }
22
23    public function structure(mixed $value = null): array
24    {
25        return $this->getSimpleStructure('number', $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('float', $this->validators));
34
35        if (!$this->isRequired()) {
36            $value->optional()->nullable();
37        }
38
39        $this->addMeta($shape);
40
41        return $shape;
42    }
43}