Item: restrict bounds of count to 0-255

This commit is contained in:
Dylan K. Taylor 2020-02-23 17:23:53 +00:00
parent 46ac4cbca1
commit 10317527e4
2 changed files with 18 additions and 0 deletions

View File

@ -557,6 +557,10 @@ class Item implements ItemIds, \JsonSerializable{
* @return $this
*/
public function setCount(int $count) : Item{
if($count < 0 or $count > 255){
throw new \InvalidArgumentException("Count must be in the range 0-255");
}
$this->count = $count;
return $this;

View File

@ -89,4 +89,18 @@ class ItemTest extends TestCase{
self::assertEquals($id, $item->getId());
self::assertEquals($meta, $item->getDamage());
}
public function testSetCountTooBig() : void{
$this->expectException(\InvalidArgumentException::class);
$item = ItemFactory::get(ItemIds::STONE);
$item->setCount(256);
}
public function testSetCountTooSmall() : void{
$this->expectException(\InvalidArgumentException::class);
$item = ItemFactory::get(ItemIds::STONE);
$item->setCount(-1);
}
}