Skip to content

Commit

Permalink
Allow ItemTooLargeException to return the item affected. Fixes #71
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Mar 12, 2017
1 parent 266dac7 commit 34f8fe7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions ItemTooLargeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,25 @@
class ItemTooLargeException extends \RuntimeException
{

/** @var Item */
public $item;

/**
* ItemTooLargeException constructor.
*
* @param string $message
* @param Item $item
*/
public function __construct($message, Item $item) {
$this->item = $item;
parent::__construct($message);
}

/**
* @return Item
*/
public function getItem() {
return $this->item;
}

}
2 changes: 1 addition & 1 deletion Packer.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function doVolumePacking()

//Check iteration was productive
if ($packedBoxesIteration->isEmpty()) {
throw new ItemTooLargeException('Item ' . $this->items->top()->getDescription() . ' is too large to fit into any box');
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
Expand Down

0 comments on commit 34f8fe7

Please sign in to comment.