Modernize private property declarations in src/inventory

This commit is contained in:
Dylan K. Taylor 2022-05-17 20:49:12 +01:00
parent 221c6b8570
commit a06b9294df
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 10 additions and 22 deletions

View File

@ -30,31 +30,20 @@ class CallbackInventoryListener implements InventoryListener{
//TODO: turn the closure signatures into type aliases when PHPStan supports them //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, int, Item) : void)|null $onSlotChange
* @phpstan-param (\Closure(Inventory, Item[]) : void)|null $onContentChange * @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){ if($onSlotChange !== null){
Utils::validateCallableSignature(function(Inventory $inventory, int $slot, Item $oldItem) : void{}, $onSlotChange); Utils::validateCallableSignature(function(Inventory $inventory, int $slot, Item $oldItem) : void{}, $onSlotChange);
} }
if($onContentChange !== null){ if($onContentChange !== null){
Utils::validateCallableSignature(function(Inventory $inventory, array $oldContents) : void{}, $onContentChange); 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{ public function onSlotChange(Inventory $inventory, int $slot, Item $oldItem) : void{
if($this->onSlotChangeCallback !== null){ if($this->onSlotChange !== null){
($this->onSlotChangeCallback)($inventory, $slot, $oldItem); ($this->onSlotChange)($inventory, $slot, $oldItem);
} }
} }
@ -81,8 +70,8 @@ class CallbackInventoryListener implements InventoryListener{
* @param Item[] $oldContents * @param Item[] $oldContents
*/ */
public function onContentChange(Inventory $inventory, array $oldContents) : void{ public function onContentChange(Inventory $inventory, array $oldContents) : void{
if($this->onContentChangeCallback !== null){ if($this->onContentChange !== null){
($this->onContentChangeCallback)($inventory, $oldContents); ($this->onContentChange)($inventory, $oldContents);
} }
} }
} }

View File

@ -34,7 +34,7 @@ final class CreativeInventory{
use SingletonTrait; use SingletonTrait;
/** @var Item[] */ /** @var Item[] */
private $creative = []; private array $creative = [];
private function __construct(){ private function __construct(){
$creativeItems = json_decode(file_get_contents(Path::join(\pocketmine\BEDROCK_DATA_PATH, "creativeitems.json")), true); $creativeItems = json_decode(file_get_contents(Path::join(\pocketmine\BEDROCK_DATA_PATH, "creativeitems.json")), true);

View File

@ -26,8 +26,7 @@ namespace pocketmine\inventory;
use pocketmine\entity\Human; use pocketmine\entity\Human;
final class PlayerOffHandInventory extends SimpleInventory{ final class PlayerOffHandInventory extends SimpleInventory{
/** @var Human */ private Human $holder;
private $holder;
public function __construct(Human $player){ public function __construct(Human $player){
$this->holder = $player; $this->holder = $player;