PotionCauldron: fixed setPotionItem() not validating the given item

we should probably remove this API and have enums for potion container and type tbh... this API was a mistake
This commit is contained in:
Dylan K. Taylor 2023-08-10 16:06:25 +01:00
parent f03e708f64
commit 91d5a3ddfe
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -63,6 +63,14 @@ final class PotionCauldron extends FillableCauldron{
/** @return $this */
public function setPotionItem(?Item $potionItem) : self{
if($potionItem !== null && !match($potionItem->getTypeId()){
ItemTypeIds::POTION,
ItemTypeIds::SPLASH_POTION,
ItemTypeIds::LINGERING_POTION => true,
default => false,
}){
throw new \InvalidArgumentException("Item must be a POTION, SPLASH_POTION or LINGERING_POTION");
}
$this->potionItem = $potionItem !== null ? (clone $potionItem)->setCount(1) : null;
return $this;
}