| 1 | <?php declare(strict_types=1); |
||
| 9 | class ValidationResponseFactory |
||
| 10 | { |
||
| 11 | 2 | public function create(ResponseInterface $response): ValidationResponseInterface |
|
| 12 | { |
||
| 13 | 2 | $jsonResponse = (string)$response->getBody(); |
|
| 14 | 2 | $jsonResponseObject = json_decode($jsonResponse); |
|
| 15 | |||
| 16 | 2 | $errorCollection = $jsonResponseObject->valid ? |
|
| 17 | 1 | new ErrorCollection() : |
|
| 18 | 2 | $this->createErrorCollectionFromJsonResponseObject($jsonResponseObject); |
|
| 19 | |||
| 20 | 2 | return new ValidationResponse( |
|
| 21 | 2 | $jsonResponseObject->source, |
|
| 22 | 2 | $jsonResponseObject->version, |
|
| 23 | 2 | $jsonResponseObject->valid, |
|
| 24 | 2 | $errorCollection |
|
| 25 | ); |
||
| 26 | } |
||
| 27 | |||
| 28 | 1 | private function createErrorCollectionFromJsonResponseObject(\stdClass $jsonResponseObject): ErrorCollection |
|
| 46 | } |
||
| 47 |