Consistent fluency for block property setters

This commit is contained in:
Dylan K. Taylor 2020-08-06 13:46:08 +01:00
parent 3d4470ed8d
commit 7399e6944e
8 changed files with 36 additions and 12 deletions

View File

@ -137,13 +137,15 @@ class Banner extends Transparent{
/** /**
* @param Deque|BannerPattern[] $patterns * @param Deque|BannerPattern[] $patterns
* @phpstan-param Deque<BannerPattern> $patterns * @phpstan-param Deque<BannerPattern> $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; }); $checked = $patterns->filter(function($v) : bool{ return $v instanceof BannerPattern; });
if($checked->count() !== $patterns->count()){ if($checked->count() !== $patterns->count()){
throw new \TypeError("Deque must only contain " . BannerPattern::class . " objects"); throw new \TypeError("Deque must only contain " . BannerPattern::class . " objects");
} }
$this->patterns = $checked; $this->patterns = $checked;
return $this;
} }
/** /**

View File

@ -104,8 +104,10 @@ class Bed extends Transparent{
return $this->occupied; return $this->occupied;
} }
public function setOccupied(bool $occupied = true) : void{ /** @return $this */
public function setOccupied(bool $occupied = true) : self{
$this->occupied = $occupied; $this->occupied = $occupied;
return $this;
} }
private function getOtherHalfSide() : int{ private function getOtherHalfSide() : int{

View File

@ -81,13 +81,15 @@ class FlowerPot extends Flowable{
return $this->plant; return $this->plant;
} }
public function setPlant(?Block $plant) : void{ /** @return $this */
public function setPlant(?Block $plant) : self{
if($plant === null or $plant instanceof Air){ if($plant === null or $plant instanceof Air){
$this->plant = null; $this->plant = null;
}else{ }else{
$this->plant = clone $plant; $this->plant = clone $plant;
} }
$this->occupied = $this->plant !== null; $this->occupied = $this->plant !== null;
return $this;
} }
public function canAddPlant(Block $block) : bool{ public function canAddPlant(Block $block) : bool{

View File

@ -91,29 +91,35 @@ class ItemFrame extends Flowable{
return $this->framedItem !== null ? clone $this->framedItem : null; 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()){ if($item === null or $item->isNull()){
$this->framedItem = null; $this->framedItem = null;
$this->itemRotation = 0; $this->itemRotation = 0;
}else{ }else{
$this->framedItem = clone $item; $this->framedItem = clone $item;
} }
return $this;
} }
public function getItemRotation() : int{ public function getItemRotation() : int{
return $this->itemRotation; return $this->itemRotation;
} }
public function setItemRotation(int $itemRotation) : void{ /** @return $this */
public function setItemRotation(int $itemRotation) : self{
$this->itemRotation = $itemRotation; $this->itemRotation = $itemRotation;
return $this;
} }
public function getItemDropChance() : float{ public function getItemDropChance() : float{
return $this->itemDropChance; return $this->itemDropChance;
} }
public function setItemDropChance(float $itemDropChance) : void{ /** @return $this */
public function setItemDropChance(float $itemDropChance) : self{
$this->itemDropChance = $itemDropChance; $this->itemDropChance = $itemDropChance;
return $this;
} }
public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{

View File

@ -54,12 +54,14 @@ class NetherPortal extends Transparent{
/** /**
* @throws \InvalidArgumentException * @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){ if($axis !== Facing::AXIS_X and $axis !== Facing::AXIS_Z){
throw new \InvalidArgumentException("Invalid axis"); throw new \InvalidArgumentException("Invalid axis");
} }
$this->axis = $axis; $this->axis = $axis;
return $this;
} }
public function getLightLevel() : int{ public function getLightLevel() : int{

View File

@ -62,11 +62,13 @@ class Note extends Opaque{
return $this->pitch; 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){ if($pitch < self::MIN_PITCH or $pitch > self::MAX_PITCH){
throw new \InvalidArgumentException("Pitch must be in range " . self::MIN_PITCH . " - " . self::MAX_PITCH); throw new \InvalidArgumentException("Pitch must be in range " . self::MIN_PITCH . " - " . self::MAX_PITCH);
} }
$this->pitch = $pitch; $this->pitch = $pitch;
return $this;
} }
//TODO //TODO

View File

@ -90,24 +90,30 @@ class RedstoneComparator extends Flowable{
return $this->isSubtractMode; return $this->isSubtractMode;
} }
public function setSubtractMode(bool $isSubtractMode) : void{ /** @return $this */
public function setSubtractMode(bool $isSubtractMode) : self{
$this->isSubtractMode = $isSubtractMode; $this->isSubtractMode = $isSubtractMode;
return $this;
} }
public function isPowered() : bool{ public function isPowered() : bool{
return $this->powered; return $this->powered;
} }
public function setPowered(bool $powered) : void{ /** @return $this */
public function setPowered(bool $powered) : self{
$this->powered = $powered; $this->powered = $powered;
return $this;
} }
public function getSignalStrength() : int{ public function getSignalStrength() : int{
return $this->signalStrength; return $this->signalStrength;
} }
public function setSignalStrength(int $signalStrength) : void{ /** @return $this */
public function setSignalStrength(int $signalStrength) : self{
$this->signalStrength = $signalStrength; $this->signalStrength = $signalStrength;
return $this;
} }
/** /**

View File

@ -140,8 +140,10 @@ class Sign extends Transparent{
return $this->text; return $this->text;
} }
public function setText(SignText $text) : void{ /** @return $this */
public function setText(SignText $text) : self{
$this->text = $text; $this->text = $text;
return $this;
} }
/** /**