From 91af0ef7f8b3cc4ad86917f6236ed9653434cc64 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 10 Jan 2019 22:57:07 +0000 Subject: [PATCH] Display tweets in a table --- src/Command/FetchTweetsCommand.php | 12 +++++++++++- src/Service/TweetFetcher.php | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Command/FetchTweetsCommand.php b/src/Command/FetchTweetsCommand.php index 10cb744..0c16646 100644 --- a/src/Command/FetchTweetsCommand.php +++ b/src/Command/FetchTweetsCommand.php @@ -37,6 +37,16 @@ class FetchTweetsCommand extends Command { $io = new SymfonyStyle($input, $output); - dump($this->tweetFetcher->getTweets()); + $io->table( + ['Tweet', 'Author', 'Created', 'ID'], + $this->tweetFetcher->getTweets()->map(function (array $tweet) { + return [ + $tweet['text'], + $tweet['author'], + $tweet['created'], + $tweet['id'], + ]; + })->all() + ); } } diff --git a/src/Service/TweetFetcher.php b/src/Service/TweetFetcher.php index 57b0472..48acb3a 100644 --- a/src/Service/TweetFetcher.php +++ b/src/Service/TweetFetcher.php @@ -57,7 +57,7 @@ class TweetFetcher return collect($response->get('statuses')) ->map(function (\stdClass $tweet) { - return (object) [ + return [ 'id' => $tweet->id, 'created' => strtotime($tweet->created_at), 'text' => $tweet->text,