Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
83.33% |
10 / 12 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| LimitHandler | |
83.33% |
10 / 12 |
|
0.00% |
0 / 2 |
4.07 | |
0.00% |
0 / 1 |
| apply | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
| properties | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
2.01 | |||
| 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\Limitable; |
| 9 | use Cosray\Field\Field; |
| 10 | |
| 11 | class LimitHandler extends Handler |
| 12 | { |
| 13 | public function apply(object $meta, Field $field): void |
| 14 | { |
| 15 | if ($field instanceof Limitable) { |
| 16 | $field->limit($meta->max, $meta->min); |
| 17 | |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | throw new RuntimeException($this->capabilityErrorMessage($field, Limitable::class)); |
| 22 | } |
| 23 | |
| 24 | public function properties(object $meta, Field $field): array |
| 25 | { |
| 26 | if ($field instanceof Limitable) { |
| 27 | return [ |
| 28 | 'limit' => [ |
| 29 | 'min' => $field->getLimitMin(), |
| 30 | 'max' => $field->getLimitMax(), |
| 31 | ], |
| 32 | ]; |
| 33 | } |
| 34 | |
| 35 | return []; |
| 36 | } |
| 37 | } |