Refactor
This commit is contained in:
parent
c84e6ed25c
commit
8ec5b621c1
3 changed files with 35 additions and 35 deletions
|
@ -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];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue