lines = $lines; $this->reference = $reference; } public function getForStop(Stop $stop): Collection { $estimates = json_decode(file_get_contents(static::ESTIMATES_URL . "?stopId=" . $stop->getId()), true)['delay']; $estimates = collect($estimates); $lines = $estimates->map(function ($delay) { return $delay['routeId']; })->unique(); $lines = $this->lines->getManyById($lines)->keyBy(t\property('id')); return collect($estimates)->map(function ($delay) use ($stop, $lines) { $scheduled = new Carbon($delay['theoreticalTime']); $estimated = (clone $scheduled)->addSeconds($delay['delayInSeconds']); return Departure::createFromArray([ 'scheduled' => $scheduled, 'estimated' => $estimated, 'stop' => $stop, 'display' => trim($delay['headsign']), 'vehicle' => $this->reference->get(Vehicle::class, $delay['vehicleCode']), 'line' => $lines->get($delay['routeId']) ?: Line::createFromArray([ 'symbol' => $delay['routeId'], 'type' => Line::TYPE_UNKNOWN, ]), ]); })->values(); } }