apiKeyService = $apiKeyService; } /** * @throws ValidationException */ protected function buildShortUrlData(Request $request): CreateShortUrlData { $query = $request->getQueryParams(); if (! $this->apiKeyService->check($query['apiKey'] ?? '')) { throw ValidationException::fromArray([ 'apiKey' => 'No API key was provided or it is not valid', ]); } if (! isset($query['longUrl'])) { throw ValidationException::fromArray([ 'longUrl' => 'A URL was not provided', ]); } return new CreateShortUrlData(new Uri($query['longUrl'])); } }