Skip to content

Instantly share code, notes, and snippets.

@mannion007
Last active November 12, 2019 17:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mannion007/d20918f5c37e4171aca66243a9775b8c to your computer and use it in GitHub Desktop.
Save mannion007/d20918f5c37e4171aca66243a9775b8c to your computer and use it in GitHub Desktop.
No schema
<?php
/** ...Make the request, decode the response */
/** Check scan reference is present before we can use it */
if (!isset($decodedResponse->scanReference)) {
throw new \Exception("Invalid response - Scan Reference is missing");
}
if (!is_string($decodedResponse->scanReference)) {
throw new \Exception("Invalid response - Scan Reference is not a string");
}
/** Check status is present before we can use it */
if (!isset($decodedResponse->status)) {
throw new \Exception("Invalid response - Status is missing");
}
if (!is_string($decodedResponse->scanReference)) {
throw new \Exception("Invalid response - Status is not a string");
}
/** Check dob is present and in the format we expect before we can use it */
$dob = null;
if (isset($decodedResponse->document->dob)) {
if (!preg_match("/^[0-9]{4}-[0,1][0-9]-[0,1][0-9]$/", $decodedResponse->document->dob)) {
throw new \Exception("DOB present but not in the expected format");
}
$dob = \DateTimeImmutable::createFromFormat('Y-m-d', $decodedResponse->document->dob);
}
/** ...continues for every other property we want to use */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment