diff --git a/ItemTooLargeException.php b/ItemTooLargeException.php index aa661934..6ae89f13 100644 --- a/ItemTooLargeException.php +++ b/ItemTooLargeException.php @@ -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; + } + } diff --git a/Packer.php b/Packer.php index dbe6bc0a..2d57c9c0 100644 --- a/Packer.php +++ b/Packer.php @@ -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