| Total Complexity | 7 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | class InputMediaNormalizer implements NormalizerInterface |
||
| 13 | { |
||
| 14 | private $files; |
||
| 15 | private $objectNormalizer; |
||
| 16 | |||
| 17 | 39 | public function __construct(NormalizerInterface $objectNormalizer, &$files) |
|
| 21 | 39 | } |
|
| 22 | |||
| 23 | 1 | public function normalize($topic, $format = null, array $context = []) |
|
| 24 | { |
||
| 25 | 1 | if ($topic->media instanceof \SplFileInfo) { |
|
| 26 | 1 | $uniqid = \uniqid(); |
|
| 27 | 1 | $this->files[$uniqid] = $topic->media; |
|
| 28 | 1 | $topic->media = 'attach://' . $uniqid; |
|
| 29 | } |
||
| 30 | |||
| 31 | 1 | if (\property_exists($topic, 'thumb') && $topic->thumb instanceof \SplFileInfo) { |
|
| 32 | 1 | $uniqid = \uniqid(); |
|
| 33 | 1 | $this->files[$uniqid] = $topic->thumb; |
|
| 34 | 1 | $topic->thumb = 'attach://' . $uniqid; |
|
| 35 | } |
||
| 36 | |||
| 37 | 1 | $serializer = new Serializer([$this->objectNormalizer]); |
|
| 38 | |||
| 39 | 1 | return $serializer->normalize($topic, null, ['skip_null_values' => true]); |
|
| 40 | } |
||
| 41 | |||
| 42 | 1 | public function supportsNormalization($data, $format = null) |
|
| 46 | } |
||
| 47 | } |
||
| 48 |