From 6fe88456cad15d98242feb398062ba192f3a64ab Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 12 Jun 2025 02:10:09 +0100 Subject: [PATCH] Refactor --- modules/opd_podcast/src/Guests.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/opd_podcast/src/Guests.php b/modules/opd_podcast/src/Guests.php index f0594c290..62ed08d0f 100644 --- a/modules/opd_podcast/src/Guests.php +++ b/modules/opd_podcast/src/Guests.php @@ -19,6 +19,10 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable { return count($this->guests); } + public function first(): ?Guest { + return array_values($this->guests)[0]; + } + public function getIterator(): \Traversable { return new \ArrayIterator($this->guests); } @@ -26,12 +30,12 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable { public function __toString(): string { // TODO: allow for more than two guests. if ($this->count() === 2) { - assert($this->get(0) instanceof Guest); + assert($this->first() instanceof Guest); - return sprintf('%s %s %s', $this->get(0)->getName(), t('and'), $this->get(1)->getName()); + return sprintf('%s %s %s', $this->first()->getName(), t('and'), $this->get(1)->getName()); } - return strval($this->get(0)->getName()); + return strval($this->first()->getName()); } /**