/** * @param string[] $query * @param int $since * @param int $store * @return int */ public function runInternal(array $query, $since, $store) { $nextMin = null; $qty = 0; do { // we're not on the first iteration anymore - utilize pagination in the api if ($nextMin !== null) { $query['since_id'] = $nextMin; } $data = $this->client->searchTweets($query); $medias = array_map([$this, 'toMedia'], $data->statuses); $medias = array_filter($medias, function ($it) use($since) { return $it->createdAt > $since; }); $n = $data->search_metadata->max_id; if ($n === $nextMin) { break; } $nextMin = $n; $store->insert($medias); $qty += count($medias); } while (count($medias) !== 0); return $qty; }