From 32eeba4ec1794b2156b51007c5b9d7064932cb41 Mon Sep 17 00:00:00 2001 From: Kurt Thiemann Date: Thu, 9 Sep 2021 15:57:00 +0200 Subject: [PATCH] return correct keys when iterating over CompoundTags, improve compound/array tag stringification --- src/Tag/ArrayValueTag.php | 4 +++- src/Tag/ByteArrayTag.php | 2 +- src/Tag/CompoundTag.php | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Tag/ArrayValueTag.php b/src/Tag/ArrayValueTag.php index 1c23419..9c29412 100644 --- a/src/Tag/ArrayValueTag.php +++ b/src/Tag/ArrayValueTag.php @@ -154,7 +154,9 @@ abstract protected function checkArrayKey($offset): bool; */ protected function getValueString(): string { - return $this->count() . " entries\n[\n" . $this->indent(implode(", \n", array_map("strval", $this->valueArray))) . "\n]"; + return $this->count() . " entr" . ($this->count() === 1 ? "y" : "ies") . "\n[\n" . + $this->indent(implode(", \n", array_map("strval", $this->valueArray))) . + "\n]"; } /** diff --git a/src/Tag/ByteArrayTag.php b/src/Tag/ByteArrayTag.php index a60bb03..7659ad9 100644 --- a/src/Tag/ByteArrayTag.php +++ b/src/Tag/ByteArrayTag.php @@ -62,6 +62,6 @@ protected function getValueString(): string if(count($this->valueArray) > 32) { $values[] = "..."; } - return $this->count() . " bytes [" . implode(" ", $values) . "]"; + return $this->count() . " byte" . ($this->count() === 1 ? "" : "s") . " [" . implode(" ", $values) . "]"; } } diff --git a/src/Tag/CompoundTag.php b/src/Tag/CompoundTag.php index f8b2821..0477db4 100644 --- a/src/Tag/CompoundTag.php +++ b/src/Tag/CompoundTag.php @@ -91,7 +91,7 @@ public function next() */ public function key() { - return key($this->valueArray); + return $this->current()->getName(); } /** @@ -162,7 +162,9 @@ public function count(): int */ protected function getValueString(): string { - return $this->count() . " entries\n{\n" . $this->indent(implode(", \n", array_map("strval", array_values($this->valueArray)))) . "\n}"; + return $this->count() . " entr" . ($this->count() === 1 ? "y" : "ies") . "\n{\n" . + $this->indent(implode(", \n", array_map("strval", array_values($this->valueArray)))) . + "\n}"; } /**