Skip to content

Commit

Permalink
update to PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Nov 13, 2023
1 parent c6b0d14 commit 41106bc
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 40 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"require": {
"pocketmine/binaryutils": "^0.2.1",
"php": ">=8.0",
"php": ">=8.1",
"php-64bit": "*",
"ext-zlib": "*",
"ext-json": "*",
Expand Down
30 changes: 19 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Deserializer/BedrockEditionNbtDeserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function readInt(): DeserializerIntReadResult
public function readLong(): DeserializerIntReadResult
{
$raw = $this->getReader()->read(8);
$value = @unpack("q", MachineByteOrder::isBigEndian() ? strrev($raw) : $raw)[1] ?? 0;;
$value = @unpack("q", MachineByteOrder::isBigEndian() ? strrev($raw) : $raw)[1] ?? 0;
return new DeserializerIntReadResult($value, $raw);
}

Expand Down
6 changes: 4 additions & 2 deletions src/String/StringDataFormatException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Aternos\Nbt\String;

class StringDataFormatException extends \Exception
use Exception;

class StringDataFormatException extends Exception
{

}
}
18 changes: 9 additions & 9 deletions src/Tag/ArrayValueTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,23 @@ abstract protected function checkArrayValue($value): bool;
/**
* @inheritDoc
*/
public function current()
public function current(): mixed
{
return current($this->valueArray);
}

/**
* @inheritDoc
*/
public function next()
public function next(): void
{
next($this->valueArray);
}

/**
* @inheritDoc
*/
public function key()
public function key(): string|int|null
{
return key($this->valueArray);
}
Expand All @@ -113,7 +113,7 @@ public function valid(): bool
/**
* @inheritDoc
*/
public function rewind()
public function rewind(): void
{
reset($this->valueArray);
}
Expand All @@ -129,7 +129,7 @@ public function offsetExists($offset): bool
/**
* @inheritDoc
*/
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return $this->valueArray[$offset];
}
Expand All @@ -138,7 +138,7 @@ public function offsetGet($offset)
* @inheritDoc
* @throws Exception
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
if (!$this->checkArrayValue($value)) {
throw new Exception("Invalid array value");
Expand All @@ -156,7 +156,7 @@ public function offsetSet($offset, $value)
/**
* @inheritDoc
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
unset($this->valueArray[$offset]);
}
Expand All @@ -181,14 +181,14 @@ abstract protected function checkArrayKey($offset): bool;
protected function getValueString(): string
{
return $this->count() . " entr" . ($this->count() === 1 ? "y" : "ies") . "\n[\n" .
$this->indent(implode(", \n", array_map("strval", $this->valueArray))) .
$this->indent(implode(", \n", array_map(strval(...), $this->valueArray))) .
"\n]";
}

/**
* @inheritDoc
*/
public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->valueArray;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/ByteArrayTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function checkArrayKey($offset): bool
protected function getValueString(): string
{
$values = array_map(function ($elem) {
return str_pad(dechex($elem), 2, "0", STR_PAD_RIGHT);
return str_pad(dechex($elem), 2, "0");
}, array_slice($this->valueArray, 0, 32));
if (count($this->valueArray) > 32) {
$values[] = "...";
Expand Down
18 changes: 9 additions & 9 deletions src/Tag/CompoundTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function writeContent(Writer $writer): static
if (in_array($value->getName(), $writtenNames)) {
throw new Exception("Duplicate key '" . $value->getName() . "' in compound tag");
}
$value->writeData($writer, true);
$value->writeData($writer);
}
(new EndTag($this->options))->writeData($writer);
return $this;
Expand Down Expand Up @@ -116,23 +116,23 @@ public function offsetSet($offset, $value): void
/**
* @inheritDoc
*/
public function current()
public function current(): bool|Tag
{
return current($this->valueArray);
}

/**
* @inheritDoc
*/
public function next()
public function next(): void
{
next($this->valueArray);
}

/**
* @inheritDoc
*/
public function key()
public function key(): ?string
{
return $this->current()->getName();
}
Expand All @@ -148,7 +148,7 @@ public function valid(): bool
/**
* @inheritDoc
*/
public function rewind()
public function rewind(): void
{
reset($this->valueArray);
}
Expand All @@ -169,7 +169,7 @@ public function offsetExists($offset): bool
/**
* @inheritDoc
*/
public function offsetGet($offset)
public function offsetGet($offset): ?Tag
{
foreach ($this->valueArray as $val) {
if ($val->getName() === $offset) {
Expand All @@ -183,7 +183,7 @@ public function offsetGet($offset)
* @inheritDoc
* @throws Exception
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
if($this->isRaw()) {
throw new Exception("Raw compound tags cannot be modified");
Expand Down Expand Up @@ -214,14 +214,14 @@ protected function getValueString(): string
return strlen($this->rawContent) . " bytes";
}
return $this->count() . " entr" . ($this->count() === 1 ? "y" : "ies") . "\n{\n" .
$this->indent(implode(", \n", array_map("strval", array_values($this->valueArray)))) .
$this->indent(implode(", \n", array_map(strval(...), array_values($this->valueArray)))) .
"\n}";
}

/**
* @inheritDoc
*/
public function jsonSerialize()
public function jsonSerialize(): array
{
$data = [];
foreach ($this->valueArray as $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/EndTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function getValueString(): string
/**
* @inheritDoc
*/
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/FloatValueTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function getValueString(): string
/**
* @inheritDoc
*/
public function jsonSerialize()
public function jsonSerialize(): int|float
{
return $this->value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/IntValueTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function getValueString(): string
/**
* @inheritDoc
*/
public function jsonSerialize()
public function jsonSerialize(): int
{
return $this->value;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Tag/ListTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ protected function getTagTypeString(): string
/**
* @inheritDoc
*/
public function offsetSet($offset, $value)
public function offsetSet($offset, $value): void
{
if ($this->isRaw()) {
throw new Exception("Raw list tags cannot be modified");
Expand All @@ -209,7 +209,7 @@ public function offsetSet($offset, $value)
* @inheritDoc
* @throws Exception
*/
public function offsetUnset($offset)
public function offsetUnset($offset): void
{
if ($this->isRaw()) {
throw new Exception("Raw list tags cannot be modified");
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/StringTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function getValueString(): string
/**
* @inheritDoc
*/
public function jsonSerialize()
public function jsonSerialize(): string
{
return $this->value;
}
Expand Down

0 comments on commit 41106bc

Please sign in to comment.