Revert "Tidy imports"

This reverts commit 2079aaef0e.
This commit is contained in:
Oliver Davies 2019-01-15 23:37:55 +00:00
parent 2079aaef0e
commit c199a9fd78
2 changed files with 27 additions and 21 deletions

View file

@ -3,7 +3,7 @@
namespace App\Service;
use App\Entity\Tweet;
use App\Repository\TweetRepository;
use Doctrine\ORM\EntityManagerInterface;
use Tightenco\Collect\Support\Collection;
class TweetFetcher
@ -30,30 +30,28 @@ class TweetFetcher
];
/**
* @var \App\Repository\TweetRepository
* @var \Doctrine\ORM\EntityManagerInterface
*/
private $tweetRepository;
private $entityManager;
public function __construct(Codebird $codebird, TweetRepository $tweetRepository)
public function __construct(Codebird $codebird, EntityManagerInterface $entityManager)
{
$this->codebird = $codebird;
$this->tweetRepository = $tweetRepository;
$this->entityManager = $entityManager;
}
public function getTweets(): Collection
{
$latestTweet = $this->tweetRepository->findNewestTweet();
$response = collect($this->codebird->get()->search_tweets([
'q' => collect($this->params()->all())->implode(' AND '),
'since_id' => $latestTweet ? $latestTweet->getId() : null,
// 'since_id' => $this->lastTweetId,
]));
if ($response->get('httpstatus') != 200) {
dump($response);
}
return collect($response->get('statuses'))
$tweets = collect($response->get('statuses'))
->map(function (\stdClass $status) {
return tap(new Tweet(), function (Tweet $tweet) use ($status) {
$tweet->setId($status->id);
@ -64,6 +62,10 @@ class TweetFetcher
$this->entityManager->persist($tweet);
});
})->reverse();
$this->entityManager->flush();
return $tweets;
}
private function params(): Collection