From ce3ce1e971df17dc6e44cb09c5352720767947a6 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 14 Feb 2019 12:21:13 +0000 Subject: [PATCH] Format console output --- src/Command/PickWinnerCommand.php | 17 ++++++++- src/Comment.php | 58 +++++++++++++++++++++++++++++-- src/Service/Picker.php | 2 ++ 3 files changed, 74 insertions(+), 3 deletions(-) diff --git a/src/Command/PickWinnerCommand.php b/src/Command/PickWinnerCommand.php index d0a33ef..d83f92c 100644 --- a/src/Command/PickWinnerCommand.php +++ b/src/Command/PickWinnerCommand.php @@ -2,6 +2,7 @@ namespace App\Command; +use App\Comment; use App\Service\Picker; use GuzzleHttp\Client; use Symfony\Component\Cache\Simple\FilesystemCache; @@ -65,16 +66,30 @@ class PickWinnerCommand extends Command { $io = new SymfonyStyle($input, $output); + $io->title('Joind.in Winner Picker!'); + $tag = $input->getArgument('tag'); $startDate = (new \DateTime($input->getArgument('start')))->format('Y-m-d'); $endDate = (new \DateTime($input->getArgument('end')))->format('Y-m-d'); + $io->comment(vsprintf('Selecting from #%s events between %s and %s.', [ + $tag, + $startDate, + $endDate, + ])); $events = collect($this->getEventData($tag, $startDate, $endDate)); $this->picker->setHosts($events); $this->picker->setComments($this->allComments($events)); - var_dump($this->picker->getWinners(1)->first()); + $this->picker->getWinners(1)->each(function (Comment $comment) use ($io) { + $io->section(vsprintf('%s (%s)', [ + $comment->getUserDisplayName(), + $comment->getTalkTitle(), + ])); + $io->text($comment->getText()); + $io->text($comment->getUri()); + }); } /** diff --git a/src/Comment.php b/src/Comment.php index 761614e..4d4d866 100644 --- a/src/Comment.php +++ b/src/Comment.php @@ -14,12 +14,26 @@ class Comment */ private $userDisplayName; + /** + * The URI for the comment. + * + * @var string + */ + private $uri; + + /** + * The title of the talk that was commented on. + * + * @var string + */ + private $talkTitle; + /** * Set the comment text. * * @param string $text */ - public function setText(string $text) + public function setText(string $text): void { $this->text = $text; } @@ -29,11 +43,31 @@ class Comment * * @param string $name */ - public function setUserDisplayName(string $name) + public function setUserDisplayName(string $name): void { $this->userDisplayName = $name; } + /** + * Set the URI for the comment. + * + * @param string $uri + */ + public function setUri(string $uri): void + { + $this->uri = $uri; + } + + /** + * Set the talk title. + * + * @param string $talkTitle + */ + public function setTalkTitle(string $talkTitle): void + { + $this->talkTitle = $talkTitle; + } + /** * @return string */ @@ -49,4 +83,24 @@ class Comment { return $this->userDisplayName; } + + /** + * Get the URI for the comment. + * + * @return string + */ + public function getUri(): string + { + return $this->uri; + } + + /** + * Get the talk title. + * + * @return string + */ + public function getTalkTitle(): string + { + return $this->talkTitle; + } } diff --git a/src/Service/Picker.php b/src/Service/Picker.php index 1b7e839..d8c6482 100644 --- a/src/Service/Picker.php +++ b/src/Service/Picker.php @@ -85,6 +85,8 @@ class Picker return tap(new Comment(), function (Comment $comment) use ($original) { $comment->setText($original->comment); $comment->setUserDisplayName($original->user_display_name); + $comment->setUri($original->uri); + $comment->setTalkTitle($original->talk_title); }); }) ->values();