| Total Complexity | 6 |
| Total Lines | 60 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | class BoxList implements IteratorAggregate |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * List containing boxes. |
||
| 25 | * |
||
| 26 | * @var Box[] |
||
| 27 | */ |
||
| 28 | private $list = []; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Has this list already been sorted? |
||
| 32 | * |
||
| 33 | * @var bool |
||
| 34 | */ |
||
| 35 | private $isSorted = false; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return Traversable |
||
| 39 | */ |
||
| 40 | 26 | public function getIterator(): Traversable |
|
| 41 | { |
||
| 42 | 26 | if (!$this->isSorted) { |
|
| 43 | 26 | usort($this->list, [$this, 'compare']); |
|
| 44 | 26 | $this->isSorted = true; |
|
| 45 | } |
||
| 46 | |||
| 47 | 26 | return new ArrayIterator($this->list); |
|
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param Box $item |
||
| 52 | */ |
||
| 53 | 25 | public function insert(Box $item): void |
|
| 56 | 25 | } |
|
| 57 | |||
| 58 | /** |
||
| 59 | * @param Box $boxA |
||
| 60 | * @param Box $boxB |
||
| 61 | * |
||
| 62 | * @return int |
||
| 63 | */ |
||
| 64 | 13 | public function compare($boxA, $boxB): int |
|
| 83 |