• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 17054069864

18 Aug 2025 10:27PM UTC coverage: 21.952% (+0.2%) from 21.769%
17054069864

Pull #7151

github

web-flow
Merge 0da010d8d into 6491bfc7a
Pull Request #7151: fix: 7119 parameter array shape uses invalid syntax

11524 of 52497 relevant lines covered (21.95%)

11.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

11.11
/src/GraphQl/Serializer/ObjectNormalizer.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\GraphQl\Serializer;
15

16
use ApiPlatform\Metadata\IdentifiersExtractorInterface;
17
use ApiPlatform\Metadata\IriConverterInterface;
18
use ApiPlatform\Metadata\Util\ClassInfoTrait;
19
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
20
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
21

22
/**
23
 * Decorates the output with GraphQL metadata when appropriate, but otherwise just
24
 * passes through to the decorated normalizer.
25
 */
26
final class ObjectNormalizer implements NormalizerInterface
27
{
28
    use ClassInfoTrait;
29

30
    public const FORMAT = 'graphql';
31
    public const ITEM_RESOURCE_CLASS_KEY = '#itemResourceClass';
32
    public const ITEM_IDENTIFIERS_KEY = '#itemIdentifiers';
33

34
    public function __construct(private readonly NormalizerInterface $decorated, private readonly IriConverterInterface $iriConverter, private readonly IdentifiersExtractorInterface $identifiersExtractor)
35
    {
36
    }
302✔
37

38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
42
    {
43
        return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
×
44
    }
45

46
    /**
47
     * @param string|null $format
48
     */
49
    public function getSupportedTypes($format): array
50
    {
51
        return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
237✔
52
    }
53

54
    /**
55
     * {@inheritdoc}
56
     *
57
     * @throws UnexpectedValueException
58
     */
59
    public function normalize(mixed $object, ?string $format = null, array $context = []): array
60
    {
61
        if (isset($context['api_resource'])) {
×
62
            $originalResource = $context['api_resource'];
×
63
            unset($context['api_resource']);
×
64
        }
65

66
        $data = $this->decorated->normalize($object, $format, $context);
×
67
        if (!\is_array($data)) {
×
68
            throw new UnexpectedValueException('Expected data to be an array.');
×
69
        }
70

71
        if (!isset($originalResource)) {
×
72
            return $data;
×
73
        }
74

75
        if (isset($data['id'])) {
×
76
            $data['_id'] = $data['id'];
×
77
            $data['id'] = $this->iriConverter->getIriFromResource($originalResource);
×
78
        }
79

80
        if (!($context['no_resolver_data'] ?? false)) {
×
81
            $data[self::ITEM_RESOURCE_CLASS_KEY] = $this->getObjectClass($originalResource);
×
82
            $data[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($originalResource);
×
83
        }
84

85
        return $data;
×
86
    }
87
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc