Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| ToolsHandler | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| apply | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| properties | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Field\Schema; |
| 6 | |
| 7 | use Cosray\Exception\RuntimeException; |
| 8 | use Cosray\Field\Capability\ToolsAware; |
| 9 | use Cosray\Field\Field; |
| 10 | use Cosray\Schema\Tools; |
| 11 | use Override; |
| 12 | |
| 13 | class ToolsHandler extends Handler |
| 14 | { |
| 15 | #[Override] |
| 16 | public function apply(object $meta, Field $field): void |
| 17 | { |
| 18 | assert($meta instanceof Tools, 'The registry maps #[Tools] to this handler'); |
| 19 | |
| 20 | if ($field instanceof ToolsAware) { |
| 21 | $field->tools(...$meta->tools); |
| 22 | |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | throw new RuntimeException($this->capabilityErrorMessage($field, ToolsAware::class)); |
| 27 | } |
| 28 | |
| 29 | #[Override] |
| 30 | public function properties(object $meta, Field $field): array |
| 31 | { |
| 32 | // The field emits the resolved list itself, so fields without the |
| 33 | // attribute carry their `tools` property too. |
| 34 | return []; |
| 35 | } |
| 36 | } |