| Total Complexity | 7 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | trait SerializationTrait |
||
| 9 | { |
||
| 10 | private ?SerializerInterface $serializer = null; |
||
| 11 | |||
| 12 | protected function json(mixed $obj): string |
||
| 13 | { |
||
| 14 | return $this->getSerializer()->serialize($obj, 'json'); |
||
| 15 | } |
||
| 16 | |||
| 17 | protected function object(string $json, string $class): mixed |
||
| 18 | { |
||
| 19 | return $this->getSerializer()->deserialize($json, $class, 'json'); |
||
| 20 | } |
||
| 21 | |||
| 22 | protected function convert(array $data, string $class): mixed |
||
| 23 | { |
||
| 24 | return $this->getSerializer()->deserialize(json_encode($data), $class, 'json'); |
||
| 25 | } |
||
| 26 | |||
| 27 | protected function responseObject(KernelBrowser $client, string $class): mixed |
||
| 31 | } |
||
| 32 | |||
| 33 | protected function responseObjects(KernelBrowser $client, string $class): array |
||
| 34 | { |
||
| 35 | $content = $client->getResponse()->getContent(); |
||
| 36 | $array = json_decode($content, true); |
||
| 37 | $result = []; |
||
| 38 | foreach ($array as $item) { |
||
| 39 | array_push($result, $this->convert($item, $class)); |
||
| 40 | } |
||
| 41 | return $result; |
||
| 42 | |||
| 43 | } |
||
| 44 | |||
| 45 | private function getSerializer(): SerializerInterface |
||
| 48 | } |
||
| 49 | } |