refactor: add RsvpResponse

This commit is contained in:
Oliver Davies 2022-01-13 20:54:29 +00:00
parent aadb1e0176
commit 78841ad9d6
2 changed files with 18 additions and 5 deletions

11
src/RsvpResponse.php Normal file
View file

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace App;
final class RsvpResponse
{
public const RESPONSE_NO = 'no';
public const RESPONSE_YES = 'yes';
}

View file

@ -5,20 +5,22 @@ declare(strict_types=1);
namespace App\Tests; namespace App\Tests;
use App\EventRepository; use App\EventRepository;
use App\RsvpResponse;
use Tightenco\Collect\Support\Collection; use Tightenco\Collect\Support\Collection;
final class FakeEventRepository implements EventRepository final class FakeEventRepository implements EventRepository
{ {
private static array $rsvps = [ private static array $rsvps = [
['name' => 'matthew s.', 'response' => 'yes'], ['name' => 'matthew s.', 'response' => RsvpResponse::RESPONSE_YES],
['name' => 'Michael P.', 'response' => 'yes'], ['name' => 'Michael P.', 'response' => RsvpResponse::RESPONSE_YES],
['name' => 'Kathryn "Kat" R.', 'response' => 'yes'], ['name' => 'Kathryn "Kat" R.', 'response' => RsvpResponse::RESPONSE_YES],
['name' => 'Did not attend', 'response' => 'no'], ['name' => 'Did not attend', 'response' => RsvpResponse::RESPONSE_NO],
]; ];
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'] == 'yes') ->filter(fn (array $attendee): bool => $attendee['response']
== RsvpResponse::RESPONSE_YES)
; ;
} }
} }