Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Option | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
6 | |
100.00% |
1 / 1 |
| control | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| value | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| properties | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| structure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| shape | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Field; |
| 6 | |
| 7 | use Celema\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 | public function control(): Control |
| 16 | { |
| 17 | return Control::option(); |
| 18 | } |
| 19 | |
| 20 | protected bool $hasLabel = false; |
| 21 | |
| 22 | public function value(): Value\Option |
| 23 | { |
| 24 | return new Value\Option($this->owner, $this, $this->valueContext); |
| 25 | } |
| 26 | |
| 27 | public function properties(): array |
| 28 | { |
| 29 | $result = parent::properties(); |
| 30 | $result['hasLabel'] = $this->hasLabel; |
| 31 | |
| 32 | return $result; |
| 33 | } |
| 34 | |
| 35 | public function structure(mixed $value = null): array |
| 36 | { |
| 37 | return $this->getSimpleStructure('option', $value); |
| 38 | } |
| 39 | |
| 40 | public function shape(): Shape |
| 41 | { |
| 42 | $shape = Shapes::create(); |
| 43 | $this->addType($shape); |
| 44 | |
| 45 | $value = $shape->add('value', $this->zxxShape('string', $this->validators)); |
| 46 | |
| 47 | if (!$this->isRequired()) { |
| 48 | $value->optional()->nullable(); |
| 49 | } |
| 50 | |
| 51 | $this->addMeta($shape); |
| 52 | |
| 53 | return $shape; |
| 54 | } |
| 55 | } |