Skip to content

Commit

Permalink
Return empty array when no data is found instead of a null value
Browse files Browse the repository at this point in the history
  • Loading branch information
dovereem committed Sep 22, 2022
1 parent e0542d2 commit 09705c4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/RdwApiClient/RdwApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -67,7 +72,7 @@ public function getLicensedVehicleDataByLicensePlateNumber(string $licensePlateN
);
$results = $this->processApiResponse($response);

return empty($results) ? null : $results[0];
return empty($results) ? [] : $results[0];
}

}

0 comments on commit 09705c4

Please sign in to comment.