diff --git a/src/RdwApiClient/RdwApiClient.php b/src/RdwApiClient/RdwApiClient.php index 7432331..57c4b54 100755 --- a/src/RdwApiClient/RdwApiClient.php +++ b/src/RdwApiClient/RdwApiClient.php @@ -52,11 +52,16 @@ protected function processApiResponse(Response $response): array throw new UnexpectedApiResponseException("API endpoint did not return valid JSON. Received: " . $response->getBody()->getContents()); } + if (!is_array($results)) { + throw new UnexpectedApiResponseException("API endpoint did not return an expected JSON array. Received: " . $response->getBody()->getContents()); + } + return $results; } - public function getLicensedVehicleDataByLicensePlateNumber(string $licensePlateNumber): ?array { + public function getLicensedVehicleDataByLicensePlateNumber(string $licensePlateNumber): array + { $licensePlateNumber = $this->normalizeLicensePlateNumber($licensePlateNumber); $response = $this->createGuzzleClient()->get( @@ -67,7 +72,7 @@ public function getLicensedVehicleDataByLicensePlateNumber(string $licensePlateN ); $results = $this->processApiResponse($response); - return empty($results) ? null : $results[0]; + return empty($results) ? [] : $results[0]; } }