From 41106bc58c19e3b6ecbe8a1a6410210ac5b7b808 Mon Sep 17 00:00:00 2001 From: Kurt Thiemann Date: Mon, 13 Nov 2023 13:52:33 +0100 Subject: [PATCH] update to PHP 8.1 --- composer.json | 2 +- composer.lock | 30 ++++++++++++------- .../BedrockEditionNbtDeserializer.php | 2 +- src/String/StringDataFormatException.php | 6 ++-- src/Tag/ArrayValueTag.php | 18 +++++------ src/Tag/ByteArrayTag.php | 2 +- src/Tag/CompoundTag.php | 18 +++++------ src/Tag/EndTag.php | 2 +- src/Tag/FloatValueTag.php | 2 +- src/Tag/IntValueTag.php | 2 +- src/Tag/ListTag.php | 4 +-- src/Tag/StringTag.php | 2 +- 12 files changed, 50 insertions(+), 40 deletions(-) diff --git a/composer.json b/composer.json index d81e0fe..436fd85 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ ], "require": { "pocketmine/binaryutils": "^0.2.1", - "php": ">=8.0", + "php": ">=8.1", "php-64bit": "*", "ext-zlib": "*", "ext-json": "*", diff --git a/composer.lock b/composer.lock index c082a91..103935a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0801dc76c62b7624691dd2eb12caf7a0", + "content-hash": "98a0214009234bb58b601d4cdb87f734", "packages": [ { "name": "pocketmine/binaryutils", - "version": "0.2.1", + "version": "0.2.4", "source": { "type": "git", "url": "https://github.com/pmmp/BinaryUtils.git", - "reference": "8cd078e2426f8100331f2d73bef10f481dad6cde" + "reference": "5ac7eea91afbad8dc498f5ce34ce6297d5e6ea9a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/pmmp/BinaryUtils/zipball/8cd078e2426f8100331f2d73bef10f481dad6cde", - "reference": "8cd078e2426f8100331f2d73bef10f481dad6cde", + "url": "https://api.github.com/repos/pmmp/BinaryUtils/zipball/5ac7eea91afbad8dc498f5ce34ce6297d5e6ea9a", + "reference": "5ac7eea91afbad8dc498f5ce34ce6297d5e6ea9a", "shasum": "" }, "require": { @@ -26,8 +26,10 @@ }, "require-dev": { "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "0.12.85", - "phpstan/phpstan-strict-rules": "^0.12.4" + "phpstan/phpstan": "1.3.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-strict-rules": "^1.0.0", + "phpunit/phpunit": "^9.5" }, "type": "library", "autoload": { @@ -42,9 +44,9 @@ "description": "Classes and methods for conveniently handling binary data", "support": { "issues": "https://github.com/pmmp/BinaryUtils/issues", - "source": "https://github.com/pmmp/BinaryUtils/tree/0.2.1" + "source": "https://github.com/pmmp/BinaryUtils/tree/0.2.4" }, - "time": "2021-05-30T19:42:57+00:00" + "time": "2022-01-12T18:06:33+00:00" } ], "packages-dev": [], @@ -53,7 +55,13 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "php": ">=8.1", + "php-64bit": "*", + "ext-zlib": "*", + "ext-json": "*", + "ext-mbstring": "*" + }, "platform-dev": [], - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Deserializer/BedrockEditionNbtDeserializer.php b/src/Deserializer/BedrockEditionNbtDeserializer.php index 388a891..35ba5e0 100644 --- a/src/Deserializer/BedrockEditionNbtDeserializer.php +++ b/src/Deserializer/BedrockEditionNbtDeserializer.php @@ -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); } diff --git a/src/String/StringDataFormatException.php b/src/String/StringDataFormatException.php index 65e779e..40f4e7b 100644 --- a/src/String/StringDataFormatException.php +++ b/src/String/StringDataFormatException.php @@ -2,7 +2,9 @@ namespace Aternos\Nbt\String; -class StringDataFormatException extends \Exception +use Exception; + +class StringDataFormatException extends Exception { -} \ No newline at end of file +} diff --git a/src/Tag/ArrayValueTag.php b/src/Tag/ArrayValueTag.php index e707c1e..50157be 100644 --- a/src/Tag/ArrayValueTag.php +++ b/src/Tag/ArrayValueTag.php @@ -81,7 +81,7 @@ abstract protected function checkArrayValue($value): bool; /** * @inheritDoc */ - public function current() + public function current(): mixed { return current($this->valueArray); } @@ -89,7 +89,7 @@ public function current() /** * @inheritDoc */ - public function next() + public function next(): void { next($this->valueArray); } @@ -97,7 +97,7 @@ public function next() /** * @inheritDoc */ - public function key() + public function key(): string|int|null { return key($this->valueArray); } @@ -113,7 +113,7 @@ public function valid(): bool /** * @inheritDoc */ - public function rewind() + public function rewind(): void { reset($this->valueArray); } @@ -129,7 +129,7 @@ public function offsetExists($offset): bool /** * @inheritDoc */ - public function offsetGet($offset) + public function offsetGet($offset): mixed { return $this->valueArray[$offset]; } @@ -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"); @@ -156,7 +156,7 @@ public function offsetSet($offset, $value) /** * @inheritDoc */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { unset($this->valueArray[$offset]); } @@ -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; } diff --git a/src/Tag/ByteArrayTag.php b/src/Tag/ByteArrayTag.php index df91024..649a5fe 100644 --- a/src/Tag/ByteArrayTag.php +++ b/src/Tag/ByteArrayTag.php @@ -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[] = "..."; diff --git a/src/Tag/CompoundTag.php b/src/Tag/CompoundTag.php index 015e119..d53ed87 100644 --- a/src/Tag/CompoundTag.php +++ b/src/Tag/CompoundTag.php @@ -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; @@ -116,7 +116,7 @@ public function offsetSet($offset, $value): void /** * @inheritDoc */ - public function current() + public function current(): bool|Tag { return current($this->valueArray); } @@ -124,7 +124,7 @@ public function current() /** * @inheritDoc */ - public function next() + public function next(): void { next($this->valueArray); } @@ -132,7 +132,7 @@ public function next() /** * @inheritDoc */ - public function key() + public function key(): ?string { return $this->current()->getName(); } @@ -148,7 +148,7 @@ public function valid(): bool /** * @inheritDoc */ - public function rewind() + public function rewind(): void { reset($this->valueArray); } @@ -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) { @@ -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"); @@ -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) { diff --git a/src/Tag/EndTag.php b/src/Tag/EndTag.php index a78671f..1e4356c 100644 --- a/src/Tag/EndTag.php +++ b/src/Tag/EndTag.php @@ -52,7 +52,7 @@ protected function getValueString(): string /** * @inheritDoc */ - public function jsonSerialize() + public function jsonSerialize(): mixed { return null; } diff --git a/src/Tag/FloatValueTag.php b/src/Tag/FloatValueTag.php index a6ff846..819cdca 100644 --- a/src/Tag/FloatValueTag.php +++ b/src/Tag/FloatValueTag.php @@ -35,7 +35,7 @@ protected function getValueString(): string /** * @inheritDoc */ - public function jsonSerialize() + public function jsonSerialize(): int|float { return $this->value; } diff --git a/src/Tag/IntValueTag.php b/src/Tag/IntValueTag.php index 96d4462..178c405 100644 --- a/src/Tag/IntValueTag.php +++ b/src/Tag/IntValueTag.php @@ -35,7 +35,7 @@ protected function getValueString(): string /** * @inheritDoc */ - public function jsonSerialize() + public function jsonSerialize(): int { return $this->value; } diff --git a/src/Tag/ListTag.php b/src/Tag/ListTag.php index d171ae1..e1b4004 100644 --- a/src/Tag/ListTag.php +++ b/src/Tag/ListTag.php @@ -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"); @@ -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"); diff --git a/src/Tag/StringTag.php b/src/Tag/StringTag.php index bafcc38..eaccb97 100644 --- a/src/Tag/StringTag.php +++ b/src/Tag/StringTag.php @@ -81,7 +81,7 @@ protected function getValueString(): string /** * @inheritDoc */ - public function jsonSerialize() + public function jsonSerialize(): string { return $this->value; }