From 43ae1a5cb4e746808ab6cda3bc7ed174f17bdd59 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Mon, 29 Jun 2020 20:54:51 +0100 Subject: [PATCH] Block: make getAllSides() and getHorizontalSides() return generators --- src/block/Block.php | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/block/Block.php b/src/block/Block.php index f4a8e8054..bed56f3d2 100644 --- a/src/block/Block.php +++ b/src/block/Block.php @@ -43,7 +43,6 @@ use pocketmine\player\Player; use pocketmine\world\BlockTransaction; use pocketmine\world\Position; use pocketmine\world\World; -use function array_merge; use function assert; use function count; use function dechex; @@ -489,30 +488,26 @@ class Block{ /** * Returns the 4 blocks on the horizontal axes around the block (north, south, east, west) * - * @return Block[] + * @return Block[]|\Generator + * @phpstan-return \Generator */ - public function getHorizontalSides() : array{ - return [ - $this->getSide(Facing::NORTH), - $this->getSide(Facing::SOUTH), - $this->getSide(Facing::WEST), - $this->getSide(Facing::EAST) - ]; + public function getHorizontalSides() : \Generator{ + yield $this->getSide(Facing::NORTH); + yield $this->getSide(Facing::SOUTH); + yield $this->getSide(Facing::WEST); + yield $this->getSide(Facing::EAST); } /** * Returns the six blocks around this block. * - * @return Block[] + * @return Block[]|\Generator + * @phpstan-return \Generator */ - public function getAllSides() : array{ - return array_merge( - [ - $this->getSide(Facing::DOWN), - $this->getSide(Facing::UP) - ], - $this->getHorizontalSides() - ); + public function getAllSides() : \Generator{ + yield $this->getSide(Facing::DOWN); + yield $this->getSide(Facing::UP); + yield from $this->getHorizontalSides(); } /**