/** * Feed the item to a specified pet. * * Increases pet's hunger level and destroys the item. * * @param Pet $pet * @return string The success message. **/ public function feedTo(Pet $pet, $quantity) { if ($quantity > $this->getQuantity()) { throw new ArgumentError("This stack does not have {$quantity} items."); } // Do it before destroying the object. $pet->consume($this->getHungerBonus() * $quantity); $text = "You have fed {$pet->getPetName()} {$this->makeActionText($quantity)}."; $this->updateQuantity($this->getQuantity() - $quantity); return $text; }