Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
33.33% |
4 / 12 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Option | |
33.33% |
4 / 12 |
|
50.00% |
2 / 4 |
12.41 | |
0.00% |
0 / 1 |
| value | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| properties | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| structure | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| shape | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Field; |
| 6 | |
| 7 | use Celemas\Sire\Shape; |
| 8 | use Cosray\Validation\Shapes; |
| 9 | use Cosray\Value; |
| 10 | |
| 11 | class 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 | } |