| Conditions | 3 |
| Paths | 3 |
| Total Lines | 23 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 25 | public function transform(ResponseInterface $response, string $class) |
||
| 26 | { |
||
| 27 | $body = $response->getBody()->__toString(); |
||
| 28 | $data = \json_decode($body, true); |
||
| 29 | |||
| 30 | if (JSON_ERROR_NONE !== \json_last_error()) { |
||
| 31 | throw new TransformerException( |
||
| 32 | \sprintf( |
||
| 33 | 'Invalid json response format : Error %d when trying to \json_decode response', |
||
| 34 | \json_last_error() |
||
| 35 | ) |
||
| 36 | ); |
||
| 37 | } |
||
| 38 | |||
| 39 | $reflection = new \ReflectionClass($class); |
||
| 40 | if (true === $reflection->implementsInterface(FromArrayInterface::class)) { |
||
| 41 | $object = \call_user_func($class.'::fromArray', $data); |
||
| 42 | } else { |
||
| 43 | $object = new $class($data); |
||
| 44 | } |
||
| 45 | |||
| 46 | return $object; |
||
| 47 | } |
||
| 48 | } |
||
| 49 |