This commit is contained in:
Oliver Davies 2025-06-12 02:10:09 +01:00
parent 202552cdfe
commit 6fe88456ca

View file

@ -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());
}
/**