refactor: simplify the "is host" logic

This commit is contained in:
Oliver Davies 2022-01-13 21:41:27 +00:00
parent 154bf97964
commit ce8b3466ff

View file

@ -11,18 +11,18 @@ use Tightenco\Collect\Support\Collection;
final class FakeEventRepository implements EventRepository final class FakeEventRepository implements EventRepository
{ {
private static array $rsvps = [ private static array $rsvps = [
['name' => 'Oliver Davies.', 'response' => RsvpResponse::RESPONSE_YES, 'member' => ['event_context' => ['host' => true]]], ['name' => 'Oliver Davies.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => true],
['name' => 'matthew s.', 'response' => RsvpResponse::RESPONSE_YES, 'member' => ['event_context' => ['host' => false]]], ['name' => 'matthew s.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => false],
['name' => 'Michael P.', 'response' => RsvpResponse::RESPONSE_YES, 'member' => ['event_context' => ['host' => false]]], ['name' => 'Michael P.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => false],
['name' => 'Kathryn "Kat" R.', 'response' => RsvpResponse::RESPONSE_YES, 'member' => ['event_context' => ['host' => false]]], ['name' => 'Kathryn "Kat" R.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => false],
['name' => 'Did not attend', 'response' => RsvpResponse::RESPONSE_NO, 'member' => ['event_context' => ['host' => false]]], ['name' => 'Did not attend', 'response' => RsvpResponse::RESPONSE_NO, 'is_host' => false],
]; ];
public function getConfirmedAttendees(): Collection { public function getConfirmedAttendees(): Collection {
return Collection::make(self::$rsvps) return Collection::make(self::$rsvps)
->filter(fn (array $attendee): bool => $attendee['response'] ->filter(fn (array $attendee): bool => $attendee['response']
== RsvpResponse::RESPONSE_YES) == RsvpResponse::RESPONSE_YES)
->filter(fn (array $attendee): bool => !$attendee['member']['event_context']['host']) ->filter(fn (array $attendee): bool => !$attendee['is_host'])
; ;
} }
} }