Use NamedTag::class for default expectedClass in CompoundTag->getTag()

This commit is contained in:
Dylan K. Taylor 2017-10-16 17:22:38 +01:00
parent 4a0ac01697
commit 1b5746fd97

View File

@ -82,10 +82,10 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* @return NamedTag|null
* @throws \RuntimeException if the tag exists and is not of the expected type (if specified)
*/
public function getTag(string $name, ?string $expectedClass = null) : ?NamedTag{
assert($expectedClass === null or is_a($expectedClass, NamedTag::class, true));
public function getTag(string $name, string $expectedClass = NamedTag::class) : ?NamedTag{
assert(is_a($expectedClass, NamedTag::class, true));
$tag = $this->{$name} ?? null;
if($tag !== null and $expectedClass !== null and !($tag instanceof $expectedClass)){
if($tag !== null and !($tag instanceof $expectedClass)){
throw new \RuntimeException("Expected a tag of type $expectedClass, got " . get_class($tag));
}