Skip to content

Commit

Permalink
Update PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Jan 3, 2025
1 parent d77b884 commit d31054e
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 10 deletions.
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"ramsey/uuid": "^4.1"
},
"require-dev": {
"phpstan/phpstan": "1.11.9",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpstan/phpstan-strict-rules": "^1.0.0",
"phpunit/phpunit": "^9.5 || ^10.0"
"phpstan/phpstan": "2.1.0",
"phpstan/phpstan-phpunit": "^2.0.0",
"phpstan/phpstan-strict-rules": "^2.0.0",
"phpunit/phpunit": "^9.5 || ^10.0 || ^11.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ parameters:
paths:
- src
- tests/phpunit
- tests/phpstan/DummyPacketHandler.php
stubFiles:
- tests/phpstan/stubs/JsonMapper.stub
reportUnmatchedIgnoredErrors: false #no other way to silence platform-specific non-warnings
2 changes: 1 addition & 1 deletion src/serializer/PacketSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private function putSkinImage(SkinImage $image) : void{
/**
* @return int[]
* @phpstan-return array{0: int, 1: int, 2: int}
* @throws PacketDecodeException
* @throws BinaryDataException
*/
private function getItemStackHeader() : array{
$id = $this->getVarInt();
Expand Down
2 changes: 1 addition & 1 deletion src/types/CacheableNbt.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @phpstan-template TTagType of Tag
*/
final class CacheableNbt{
private ?string $encodedNbt;
private ?string $encodedNbt = null;

/**
* @phpstan-param TTagType $nbtRoot
Expand Down
4 changes: 3 additions & 1 deletion src/types/MapImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ public static function decode(BinaryStream $input, int $height, int $width) : se
$pixels = [];

for($y = 0; $y < $height; ++$y){
$row = [];
for($x = 0; $x < $width; ++$x){
$pixels[$y][$x] = Color::fromRGBA(Binary::flipIntEndianness($input->getUnsignedVarInt()));
$row[] = Color::fromRGBA(Binary::flipIntEndianness($input->getUnsignedVarInt()));
}
$pixels[] = $row;
}

return new self($pixels);
Expand Down
33 changes: 33 additions & 0 deletions tests/phpstan/DummyPacketHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/

declare(strict_types=1);

namespace pocketmine\network\mcpe\protocol;

/**
* Ensures that PHPStan analyzes PacketHandlerDefaultImplTrait
* under a normal usage.
* TODO: Why don't we just have a PacketHandler class in protocol directly???
*/
final class DummyPacketHandler implements PacketHandlerInterface{
use PacketHandlerDefaultImplTrait;
}
26 changes: 23 additions & 3 deletions tests/phpstan/configs/phpstan-bugs.neon
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
parameters:
ignoreErrors:
-
message: "#^Casting to string something that's already string\\.$#"
message: '#^Casting to string something that''s already string\.$#'
identifier: cast.useless
count: 1
path: ../../../src/AvailableCommandsPacket.php

-
message: "#^Parameter \\#3 \\$packets of static method pocketmine\\\\network\\\\mcpe\\\\protocol\\\\serializer\\\\PacketBatch\\:\\:encodePackets\\(\\) expects array\\<int, pocketmine\\\\network\\\\mcpe\\\\protocol\\\\Packet\\>, array\\<int\\|string, pocketmine\\\\network\\\\mcpe\\\\protocol\\\\Packet\\> given\\.$#"
message: '#^Expression "\(function \(\\pocketmine\\network\\mcpe\\protocol\\types\\command\\ChainedSubCommandData \.\.\.\$chainedSubCommandData\)\: void \{…" on a separate line does not do anything\.$#'
identifier: expr.resultUnused
count: 1
path: ../../../src/serializer/PacketBatch.php
path: ../../../src/types/command/CommandData.php

-
message: '#^Expression "\(function \(\\pocketmine\\network\\mcpe\\protocol\\types\\command\\CommandOverload \.\.\.\$overloads\)\: void \{…" on a separate line does not do anything\.$#'
identifier: expr.resultUnused
count: 1
path: ../../../src/types/command/CommandData.php

-
message: '#^Expression "\(static function \(int \.\.\.\$_\)\: void \{…" on a separate line does not do anything\.$#'
identifier: expr.resultUnused
count: 1
path: ../../../src/types/command/CommandEnumConstraint.php

-
message: '#^Expression "\(function \(\\pocketmine\\network\\mcpe\\protocol\\types\\command\\CommandParameter \.\.\.\$parameters\)\: void \{…" on a separate line does not do anything\.$#'
identifier: expr.resultUnused
count: 1
path: ../../../src/types/command/CommandOverload.php

0 comments on commit d31054e

Please sign in to comment.