Skip to content

Commit

Permalink
return correct keys when iterating over CompoundTags, improve compoun…
Browse files Browse the repository at this point in the history
…d/array tag stringification
  • Loading branch information
KurtThiemann committed Sep 9, 2021
1 parent 0542867 commit 32eeba4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/Tag/ArrayValueTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/ByteArrayTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) . "]";
}
}
6 changes: 4 additions & 2 deletions src/Tag/CompoundTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function next()
*/
public function key()
{
return key($this->valueArray);
return $this->current()->getName();
}

/**
Expand Down Expand Up @@ -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}";
}

/**
Expand Down

0 comments on commit 32eeba4

Please sign in to comment.