Last active
November 12, 2019 17:16
-
-
Save mannion007/d20918f5c37e4171aca66243a9775b8c to your computer and use it in GitHub Desktop.
No schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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