Remove nullable return types on CompoundTag getters

this doesn't make sense because there are default value parameters for this
This commit is contained in:
Dylan K. Taylor 2017-10-16 18:22:45 +01:00
parent c8379efbce
commit 292e462ea0
2 changed files with 15 additions and 11 deletions

View File

@ -429,7 +429,7 @@ class Item implements ItemIds, \JsonSerializable{
public function getCustomName() : string{ public function getCustomName() : string{
$display = $this->getNamedTagEntry(self::TAG_DISPLAY); $display = $this->getNamedTagEntry(self::TAG_DISPLAY);
if($display instanceof CompoundTag){ if($display instanceof CompoundTag){
return $display->getString(self::TAG_DISPLAY_NAME) ?? ""; return $display->getString(self::TAG_DISPLAY_NAME, "");
} }
return ""; return "";
@ -957,7 +957,7 @@ class Item implements ItemIds, \JsonSerializable{
} }
$count = Binary::unsignByte($tag->getByte("Count")); $count = Binary::unsignByte($tag->getByte("Count"));
$meta = $tag->getShort("Damage") ?? 0; $meta = $tag->getShort("Damage", 0);
$idTag = $tag->getTag("id"); $idTag = $tag->getTag("id");
if($idTag instanceof ShortTag){ if($idTag instanceof ShortTag){

View File

@ -165,6 +165,10 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
return $tag->getValue(); return $tag->getValue();
} }
if($default === null){
throw new \RuntimeException("Tag with name \"$name\" not found and no default value given");
}
return $default; return $default;
} }
@ -178,7 +182,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* *
* @return int * @return int
*/ */
public function getByte(string $name, ?int $default = null) : ?int{ public function getByte(string $name, ?int $default = null) : int{
return $this->getTagValue($name, ByteTag::class, $default); return $this->getTagValue($name, ByteTag::class, $default);
} }
@ -188,7 +192,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* *
* @return int * @return int
*/ */
public function getShort(string $name, ?int $default = null) : ?int{ public function getShort(string $name, ?int $default = null) : int{
return $this->getTagValue($name, ShortTag::class, $default); return $this->getTagValue($name, ShortTag::class, $default);
} }
@ -198,7 +202,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* *
* @return int * @return int
*/ */
public function getInt(string $name, ?int $default = null) : ?int{ public function getInt(string $name, ?int $default = null) : int{
return $this->getTagValue($name, IntTag::class, $default); return $this->getTagValue($name, IntTag::class, $default);
} }
@ -208,7 +212,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* *
* @return int * @return int
*/ */
public function getLong(string $name, ?int $default = null) : ?int{ public function getLong(string $name, ?int $default = null) : int{
return $this->getTagValue($name, LongTag::class, $default); return $this->getTagValue($name, LongTag::class, $default);
} }
@ -218,7 +222,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* *
* @return float * @return float
*/ */
public function getFloat(string $name, ?float $default = null) : ?float{ public function getFloat(string $name, ?float $default = null) : float{
return $this->getTagValue($name, FloatTag::class, $default); return $this->getTagValue($name, FloatTag::class, $default);
} }
@ -228,7 +232,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* *
* @return float * @return float
*/ */
public function getDouble(string $name, ?float $default = null) : ?float{ public function getDouble(string $name, ?float $default = null) : float{
return $this->getTagValue($name, DoubleTag::class, $default); return $this->getTagValue($name, DoubleTag::class, $default);
} }
@ -238,7 +242,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* *
* @return string * @return string
*/ */
public function getByteArray(string $name, ?string $default = null) : ?string{ public function getByteArray(string $name, ?string $default = null) : string{
return $this->getTagValue($name, ByteArrayTag::class, $default); return $this->getTagValue($name, ByteArrayTag::class, $default);
} }
@ -248,7 +252,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* *
* @return string * @return string
*/ */
public function getString(string $name, ?string $default = null) : ?string{ public function getString(string $name, ?string $default = null) : string{
return $this->getTagValue($name, StringTag::class, $default); return $this->getTagValue($name, StringTag::class, $default);
} }
@ -258,7 +262,7 @@ class CompoundTag extends NamedTag implements \ArrayAccess{
* *
* @return int[] * @return int[]
*/ */
public function getIntArray(string $name, ?array $default = null) : ?array{ public function getIntArray(string $name, ?array $default = null) : array{
return $this->getTagValue($name, IntArrayTag::class, $default); return $this->getTagValue($name, IntArrayTag::class, $default);
} }