From ae38fbf2b969e7a403f9f7386bda967cf2edd9fd Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 13 Jan 2022 22:22:58 +0000 Subject: [PATCH] refactor: remove old code --- src/AttendeeLoader.php | 10 --- src/Collection/RsvpCollection.php | 36 ---------- src/UseCase/FindTheWinner.php | 106 ------------------------------ src/UseCase/UseCaseInterface.php | 21 ------ src/ValueObject/Event.php | 39 ----------- src/ValueObject/Result.php | 42 ------------ src/ValueObject/Winner.php | 39 ----------- 7 files changed, 293 deletions(-) delete mode 100644 src/AttendeeLoader.php delete mode 100644 src/Collection/RsvpCollection.php delete mode 100644 src/UseCase/FindTheWinner.php delete mode 100644 src/UseCase/UseCaseInterface.php delete mode 100644 src/ValueObject/Event.php delete mode 100644 src/ValueObject/Result.php delete mode 100644 src/ValueObject/Winner.php diff --git a/src/AttendeeLoader.php b/src/AttendeeLoader.php deleted file mode 100644 index f7abb4a..0000000 --- a/src/AttendeeLoader.php +++ /dev/null @@ -1,10 +0,0 @@ -items))->filter( - function (array $rsvp): bool { - return !$rsvp['member']['event_context']['host']; - } - ); - } - - public function onlyAttending(): self - { - return (new self($this->items))->filter( - function (array $rsvp): bool { - return $rsvp['response'] == self::RESPONSE_ATTENDING; - } - ); - } - - public function getNames(): self - { - return (new self($this->items))->pluck('member.name')->sort(); - } -} diff --git a/src/UseCase/FindTheWinner.php b/src/UseCase/FindTheWinner.php deleted file mode 100644 index f7990e8..0000000 --- a/src/UseCase/FindTheWinner.php +++ /dev/null @@ -1,106 +0,0 @@ -eventId = $eventId; - $this->client = $client; - $this->cache = $cache; - } - - public function __invoke(): Result - { - $eventData = $this->retrieveEventData(); - $rsvps = $this->retrieveRsvps(); - $winner = $this->pickWinner($rsvps); - - return new Result( - Winner::createFromArray($winner), - Event::createFromArray($eventData), - $rsvps - ); - } - - private function retrieveEventData(): array - { - $eventData = $this->cache->getItem(sprintf('event.%d', $this->eventId)); - - if (!$eventData->isHit()) { - $response = $this->client->request( - 'GET', - sprintf( - 'https://api.meetup.com/%s/events/%d', - 'php-south-wales', - $this->eventId - ) - ); - - $eventData->expiresAfter( - DateInterval::createFromDateString('1 hour') - ); - $return = $response->toArray(); - $this->cache->save($eventData->set($return)); - - return $return; - } else { - return $eventData->get(); - } - } - - private function retrieveRsvps(): RsvpCollection - { - $rsvps = $this->cache->getItem(sprintf('rsvps.%d', $this->eventId)); - - if (!$rsvps->isHit()) { - $response = $this->client->request( - 'GET', - sprintf( - 'https://api.meetup.com/%s/events/%d/rsvps', - 'php-south-wales', - $this->eventId - ) - ); - - $filteredRsvps = RsvpCollection::make($response->toArray()) - ->excludeEventHosts() - ->onlyAttending(); - - $rsvps->expiresAfter(DateInterval::createFromDateString('1 hour')); - $this->cache->save($rsvps->set($filteredRsvps)); - - return $filteredRsvps; - } else { - return $rsvps->get(); - } - } - - private function pickWinner(RsvpCollection $rsvps): array - { - return $rsvps->random(1)->first()['member']; - } -} diff --git a/src/UseCase/UseCaseInterface.php b/src/UseCase/UseCaseInterface.php deleted file mode 100644 index 1ceadfe..0000000 --- a/src/UseCase/UseCaseInterface.php +++ /dev/null @@ -1,21 +0,0 @@ -link, '/'); - } - - public function getName(): string - { - return $this->name; - } - - protected function __construct(array $data) - { - [ - 'name' => $name, - 'link' => $link, - ] = $data; - - $this->name = $name; - $this->link = $link; - } -} diff --git a/src/ValueObject/Result.php b/src/ValueObject/Result.php deleted file mode 100644 index c132cb5..0000000 --- a/src/ValueObject/Result.php +++ /dev/null @@ -1,42 +0,0 @@ -winner = $winner; - $this->event = $event; - $this->rsvps = $rsvps; - } - - public function getEvent(): Event - { - return $this->event; - } - - public function getRsvps(): RsvpCollection - { - return $this->rsvps; - } - - public function getWinner(): Winner - { - return $this->winner; - } -} diff --git a/src/ValueObject/Winner.php b/src/ValueObject/Winner.php deleted file mode 100644 index 7499cda..0000000 --- a/src/ValueObject/Winner.php +++ /dev/null @@ -1,39 +0,0 @@ -name; - } - - public function getPhoto(): ?string - { - return $this->photo ?? null; - } - - protected function __construct(array $data) - { - [ - 'name' => $name, - 'photo' => $photo, - ] = $data; - - $this->name = $name; - $this->photo = $photo['photo_link']; - } -}