| Total Complexity | 7 |
| Total Lines | 71 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | * Do a bulk create. |
||
| 39 | * |
||
| 40 | * @param Box[] $items |
||
| 41 | * @return BoxList |
||
| 42 | */ |
||
| 43 | 2 | public static function fromArray(array $boxes, bool $preSorted = false): self |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @return Traversable<Box> |
||
| 54 | */ |
||
| 55 | 39 | public function getIterator(): Traversable |
|
| 56 | { |
||
| 57 | 39 | if (!$this->isSorted) { |
|
| 58 | 38 | usort($this->list, [$this, 'compare']); |
|
| 59 | 38 | $this->isSorted = true; |
|
| 60 | } |
||
| 61 | |||
| 62 | 39 | return new ArrayIterator($this->list); |
|
| 63 | } |
||
| 64 | |||
| 65 | 36 | public function insert(Box $item): void |
|
| 66 | { |
||
| 67 | 36 | $this->list[] = $item; |
|
| 68 | 36 | } |
|
| 69 | |||
| 70 | /** |
||
| 71 | * @param Box $boxA |
||
| 72 | * @param Box $boxB |
||
| 73 | */ |
||
| 74 | 23 | public static function compare($boxA, $boxB): int |
|
| 92 | } |
||
| 93 | } |
||
| 94 |