Skip to content

Commit

Permalink
Improve PHPDocs, push to PHPStan level 10
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Jan 7, 2025
1 parent 97472e0 commit 8cb4567
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ includes:
- tests/phpstan/configs/phpstan-bugs.neon

parameters:
level: 9
level: 10
treatPhpDocTypesAsCertain: false
paths:
- src
1 change: 1 addition & 0 deletions src/BaseNbtSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function readHeadless(string $buffer, int $rootType, int &$offset = 0, in
* TODO: This is only necessary because we don't have a streams API worth mentioning. Get rid of this in the future.
*
* @return TreeRoot[]
* @phpstan-return list<TreeRoot>
* @throws NbtDataException
*/
public function readMultiple(string $buffer, int $maxDepth = 0) : array{
Expand Down
1 change: 1 addition & 0 deletions src/BigEndianNbtSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function readIntArray() : array{
if($len < 0){
throw new NbtDataException("Array length cannot be less than zero ($len < 0)");
}
/** @var array<int>|false $unpacked */
$unpacked = unpack("N*", $this->buffer->get($len * 4));
assert($unpacked !== false, "The formatting string is valid, and we gave a multiple of 4 bytes");
return array_values($unpacked);
Expand Down
1 change: 1 addition & 0 deletions src/LittleEndianNbtSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function readIntArray() : array{
if($len < 0){
throw new NbtDataException("Array length cannot be less than zero ($len < 0)");
}
/** @var array<int>|false $unpacked */
$unpacked = unpack("V*", $this->buffer->get($len * 4));
assert($unpacked !== false, "The formatting string is valid, and we gave a multiple of 4 bytes");
return array_values($unpacked);
Expand Down
1 change: 1 addition & 0 deletions src/NbtStreamReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function readString() : string;

/**
* @return int[]
* @phpstan-return list<int>
* @throws BinaryDataException
*/
public function readIntArray() : array;
Expand Down
1 change: 1 addition & 0 deletions src/NbtStreamWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function writeString(string $v) : void;

/**
* @param int[] $array
* @phpstan-param list<int> $array
*/
public function writeIntArray(array $array) : void;
}
10 changes: 8 additions & 2 deletions src/tag/IntArrayTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@
use pocketmine\nbt\NBT;
use pocketmine\nbt\NbtStreamReader;
use pocketmine\nbt\NbtStreamWriter;
use function array_values;
use function assert;
use function func_num_args;
use function implode;
use function is_int;

final class IntArrayTag extends ImmutableTag{
/** @var int[] */
/**
* @var int[]
* @phpstan-var list<int>
*/
private $value;

/**
* @param int[] $value
* @phpstan-param list<int> $value
*/
public function __construct(array $value){
self::restrictArgCount(__METHOD__, func_num_args(), 1);
Expand All @@ -50,7 +55,7 @@ public function __construct(array $value){
return true;
})());

$this->value = $value;
$this->value = array_values($value);

Check failure on line 58 in src/tag/IntArrayTag.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Parameter #1 $array (list<int>) of array_values is already a list, call has no effect.

Check failure on line 58 in src/tag/IntArrayTag.php

View workflow job for this annotation

GitHub Actions / PHP 8.0

Parameter #1 $array (list<int>) of array_values is already a list, call has no effect.

Check failure on line 58 in src/tag/IntArrayTag.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Parameter #1 $array (list<int>) of array_values is already a list, call has no effect.

Check failure on line 58 in src/tag/IntArrayTag.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Parameter #1 $array (list<int>) of array_values is already a list, call has no effect.

Check failure on line 58 in src/tag/IntArrayTag.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Parameter #1 $array (list<int>) of array_values is already a list, call has no effect.
}

protected function getTypeName() : string{
Expand All @@ -75,6 +80,7 @@ protected function stringifyValue(int $indentation) : string{

/**
* @return int[]
* @phpstan-return list<int>
*/
public function getValue() : array{
return $this->value;
Expand Down
5 changes: 3 additions & 2 deletions src/tag/ListTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ public function __construct(array $value = [], int $tagType = NBT::TAG_End){

/**
* @return Tag[]
* @phpstan-return list<Tag>
*/
public function getValue() : array{
$value = [];
foreach($this->value as $k => $v){
$value[$k] = $v;
foreach($this->value as $v){
$value[] = $v;
}

return $value;
Expand Down

0 comments on commit 8cb4567

Please sign in to comment.