/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
- <?php
- namespace Github\Normalizer;
- use Jane\JsonSchemaRuntime\Reference;
- use Github\Runtime\Normalizer\CheckArray;
- use Symfony\Component\Serializer\Exception\InvalidArgumentException;
- use Symfony\Component\Serializer\Normalizer\DenormalizerAwareInterface;
- use Symfony\Component\Serializer\Normalizer\DenormalizerAwareTrait;
- use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
- use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
- use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
- use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
- class SearchCodeGetResponse200Normalizer implements DenormalizerInterface, NormalizerInterface, DenormalizerAwareInterface, NormalizerAwareInterface
- {
- use DenormalizerAwareTrait;
- use NormalizerAwareTrait;
- use CheckArray;
- public function supportsDenormalization($data, $type, $format = null)
- {
- return $type === 'Github\\Model\\SearchCodeGetResponse200';
- }
- public function supportsNormalization($data, $format = null)
- {
- return is_object($data) && get_class($data) === 'Github\\Model\\SearchCodeGetResponse200';
- }
- public function denormalize($data, $class, $format = null, array $context = array())
- {
- if (isset($data['$ref'])) {
- return new Reference($data['$ref'], $context['document-origin']);
- }
- if (isset($data['$recursiveRef'])) {
- return new Reference($data['$recursiveRef'], $context['document-origin']);
- }
- $object = new \Github\Model\SearchCodeGetResponse200();
- if (null === $data || false === \is_array($data)) {
- return $object;
- }
- if (\array_key_exists('total_count', $data)) {
- $object->setTotalCount($data['total_count']);
- }
- if (\array_key_exists('incomplete_results', $data)) {
- $object->setIncompleteResults($data['incomplete_results']);
- }
- if (\array_key_exists('items', $data)) {
- $values = array();
- foreach ($data['items'] as $value) {
- $values[] = $this->denormalizer->denormalize($value, 'Github\\Model\\CodeSearchResultItem', 'json', $context);
- }
- $object->setItems($values);
- }
- return $object;
- }
- public function normalize($object, $format = null, array $context = array())
- {
- $data = array();
- if (null !== $object->getTotalCount()) {
- $data['total_count'] = $object->getTotalCount();
- }
- if (null !== $object->getIncompleteResults()) {
- $data['incomplete_results'] = $object->getIncompleteResults();
- }
- if (null !== $object->getItems()) {
- $values = array();
- foreach ($object->getItems() as $value) {
- $values[] = $this->normalizer->normalize($value, 'json', $context);
- }
- $data['items'] = $values;
- }
- return $data;
- }
- }