Modernize property type declarations

This commit is contained in:
Dylan K. Taylor
2022-06-04 18:16:32 +01:00
parent 23695fb900
commit 083a35f970
114 changed files with 431 additions and 863 deletions

View File

@@ -32,11 +32,9 @@ class ArmorInventory extends SimpleInventory{
public const SLOT_LEGS = 2;
public const SLOT_FEET = 3;
/** @var Living */
protected $holder;
public function __construct(Living $holder){
$this->holder = $holder;
public function __construct(
protected Living $holder
){
parent::__construct(4);
}

View File

@@ -37,15 +37,14 @@ use function spl_object_id;
* This class provides everything needed to implement an inventory, minus the underlying storage system.
*/
abstract class BaseInventory implements Inventory{
/** @var int */
protected $maxStackSize = Inventory::MAX_STACK;
protected int $maxStackSize = Inventory::MAX_STACK;
/** @var Player[] */
protected $viewers = [];
protected array $viewers = [];
/**
* @var InventoryListener[]|ObjectSet
* @phpstan-var ObjectSet<InventoryListener>
*/
protected $listeners;
protected ObjectSet $listeners;
public function __construct(){
$this->listeners = new ObjectSet();

View File

@@ -26,18 +26,13 @@ namespace pocketmine\inventory;
use pocketmine\player\Player;
class PlayerCursorInventory extends SimpleInventory implements TemporaryInventory{
/** @var Player */
protected $holder;
public function __construct(Player $holder){
$this->holder = $holder;
public function __construct(
protected Player $holder
){
parent::__construct(1);
}
/**
* @return Player
*/
public function getHolder(){
public function getHolder() : Player{
return $this->holder;
}
}

View File

@@ -30,17 +30,14 @@ use pocketmine\utils\ObjectSet;
class PlayerInventory extends SimpleInventory{
/** @var Human */
protected $holder;
/** @var int */
protected $itemInHandIndex = 0;
protected Human $holder;
protected int $itemInHandIndex = 0;
/**
* @var \Closure[]|ObjectSet
* @phpstan-var ObjectSet<\Closure(int $oldIndex) : void>
*/
protected $heldItemIndexChangeListeners;
protected ObjectSet $heldItemIndexChangeListeners;
public function __construct(Human $player){
$this->holder = $player;
@@ -123,10 +120,7 @@ class PlayerInventory extends SimpleInventory{
return 9;
}
/**
* @return Human|Player
*/
public function getHolder(){
public function getHolder() : Human{
return $this->holder;
}
}

View File

@@ -48,15 +48,13 @@ use function intdiv;
* results, with no remainder. Any leftovers are expected to be emitted back to the crafting grid.
*/
class CraftingTransaction extends InventoryTransaction{
/** @var CraftingRecipe|null */
protected $recipe;
/** @var int|null */
protected $repetitions;
protected ?CraftingRecipe $recipe;
protected ?int $repetitions;
/** @var Item[] */
protected $inputs = [];
protected array $inputs = [];
/** @var Item[] */
protected $outputs = [];
protected array $outputs = [];
private CraftingManager $craftingManager;

View File

@@ -55,22 +55,21 @@ use function spl_object_id;
* @see InventoryAction
*/
class InventoryTransaction{
/** @var bool */
protected $hasExecuted = false;
/** @var Player */
protected $source;
protected bool $hasExecuted = false;
/** @var Inventory[] */
protected $inventories = [];
protected array $inventories = [];
/** @var InventoryAction[] */
protected $actions = [];
protected array $actions = [];
/**
* @param InventoryAction[] $actions
*/
public function __construct(Player $source, array $actions = []){
$this->source = $source;
public function __construct(
protected Player $source,
array $actions = []
){
foreach($actions as $action){
$this->addAction($action);
}

View File

@@ -32,15 +32,10 @@ use pocketmine\player\Player;
* Represents an action involving a change that applies in some way to an inventory or other item-source.
*/
abstract class InventoryAction{
/** @var Item */
protected $sourceItem;
/** @var Item */
protected $targetItem;
public function __construct(Item $sourceItem, Item $targetItem){
$this->sourceItem = $sourceItem;
$this->targetItem = $targetItem;
}
public function __construct(
protected Item $sourceItem,
protected Item $targetItem
){}
/**
* Returns the item that was present before the action took place.

View File

@@ -33,15 +33,13 @@ use pocketmine\player\Player;
* Represents an action causing a change in an inventory slot.
*/
class SlotChangeAction extends InventoryAction{
/** @var Inventory */
protected $inventory;
private int $inventorySlot;
public function __construct(Inventory $inventory, int $inventorySlot, Item $sourceItem, Item $targetItem){
public function __construct(
protected Inventory $inventory,
private int $inventorySlot,
Item $sourceItem,
Item $targetItem
){
parent::__construct($sourceItem, $targetItem);
$this->inventory = $inventory;
$this->inventorySlot = $inventorySlot;
}
/**