diff --git a/src/inventory/CallbackInventoryListener.php b/src/inventory/CallbackInventoryListener.php index 8d08c4c78..98bf9a37d 100644 --- a/src/inventory/CallbackInventoryListener.php +++ b/src/inventory/CallbackInventoryListener.php @@ -30,31 +30,20 @@ class CallbackInventoryListener implements InventoryListener{ //TODO: turn the closure signatures into type aliases when PHPStan supports them - /** - * @var \Closure|null - * @phpstan-var (\Closure(Inventory, int, Item) : void)|null - */ - private $onSlotChangeCallback; - /** - * @var \Closure|null - * @phpstan-var (\Closure(Inventory, Item[]) : void)|null - */ - private $onContentChangeCallback; - /** * @phpstan-param (\Closure(Inventory, int, Item) : void)|null $onSlotChange * @phpstan-param (\Closure(Inventory, Item[]) : void)|null $onContentChange */ - public function __construct(?\Closure $onSlotChange, ?\Closure $onContentChange){ + public function __construct( + private ?\Closure $onSlotChange, + private ?\Closure $onContentChange + ){ if($onSlotChange !== null){ Utils::validateCallableSignature(function(Inventory $inventory, int $slot, Item $oldItem) : void{}, $onSlotChange); } if($onContentChange !== null){ Utils::validateCallableSignature(function(Inventory $inventory, array $oldContents) : void{}, $onContentChange); } - - $this->onSlotChangeCallback = $onSlotChange; - $this->onContentChangeCallback = $onContentChange; } /** @@ -72,8 +61,8 @@ class CallbackInventoryListener implements InventoryListener{ } public function onSlotChange(Inventory $inventory, int $slot, Item $oldItem) : void{ - if($this->onSlotChangeCallback !== null){ - ($this->onSlotChangeCallback)($inventory, $slot, $oldItem); + if($this->onSlotChange !== null){ + ($this->onSlotChange)($inventory, $slot, $oldItem); } } @@ -81,8 +70,8 @@ class CallbackInventoryListener implements InventoryListener{ * @param Item[] $oldContents */ public function onContentChange(Inventory $inventory, array $oldContents) : void{ - if($this->onContentChangeCallback !== null){ - ($this->onContentChangeCallback)($inventory, $oldContents); + if($this->onContentChange !== null){ + ($this->onContentChange)($inventory, $oldContents); } } } diff --git a/src/inventory/CreativeInventory.php b/src/inventory/CreativeInventory.php index e71966f44..610f02392 100644 --- a/src/inventory/CreativeInventory.php +++ b/src/inventory/CreativeInventory.php @@ -34,7 +34,7 @@ final class CreativeInventory{ use SingletonTrait; /** @var Item[] */ - private $creative = []; + private array $creative = []; private function __construct(){ $creativeItems = json_decode(file_get_contents(Path::join(\pocketmine\BEDROCK_DATA_PATH, "creativeitems.json")), true); diff --git a/src/inventory/PlayerOffHandInventory.php b/src/inventory/PlayerOffHandInventory.php index 1db8d63e0..bbcfd37d7 100644 --- a/src/inventory/PlayerOffHandInventory.php +++ b/src/inventory/PlayerOffHandInventory.php @@ -26,8 +26,7 @@ namespace pocketmine\inventory; use pocketmine\entity\Human; final class PlayerOffHandInventory extends SimpleInventory{ - /** @var Human */ - private $holder; + private Human $holder; public function __construct(Human $player){ $this->holder = $player;