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
/**
* @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);
}
}
}

View File

@ -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);

View File

@ -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;