diff --git a/src/Command/FetchTweetsCommand.php b/src/Command/FetchTweetsCommand.php index 0c16646..581705c 100644 --- a/src/Command/FetchTweetsCommand.php +++ b/src/Command/FetchTweetsCommand.php @@ -2,6 +2,7 @@ namespace App\Command; +use App\Model\Tweet; use App\Service\TweetFetcher; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -39,12 +40,12 @@ class FetchTweetsCommand extends Command $io->table( ['Tweet', 'Author', 'Created', 'ID'], - $this->tweetFetcher->getTweets()->map(function (array $tweet) { + $this->tweetFetcher->getTweets()->map(function (Tweet $tweet) { return [ - $tweet['text'], - $tweet['author'], - $tweet['created'], - $tweet['id'], + $tweet->getText(), + $tweet->getAuthor(), + $tweet->getCreated(), + $tweet->getId(), ]; })->all() ); diff --git a/src/Command/RetweetTweetsCommand.php b/src/Command/RetweetTweetsCommand.php index 8e08088..64aff45 100644 --- a/src/Command/RetweetTweetsCommand.php +++ b/src/Command/RetweetTweetsCommand.php @@ -2,6 +2,7 @@ namespace App\Command; +use App\Model\Tweet; use App\Service\Retweeter; use App\Service\TweetFetcher; use Symfony\Component\Console\Command\Command; @@ -36,7 +37,7 @@ class RetweetTweetsCommand extends Command protected function execute(InputInterface $input, OutputInterface $output) { - $this->tweetFetcher->getTweets()->each(function (array $tweet) { + $this->tweetFetcher->getTweets()->each(function (Tweet $tweet) { $this->retweeter->retweet($tweet); }); } diff --git a/src/Model/Tweet.php b/src/Model/Tweet.php index 92ebd04..4eb9f7b 100644 --- a/src/Model/Tweet.php +++ b/src/Model/Tweet.php @@ -24,6 +24,21 @@ class Tweet $this->author = $author; } + public function getText(): string + { + return $this->text; + } + + public function getCreated(): string + { + return $this->created; + } + + public function getAuthor(): string + { + return $this->author; + } + public function setId(int $id): void { $this->id = $id; diff --git a/src/Service/Retweeter.php b/src/Service/Retweeter.php index d32594b..af8094f 100644 --- a/src/Service/Retweeter.php +++ b/src/Service/Retweeter.php @@ -2,6 +2,7 @@ namespace App\Service; +use App\Model\Tweet; use Codebird\Codebird; class Retweeter @@ -26,10 +27,10 @@ class Retweeter $this->codebird = $codebird; } - public function retweet(array $tweet): void + public function retweet(Tweet $tweet): void { $this->codebird->statuses_retweet_ID([ - 'id' => $tweet['id'], + 'id' => $tweet->getId(), ]); } } diff --git a/src/Service/TweetFetcher.php b/src/Service/TweetFetcher.php index 48acb3a..39c8f94 100644 --- a/src/Service/TweetFetcher.php +++ b/src/Service/TweetFetcher.php @@ -2,6 +2,7 @@ namespace App\Service; +use App\Model\Tweet; use Codebird\Codebird; use Tightenco\Collect\Support\Collection; @@ -56,13 +57,13 @@ class TweetFetcher } return collect($response->get('statuses')) - ->map(function (\stdClass $tweet) { - return [ - 'id' => $tweet->id, - 'created' => strtotime($tweet->created_at), - 'text' => $tweet->text, - 'author' => $tweet->user->screen_name, - ]; + ->map(function (\stdClass $status) { + return tap(new Tweet(), function (Tweet $tweet) use ($status) { + $tweet->setId($status->id); + $tweet->setText($status->text); + $tweet->setCreated(strtotime($status->created_at)); + $tweet->setAuthor($status->user->screen_name); + }); })->reverse(); }