Modernize private property declarations in src/item

This commit is contained in:
Dylan K. Taylor 2022-05-17 20:59:24 +01:00
parent fb4d332d1a
commit 95ad3f16e1
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
21 changed files with 44 additions and 100 deletions

View File

@ -40,8 +40,7 @@ class Armor extends Durable{
public const TAG_CUSTOM_COLOR = "customColor"; //TAG_Int public const TAG_CUSTOM_COLOR = "customColor"; //TAG_Int
/** @var ArmorTypeInfo */ private ArmorTypeInfo $armorInfo;
private $armorInfo;
/** @var Color|null */ /** @var Color|null */
protected $customColor = null; protected $customColor = null;

View File

@ -24,19 +24,11 @@ declare(strict_types=1);
namespace pocketmine\item; namespace pocketmine\item;
class ArmorTypeInfo{ class ArmorTypeInfo{
public function __construct(
/** @var int */ private int $defensePoints,
private $defensePoints; private int $maxDurability,
/** @var int */ private int $armorSlot
private $maxDurability; ){}
/** @var int */
private $armorSlot;
public function __construct(int $defensePoints, int $maxDurability, int $armorSlot){
$this->defensePoints = $defensePoints;
$this->maxDurability = $maxDurability;
$this->armorSlot = $armorSlot;
}
public function getDefensePoints() : int{ public function getDefensePoints() : int{
return $this->defensePoints; return $this->defensePoints;

View File

@ -39,14 +39,13 @@ class Banner extends ItemBlockWallOrFloor{
public const TAG_PATTERN_COLOR = TileBanner::TAG_PATTERN_COLOR; public const TAG_PATTERN_COLOR = TileBanner::TAG_PATTERN_COLOR;
public const TAG_PATTERN_NAME = TileBanner::TAG_PATTERN_NAME; public const TAG_PATTERN_NAME = TileBanner::TAG_PATTERN_NAME;
/** @var DyeColor */ private DyeColor $color;
private $color;
/** /**
* @var BannerPatternLayer[] * @var BannerPatternLayer[]
* @phpstan-var list<BannerPatternLayer> * @phpstan-var list<BannerPatternLayer>
*/ */
private $patterns = []; private array $patterns = [];
public function __construct(ItemIdentifier $identifier, Block $floorVariant, Block $wallVariant){ public function __construct(ItemIdentifier $identifier, Block $floorVariant, Block $wallVariant){
parent::__construct($identifier, $floorVariant, $wallVariant); parent::__construct($identifier, $floorVariant, $wallVariant);

View File

@ -28,9 +28,7 @@ use pocketmine\block\utils\DyeColor;
use pocketmine\block\VanillaBlocks; use pocketmine\block\VanillaBlocks;
class Bed extends Item{ class Bed extends Item{
private DyeColor $color;
/** @var DyeColor */
private $color;
public function __construct(ItemIdentifier $identifier, string $name, DyeColor $color){ public function __construct(ItemIdentifier $identifier, string $name, DyeColor $color){
parent::__construct($identifier, $name); parent::__construct($identifier, $name);

View File

@ -26,8 +26,7 @@ namespace pocketmine\item;
use pocketmine\block\utils\TreeType; use pocketmine\block\utils\TreeType;
class Boat extends Item{ class Boat extends Item{
/** @var TreeType */ private TreeType $woodType;
private $woodType;
public function __construct(ItemIdentifier $identifier, string $name, TreeType $woodType){ public function __construct(ItemIdentifier $identifier, string $name, TreeType $woodType){
parent::__construct($identifier, $name); parent::__construct($identifier, $name);

View File

@ -32,8 +32,7 @@ abstract class Durable extends Item{
/** @var int */ /** @var int */
protected $damage = 0; protected $damage = 0;
/** @var bool */ private bool $unbreakable = false;
private $unbreakable = false;
public function getMeta() : int{ public function getMeta() : int{
return $this->damage; return $this->damage;

View File

@ -26,9 +26,7 @@ namespace pocketmine\item;
use pocketmine\block\utils\DyeColor; use pocketmine\block\utils\DyeColor;
class Dye extends Item{ class Dye extends Item{
private DyeColor $color;
/** @var DyeColor */
private $color;
public function __construct(ItemIdentifier $identifier, string $name, DyeColor $color){ public function __construct(ItemIdentifier $identifier, string $name, DyeColor $color){
parent::__construct($identifier, $name); parent::__construct($identifier, $name);

View File

@ -65,10 +65,9 @@ class Item implements \JsonSerializable{
public const TAG_DISPLAY_NAME = "Name"; public const TAG_DISPLAY_NAME = "Name";
public const TAG_DISPLAY_LORE = "Lore"; public const TAG_DISPLAY_LORE = "Lore";
/** @var ItemIdentifier */ private ItemIdentifier $identifier;
private $identifier; private CompoundTag $nbt;
/** @var CompoundTag */
private $nbt;
/** @var int */ /** @var int */
protected $count = 1; protected $count = 1;
/** @var string */ /** @var string */

View File

@ -30,8 +30,7 @@ use pocketmine\block\BlockFactory;
* Class used for Items that can be Blocks * Class used for Items that can be Blocks
*/ */
class ItemBlock extends Item{ class ItemBlock extends Item{
/** @var int */ private int $blockFullId;
private $blockFullId;
public function __construct(ItemIdentifier $identifier, Block $block){ public function __construct(ItemIdentifier $identifier, Block $block){
parent::__construct($identifier, $block->getName()); parent::__construct($identifier, $block->getName());

View File

@ -29,11 +29,8 @@ use pocketmine\math\Axis;
use pocketmine\math\Facing; use pocketmine\math\Facing;
class ItemBlockWallOrFloor extends Item{ class ItemBlockWallOrFloor extends Item{
private int $floorVariant;
/** @var int */ private int $wallVariant;
private $floorVariant;
/** @var int */
private $wallVariant;
public function __construct(ItemIdentifier $identifier, Block $floorVariant, Block $wallVariant){ public function __construct(ItemIdentifier $identifier, Block $floorVariant, Block $wallVariant){
parent::__construct($identifier, $floorVariant->getName()); parent::__construct($identifier, $floorVariant->getName());

View File

@ -55,7 +55,7 @@ class ItemFactory{
use SingletonTrait; use SingletonTrait;
/** @var Item[] */ /** @var Item[] */
private $list = []; private array $list = [];
public function __construct(){ public function __construct(){
$this->registerArmorItems(); $this->registerArmorItems();

View File

@ -24,11 +24,8 @@ declare(strict_types=1);
namespace pocketmine\item; namespace pocketmine\item;
final class ItemIdentifier{ final class ItemIdentifier{
private int $id;
/** @var int */ private int $meta;
private $id;
/** @var int */
private $meta;
public function __construct(int $id, int $meta){ public function __construct(int $id, int $meta){
if($id < -0x8000 || $id > 0x7fff){ //signed short range if($id < -0x8000 || $id > 0x7fff){ //signed short range

View File

@ -50,9 +50,6 @@ use function trim;
final class LegacyStringToItemParser{ final class LegacyStringToItemParser{
use SingletonTrait; use SingletonTrait;
/** @var ItemFactory */
private $itemFactory;
private static function make() : self{ private static function make() : self{
$result = new self(ItemFactory::getInstance()); $result = new self(ItemFactory::getInstance());
@ -73,11 +70,9 @@ final class LegacyStringToItemParser{
* @var int[] * @var int[]
* @phpstan-var array<string, int> * @phpstan-var array<string, int>
*/ */
private $map = []; private array $map = [];
public function __construct(ItemFactory $itemFactory){ public function __construct(private ItemFactory $itemFactory){}
$this->itemFactory = $itemFactory;
}
public function addMapping(string $alias, int $id) : void{ public function addMapping(string $alias, int $id) : void{
$this->map[$alias] = $id; $this->map[$alias] = $id;

View File

@ -31,9 +31,7 @@ use pocketmine\math\Vector3;
use pocketmine\player\Player; use pocketmine\player\Player;
class LiquidBucket extends Item{ class LiquidBucket extends Item{
private Liquid $liquid;
/** @var Liquid */
private $liquid;
public function __construct(ItemIdentifier $identifier, string $name, Liquid $liquid){ public function __construct(ItemIdentifier $identifier, string $name, Liquid $liquid){
parent::__construct($identifier, $name); parent::__construct($identifier, $name);

View File

@ -26,9 +26,9 @@ namespace pocketmine\item;
use pocketmine\block\utils\RecordType; use pocketmine\block\utils\RecordType;
class Record extends Item{ class Record extends Item{
/** @var RecordType */ private RecordType $recordType;
private $recordType;
//TODO: inconsistent parameter order
public function __construct(ItemIdentifier $identifier, RecordType $recordType, string $name){ public function __construct(ItemIdentifier $identifier, RecordType $recordType, string $name){
$this->recordType = $recordType; $this->recordType = $recordType;
parent::__construct($identifier, $name); parent::__construct($identifier, $name);

View File

@ -28,9 +28,7 @@ use pocketmine\block\utils\SkullType;
use pocketmine\block\VanillaBlocks; use pocketmine\block\VanillaBlocks;
class Skull extends Item{ class Skull extends Item{
private SkullType $skullType;
/** @var SkullType */
private $skullType;
public function __construct(ItemIdentifier $identifier, string $name, SkullType $skullType){ public function __construct(ItemIdentifier $identifier, string $name, SkullType $skullType){
parent::__construct($identifier, $name); parent::__construct($identifier, $name);

View File

@ -52,21 +52,14 @@ final class ToolTier{
); );
} }
/** @var int */ private function __construct(
private $harvestLevel; string $name,
/** @var int */ private int $harvestLevel,
private $maxDurability; private int $maxDurability,
/** @var int */ private int $baseAttackPoints,
private $baseAttackPoints; private int $baseEfficiency
/** @var int */ ){
private $baseEfficiency;
private function __construct(string $name, int $harvestLevel, int $maxDurability, int $baseAttackPoints, int $baseEfficiency){
$this->Enum___construct($name); $this->Enum___construct($name);
$this->harvestLevel = $harvestLevel;
$this->maxDurability = $maxDurability;
$this->baseAttackPoints = $baseAttackPoints;
$this->baseEfficiency = $baseEfficiency;
} }
public function getHarvestLevel() : int{ public function getHarvestLevel() : int{

View File

@ -42,7 +42,7 @@ abstract class WritableBookBase extends Item{
* @var WritableBookPage[] * @var WritableBookPage[]
* @phpstan-var list<WritableBookPage> * @phpstan-var list<WritableBookPage>
*/ */
private $pages = []; private array $pages = [];
public function __construct(ItemIdentifier $identifier, string $name){ public function __construct(ItemIdentifier $identifier, string $name){
parent::__construct($identifier, $name); parent::__construct($identifier, $name);

View File

@ -32,10 +32,8 @@ class WritableBookPage{
public const PAGE_LENGTH_HARD_LIMIT_BYTES = Limits::INT16_MAX; public const PAGE_LENGTH_HARD_LIMIT_BYTES = Limits::INT16_MAX;
public const PHOTO_NAME_LENGTH_HARD_LIMIT_BYTES = Limits::INT16_MAX; public const PHOTO_NAME_LENGTH_HARD_LIMIT_BYTES = Limits::INT16_MAX;
/** @var string */ private string $text;
private $text; private string $photoName;
/** @var string */
private $photoName;
/** /**
* @throws \InvalidArgumentException * @throws \InvalidArgumentException

View File

@ -40,12 +40,9 @@ class WrittenBook extends WritableBookBase{
public const TAG_AUTHOR = "author"; //TAG_String public const TAG_AUTHOR = "author"; //TAG_String
public const TAG_TITLE = "title"; //TAG_String public const TAG_TITLE = "title"; //TAG_String
/** @var int */ private int $generation = self::GENERATION_ORIGINAL;
private $generation = self::GENERATION_ORIGINAL; private string $author = "";
/** @var string */ private string $title = "";
private $author = "";
/** @var string */
private $title = "";
public function getMaxStackSize() : int{ public function getMaxStackSize() : int{
return 16; return 16;

View File

@ -29,21 +29,10 @@ namespace pocketmine\item\enchantment;
* Note: This class is assumed to be immutable. Consider this before making alterations. * Note: This class is assumed to be immutable. Consider this before making alterations.
*/ */
final class EnchantmentInstance{ final class EnchantmentInstance{
/** @var Enchantment */ public function __construct(
private $enchantment; private Enchantment $enchantment,
/** @var int */ private int $level = 1
private $level; ){}
/**
* EnchantmentInstance constructor.
*
* @param Enchantment $enchantment Enchantment type
* @param int $level Level of enchantment
*/
public function __construct(Enchantment $enchantment, int $level = 1){
$this->enchantment = $enchantment;
$this->level = $level;
}
/** /**
* Returns the type of this enchantment. * Returns the type of this enchantment.