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.
*
* @param string $name
* @param string $expectedClass
*
* @return bool
*/
public function hasTag(string $name) : bool{
return ($this->{$name} ?? null) instanceof NamedTag;
public function hasTag(string $name, string $expectedClass = NamedTag::class) : bool{
assert(is_a($expectedClass, NamedTag::class, true));
return ($this->{$name} ?? null) instanceof $expectedClass;
}
/**