/src/OpenApi3/Tests/fixtures/github/expected/Normalizer/SearchCodeGetResponse200Normalizer.php

https://github.com/janephp/janephp · PHP · 72 lines · 70 code · 2 blank · 0 comment · 11 complexity · 91bcf304d68cb0e10b5fea0d373d114a MD5 · raw file

  1. <?php
  2. namespace Github\Normalizer;
  3. use Jane\JsonSchemaRuntime\Reference;
  4. use Github\Runtime\Normalizer\CheckArray;
  5. use Symfony\Component\Serializer\Exception\InvalidArgumentException;
  6. use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
  7. use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
  8. use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
  9. use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
  10. use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
  11. use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
  12. class SearchCodeGetResponse200Normalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
  13. {
  14. use DenormalizerAwareTrait;
  15. use NormalizerAwareTrait;
  16. use CheckArray;
  17. public function supportsDenormalization($data, $type, $format = null)
  18. {
  19. return $type === 'Github\\Model\\SearchCodeGetResponse200';
  20. }
  21. public function supportsNormalization($data, $format = null)
  22. {
  23. return is_object($data) && get_class($data) === 'Github\\Model\\SearchCodeGetResponse200';
  24. }
  25. public function denormalize($data, $class, $format = null, array $context = array())
  26. {
  27. if (isset($data['$ref'])) {
  28. return new Reference($data['$ref'], $context['document-origin']);
  29. }
  30. if (isset($data['$recursiveRef'])) {
  31. return new Reference($data['$recursiveRef'], $context['document-origin']);
  32. }
  33. $object = new \Github\Model\SearchCodeGetResponse200();
  34. if (null === $data || false === \is_array($data)) {
  35. return $object;
  36. }
  37. if (\array_key_exists('total_count', $data)) {
  38. $object->setTotalCount($data['total_count']);
  39. }
  40. if (\array_key_exists('incomplete_results', $data)) {
  41. $object->setIncompleteResults($data['incomplete_results']);
  42. }
  43. if (\array_key_exists('items', $data)) {
  44. $values = array();
  45. foreach ($data['items'] as $value) {
  46. $values[] = $this->denormalizer->denormalize($value, 'Github\\Model\\CodeSearchResultItem', 'json', $context);
  47. }
  48. $object->setItems($values);
  49. }
  50. return $object;
  51. }
  52. public function normalize($object, $format = null, array $context = array())
  53. {
  54. $data = array();
  55. if (null !== $object->getTotalCount()) {
  56. $data['total_count'] = $object->getTotalCount();
  57. }
  58. if (null !== $object->getIncompleteResults()) {
  59. $data['incomplete_results'] = $object->getIncompleteResults();
  60. }
  61. if (null !== $object->getItems()) {
  62. $values = array();
  63. foreach ($object->getItems() as $value) {
  64. $values[] = $this->normalizer->normalize($value, 'json', $context);
  65. }
  66. $data['items'] = $values;
  67. }
  68. return $data;
  69. }
  70. }