Added expectedClass parameter to hasTag() to allow type-checking

This commit is contained in:
Dylan K. Taylor 2017-10-16 17:26:12 +01:00
parent 1b5746fd97
commit c8379efbce

View File

@ -140,10 +140,13 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* Returns whether the CompoundTag contains a child tag with the specified name. * Returns whether the CompoundTag contains a child tag with the specified name.
* *
* @param string $name * @param string $name
* @param string $expectedClass
*
* @return bool * @return bool
*/ */
public function hasTag(string $name) : bool{ public function hasTag(string $name, string $expectedClass = NamedTag::class) : bool{
return ($this->{$name} ?? null) instanceof NamedTag; assert(is_a($expectedClass, NamedTag::class, true));
return ($this->{$name} ?? null) instanceof $expectedClass;
} }
/** /**