Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| IntegerBounds | |
100.00% |
6 / 6 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| add | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| isCloserToEnd | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| flip | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | class IntegerBounds |
| 4 | { |
| 5 | public function add(int $value): void |
| 6 | { |
| 7 | $this->min = min($this->min, $value); |
| 8 | $this->max = max($this->max, $value); |
| 9 | } |
| 10 | |
| 11 | public function isCloserToEnd($size) |
| 12 | { |
| 13 | return $size - 1 - $this->min < $this->max; |
| 14 | } |
| 15 | |
| 16 | public function flip($size) |
| 17 | { |
| 18 | $minSave = $this->min; |
| 19 | $this->min = $size - 1 - $this->max; |
| 20 | $this->max = $size - 1 - $minSave; |
| 21 | } |
| 22 | |
| 23 | public int $min = PHP_INT_MAX; |
| 24 | public int $max = 0; |
| 25 | } |