Format console output

This commit is contained in:
Oliver Davies 2019-02-14 12:21:13 +00:00
parent aa3e6960a3
commit ce3ce1e971
3 changed files with 74 additions and 3 deletions

View file

@ -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());
});
}
/**

View file

@ -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;
}
}

View file

@ -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();