From 8ec5b621c11f982cfde586dd323a45f0c9daa39b Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 12 Jun 2025 02:10:09 +0100 Subject: [PATCH] Refactor --- modules/opd_daily_emails/src/DailyEmails.php | 18 +++++------ modules/opd_podcast/src/Guests.php | 32 ++++++++++---------- modules/opd_presentations/src/Events.php | 20 ++++++------ 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/modules/opd_daily_emails/src/DailyEmails.php b/modules/opd_daily_emails/src/DailyEmails.php index f2bde6c8d..232b7f043 100644 --- a/modules/opd_daily_emails/src/DailyEmails.php +++ b/modules/opd_daily_emails/src/DailyEmails.php @@ -9,15 +9,6 @@ use Webmozart\Assert\Assert; final class DailyEmails implements \Countable { - /** - * @param array $emails - */ - private function __construct( - private array $emails, - ) { - Assert::allIsInstanceOf($emails, NodeInterface::class); - } - public function count(): int { return count($this->emails); } @@ -30,4 +21,13 @@ final class DailyEmails implements \Countable { return new self($emails); } + /** + * @param array $emails + */ + private function __construct( + private array $emails, + ) { + Assert::allIsInstanceOf($emails, NodeInterface::class); + } + } diff --git a/modules/opd_podcast/src/Guests.php b/modules/opd_podcast/src/Guests.php index 4f6bd29a3..75bba7295 100644 --- a/modules/opd_podcast/src/Guests.php +++ b/modules/opd_podcast/src/Guests.php @@ -12,11 +12,15 @@ use Webmozart\Assert\Assert; */ final class Guests implements \Countable, \IteratorAggregate, \Stringable { - /** - * @param Guest[] $guests - */ - private function __construct(private array $guests) { - Assert::allIsInstanceOf($guests, Guest::class); + public function __toString(): string { + // TODO: allow for more than two guests. + if ($this->count() === 2) { + assert($this->first() instanceof Guest); + + return sprintf('%s %s %s', $this->first()->getName(), t('and'), $this->get(1)->getName()); + } + + return strval($this->first()->getName()); } public function count(): int { @@ -31,17 +35,6 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable { return new \ArrayIterator($this->guests); } - public function __toString(): string { - // TODO: allow for more than two guests. - if ($this->count() === 2) { - assert($this->first() instanceof Guest); - - return sprintf('%s %s %s', $this->first()->getName(), t('and'), $this->get(1)->getName()); - } - - return strval($this->first()->getName()); - } - /** * @param Guest[] $guests */ @@ -49,6 +42,13 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable { return new self($guests); } + /** + * @param Guest[] $guests + */ + private function __construct(private array $guests) { + Assert::allIsInstanceOf($guests, Guest::class); + } + private function get(int $offset): ?Guest { return $this->guests[$offset]; } diff --git a/modules/opd_presentations/src/Events.php b/modules/opd_presentations/src/Events.php index f79049686..fa206e2ed 100644 --- a/modules/opd_presentations/src/Events.php +++ b/modules/opd_presentations/src/Events.php @@ -12,13 +12,6 @@ use Webmozart\Assert\Assert; */ readonly final class Events implements \IteratorAggregate { - /** - * @param Event[] $events - */ - private function __construct(private array $events) { - Assert::allIsInstanceOf($events, Event::class); - } - public function filter(\Closure $callback): self { return new self(array_filter( array: $this->events, @@ -34,11 +27,18 @@ readonly final class Events implements \IteratorAggregate { return new \ArrayIterator($this->events); } - /** - * @param Event[] $events - */ + /** + * @param Event[] $events + */ public static function fromEvents(array $events): self { return new self($events); } + /** + * @param Event[] $events + */ + private function __construct(private array $events) { + Assert::allIsInstanceOf($events, Event::class); + } + }