Skip to content

Commit

Permalink
Move exception triggering out of packing loop and into decider
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Jan 7, 2018
1 parent 92270a0 commit d3846db
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Packer.php
Expand Up @@ -177,11 +177,6 @@ public function doVolumePacking(): PackedBoxList
}
}

//Check iteration was productive
if (!$packedBoxesIteration) {
throw new ItemTooLargeException('Item '.$this->items->top()->getDescription().' is too large to fit into any box', $this->items->top());
}

//Find best box of iteration, and remove packed items from unpacked list
$bestBox = $this->findBestBoxFromIteration($packedBoxesIteration);
$unPackedItems = iterator_to_array($this->items, false);
Expand Down Expand Up @@ -210,8 +205,13 @@ public function doVolumePacking(): PackedBoxList
*/
private function findBestBoxFromIteration($packedBoxes): PackedBox
{
usort($packedBoxes, [$this, 'compare']);
//Check iteration was productive
if (count($packedBoxes) === 0) {
throw new ItemTooLargeException('Item '.$this->items->top()->getDescription().' is too large to fit into any box', $this->items->top());
}

usort($packedBoxes, [$this, 'compare']);

return array_shift($packedBoxes);
}

Expand Down

0 comments on commit d3846db

Please sign in to comment.