From 7399e6944e89ef5e50a912683de2a725c4e09381 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 6 Aug 2020 13:46:08 +0100 Subject: [PATCH] Consistent fluency for block property setters --- src/block/Banner.php | 4 +++- src/block/Bed.php | 4 +++- src/block/FlowerPot.php | 4 +++- src/block/ItemFrame.php | 12 +++++++++--- src/block/NetherPortal.php | 4 +++- src/block/Note.php | 4 +++- src/block/RedstoneComparator.php | 12 +++++++++--- src/block/Sign.php | 4 +++- 8 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/block/Banner.php b/src/block/Banner.php index 683b90051..d160d430f 100644 --- a/src/block/Banner.php +++ b/src/block/Banner.php @@ -137,13 +137,15 @@ class Banner extends Transparent{ /** * @param Deque|BannerPattern[] $patterns * @phpstan-param Deque $patterns + * @return $this */ - public function setPatterns(Deque $patterns) : void{ + public function setPatterns(Deque $patterns) : self{ $checked = $patterns->filter(function($v) : bool{ return $v instanceof BannerPattern; }); if($checked->count() !== $patterns->count()){ throw new \TypeError("Deque must only contain " . BannerPattern::class . " objects"); } $this->patterns = $checked; + return $this; } /** diff --git a/src/block/Bed.php b/src/block/Bed.php index c3e9ad051..dec248576 100644 --- a/src/block/Bed.php +++ b/src/block/Bed.php @@ -104,8 +104,10 @@ class Bed extends Transparent{ return $this->occupied; } - public function setOccupied(bool $occupied = true) : void{ + /** @return $this */ + public function setOccupied(bool $occupied = true) : self{ $this->occupied = $occupied; + return $this; } private function getOtherHalfSide() : int{ diff --git a/src/block/FlowerPot.php b/src/block/FlowerPot.php index d547bf0b5..ce787ae02 100644 --- a/src/block/FlowerPot.php +++ b/src/block/FlowerPot.php @@ -81,13 +81,15 @@ class FlowerPot extends Flowable{ return $this->plant; } - public function setPlant(?Block $plant) : void{ + /** @return $this */ + public function setPlant(?Block $plant) : self{ if($plant === null or $plant instanceof Air){ $this->plant = null; }else{ $this->plant = clone $plant; } $this->occupied = $this->plant !== null; + return $this; } public function canAddPlant(Block $block) : bool{ diff --git a/src/block/ItemFrame.php b/src/block/ItemFrame.php index 5616cc5e2..0ab780480 100644 --- a/src/block/ItemFrame.php +++ b/src/block/ItemFrame.php @@ -91,29 +91,35 @@ class ItemFrame extends Flowable{ return $this->framedItem !== null ? clone $this->framedItem : null; } - public function setFramedItem(?Item $item) : void{ + /** @return $this */ + public function setFramedItem(?Item $item) : self{ if($item === null or $item->isNull()){ $this->framedItem = null; $this->itemRotation = 0; }else{ $this->framedItem = clone $item; } + return $this; } public function getItemRotation() : int{ return $this->itemRotation; } - public function setItemRotation(int $itemRotation) : void{ + /** @return $this */ + public function setItemRotation(int $itemRotation) : self{ $this->itemRotation = $itemRotation; + return $this; } public function getItemDropChance() : float{ return $this->itemDropChance; } - public function setItemDropChance(float $itemDropChance) : void{ + /** @return $this */ + public function setItemDropChance(float $itemDropChance) : self{ $this->itemDropChance = $itemDropChance; + return $this; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ diff --git a/src/block/NetherPortal.php b/src/block/NetherPortal.php index 0eb9efc05..8af227b53 100644 --- a/src/block/NetherPortal.php +++ b/src/block/NetherPortal.php @@ -54,12 +54,14 @@ class NetherPortal extends Transparent{ /** * @throws \InvalidArgumentException + * @return $this */ - public function setAxis(int $axis) : void{ + public function setAxis(int $axis) : self{ if($axis !== Facing::AXIS_X and $axis !== Facing::AXIS_Z){ throw new \InvalidArgumentException("Invalid axis"); } $this->axis = $axis; + return $this; } public function getLightLevel() : int{ diff --git a/src/block/Note.php b/src/block/Note.php index 3e027c220..846a4dfe5 100644 --- a/src/block/Note.php +++ b/src/block/Note.php @@ -62,11 +62,13 @@ class Note extends Opaque{ return $this->pitch; } - public function setPitch(int $pitch) : void{ + /** @return $this */ + public function setPitch(int $pitch) : self{ if($pitch < self::MIN_PITCH or $pitch > self::MAX_PITCH){ throw new \InvalidArgumentException("Pitch must be in range " . self::MIN_PITCH . " - " . self::MAX_PITCH); } $this->pitch = $pitch; + return $this; } //TODO diff --git a/src/block/RedstoneComparator.php b/src/block/RedstoneComparator.php index cd7c0ebdf..f640a7c58 100644 --- a/src/block/RedstoneComparator.php +++ b/src/block/RedstoneComparator.php @@ -90,24 +90,30 @@ class RedstoneComparator extends Flowable{ return $this->isSubtractMode; } - public function setSubtractMode(bool $isSubtractMode) : void{ + /** @return $this */ + public function setSubtractMode(bool $isSubtractMode) : self{ $this->isSubtractMode = $isSubtractMode; + return $this; } public function isPowered() : bool{ return $this->powered; } - public function setPowered(bool $powered) : void{ + /** @return $this */ + public function setPowered(bool $powered) : self{ $this->powered = $powered; + return $this; } public function getSignalStrength() : int{ return $this->signalStrength; } - public function setSignalStrength(int $signalStrength) : void{ + /** @return $this */ + public function setSignalStrength(int $signalStrength) : self{ $this->signalStrength = $signalStrength; + return $this; } /** diff --git a/src/block/Sign.php b/src/block/Sign.php index b14203b67..45640e968 100644 --- a/src/block/Sign.php +++ b/src/block/Sign.php @@ -140,8 +140,10 @@ class Sign extends Transparent{ return $this->text; } - public function setText(SignText $text) : void{ + /** @return $this */ + public function setText(SignText $text) : self{ $this->text = $text; + return $this; } /**