Refactor
This commit is contained in:
parent
202552cdfe
commit
6fe88456ca
1 changed files with 7 additions and 3 deletions
|
@ -19,6 +19,10 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable {
|
||||||
return count($this->guests);
|
return count($this->guests);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function first(): ?Guest {
|
||||||
|
return array_values($this->guests)[0];
|
||||||
|
}
|
||||||
|
|
||||||
public function getIterator(): \Traversable {
|
public function getIterator(): \Traversable {
|
||||||
return new \ArrayIterator($this->guests);
|
return new \ArrayIterator($this->guests);
|
||||||
}
|
}
|
||||||
|
@ -26,12 +30,12 @@ final class Guests implements \Countable, \IteratorAggregate, \Stringable {
|
||||||
public function __toString(): string {
|
public function __toString(): string {
|
||||||
// TODO: allow for more than two guests.
|
// TODO: allow for more than two guests.
|
||||||
if ($this->count() === 2) {
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue