Skip to content

Commit

Permalink
improve code style, support PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtThiemann committed Oct 27, 2021
1 parent 79925c1 commit 69a58cd
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
],
"require": {
"pocketmine/binaryutils": "^0.2.1",
"php": "^7.4 || ^8.0",
"php-64bit": "*",
"ext-zlib": "*",
"ext-json": "*"
Expand Down
3 changes: 2 additions & 1 deletion src/Serializer/JavaEditionNbtSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public function encodeShort(int $value): string
}

/**
* @inheritDoc
* @param string $data
* @return int
*/
public function decodeInt(string $data): int
{
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/ArrayValueTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function generatePayload(NbtSerializer $serializer): string
{
$count = $this->count();
if($count > 0x7fffffff) {
throw new \Exception("Array exceeds maximum length of " . 0x7fffffff . " entries");
throw new Exception("Array exceeds maximum length of " . 0x7fffffff . " entries");
}
return $serializer->encodeLengthPrefix($this->count()) . $this->generateValues($serializer);
}
Expand Down
5 changes: 4 additions & 1 deletion src/Tag/CompoundTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

namespace Aternos\Nbt\Tag;

use ArrayAccess;
use Aternos\Nbt\IO\Reader\Reader;
use Aternos\Nbt\Serializer\NbtSerializer;
use Countable;
use Exception;
use Iterator;

class CompoundTag extends Tag implements \Iterator, \ArrayAccess, \Countable
class CompoundTag extends Tag implements Iterator, ArrayAccess, Countable
{
public const TYPE = TagType::TAG_Compound;

Expand Down
2 changes: 0 additions & 2 deletions src/Tag/IntValueTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Aternos\Nbt\Tag;

use Aternos\Nbt\IO\Reader\Reader;

abstract class IntValueTag extends Tag
{
protected int $value;
Expand Down
5 changes: 3 additions & 2 deletions src/Tag/StringTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Aternos\Nbt\IO\Reader\Reader;
use Aternos\Nbt\Serializer\NbtSerializer;
use Exception;

class StringTag extends Tag
{
Expand Down Expand Up @@ -39,13 +40,13 @@ public function getLength(): int

/**
* @inheritDoc
* @throws \Exception
* @throws Exception
*/
public function generatePayload(NbtSerializer $serializer): string
{
$length = strlen($this->value);
if($length > 0xffff) {
throw new \Exception("String exceeds maximum length of " . 0xffff . " characters");
throw new Exception("String exceeds maximum length of " . 0xffff . " characters");
}
return $serializer->encodeStringLengthPrefix($length) . $this->value;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Tag/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function write(Writer $writer): Tag
if(!($this instanceof CompoundTag) && !(in_array($writer->getFormat(), [NbtFormat::BEDROCK_EDITION_NETWORK, NbtFormat::BEDROCK_EDITION]) && $this instanceof ListTag)){
throw new Exception("NBT files must start with a CompoundTag (or ListTag for Minecraft Bedrock Edition)");
}
$writer->write($this->serialize($writer->getSerializer()), true);
$writer->write($this->serialize($writer->getSerializer()));
return $this;
}

Expand Down

0 comments on commit 69a58cd

Please sign in to comment.