| Total Complexity | 10 |
| Total Lines | 43 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | final class WidgetIntervalContainer implements IWidgetIntervalContainer |
||
| 12 | { |
||
| 13 | protected ?IInterval $smallest = null; |
||
| 14 | |||
| 15 | public function __construct( |
||
| 16 | protected readonly WeakMap $map = new WeakMap(), |
||
| 17 | ) { |
||
| 18 | } |
||
| 19 | |||
| 20 | public function getSmallest(): ?IInterval |
||
| 21 | { |
||
| 22 | return $this->smallest; |
||
| 23 | } |
||
| 24 | |||
| 25 | public function add(IInterval $interval): void |
||
| 29 | } |
||
| 30 | |||
| 31 | private function updateSmallestOnAdd(IInterval $interval): void |
||
| 32 | { |
||
| 33 | if (null === $this->smallest) { |
||
| 34 | $this->smallest = $interval; |
||
| 35 | return; |
||
| 36 | } |
||
| 37 | $this->smallest = $this->smallest->smallest($interval); |
||
| 38 | } |
||
| 39 | |||
| 40 | public function remove(IInterval $interval): void |
||
| 41 | { |
||
| 42 | if ($this->map->offsetExists($interval)) { |
||
| 43 | $this->map->offsetUnset($interval); |
||
| 44 | $this->updateSmallestOnRemove($interval); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | private function updateSmallestOnRemove(IInterval $interval): void |
||
| 54 | } |
||
| 55 | } |
||
| 56 | } |
||
| 57 | } |
||
| 58 |