Refactor
This commit is contained in:
parent
c84e6ed25c
commit
8ec5b621c1
3 changed files with 35 additions and 35 deletions
|
@ -9,15 +9,6 @@ use Webmozart\Assert\Assert;
|
|||
|
||||
final class DailyEmails implements \Countable {
|
||||
|
||||
/**
|
||||
* @param array<positive-int, NodeInterface> $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<positive-int, NodeInterface> $emails
|
||||
*/
|
||||
private function __construct(
|
||||
private array $emails,
|
||||
) {
|
||||
Assert::allIsInstanceOf($emails, NodeInterface::class);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue