Conditions | 1 |
Paths | 1 |
Total Lines | 15 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 2 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php declare(strict_types=1); |
||
19 | protected function validate($input): Range |
||
20 | { |
||
21 | $settings = $this->getSettings(); |
||
22 | $limit = $settings['limit'] ?? self::SIZE_LIMIT; |
||
23 | |||
24 | Assert::that($input)->string('Must be a string.')->regex('/^\[\d+,\d+\]$/', 'Invalid format.'); |
||
25 | |||
26 | $nativeRange = array_map('intval', explode(',', trim($input, '[]'))); |
||
27 | $range = Range::fromNative($nativeRange); |
||
28 | |||
29 | Assert::that($range->getSize()) |
||
30 | ->greaterOrEqualThan(0, 'Range size must be greater than 0.') |
||
31 | ->lessOrEqualThan($limit, "Range size must be at most $limit."); |
||
32 | |||
33 | return $range; |
||
34 | } |
||
36 |