Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
33.33% covered (danger)
33.33%
4 / 12
50.00% covered (danger)
50.00%
2 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
Option
33.33% covered (danger)
33.33%
4 / 12
50.00% covered (danger)
50.00%
2 / 4
12.41
0.00% covered (danger)
0.00%
0 / 1
 value
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 properties
100.00% covered (success)
100.00%
3 / 3
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 Celemas\Sire\Shape;
8use Cosray\Validation\Shapes;
9use Cosray\Value;
10
11class Option extends Field implements Capability\Selectable
12{
13    use Capability\IsSelectable;
14
15    protected bool $hasLabel = false;
16
17    public function value(): Value\Option
18    {
19        return new Value\Option($this->owner, $this, $this->valueContext);
20    }
21
22    public function properties(): array
23    {
24        $result = parent::properties();
25        $result['hasLabel'] = $this->hasLabel;
26
27        return $result;
28    }
29
30    public function structure(mixed $value = null): array
31    {
32        return $this->getSimpleStructure('option', $value);
33    }
34
35    public function shape(): Shape
36    {
37        $shape = Shapes::create();
38        $this->addType($shape);
39
40        $value = $shape->add('value', $this->zxxShape('string', $this->validators));
41
42        if (!$this->isRequired()) {
43            $value->optional()->nullable();
44        }
45
46        $this->addMeta($shape);
47
48        return $shape;
49    }
50}