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

api-platform / core / 20847864477

09 Jan 2026 09:47AM UTC coverage: 29.1% (+0.005%) from 29.095%
20847864477

Pull #7649

github

web-flow
Merge b342dd5db into d640d106b
Pull Request #7649: feat(validator): uuid/ulid parameter validation

0 of 4 new or added lines in 1 file covered. (0.0%)

15050 existing lines in 491 files now uncovered.

16996 of 58406 relevant lines covered (29.1%)

81.8 hits per line

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

31.82
/src/JsonApi/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\JsonApi\Serializer;
15

16
use ApiPlatform\Metadata\IriConverterInterface;
17
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
18
use ApiPlatform\Metadata\ResourceClassResolverInterface;
19
use ApiPlatform\Metadata\Util\ClassInfoTrait;
20
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
21

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

30
    public const FORMAT = 'jsonapi';
31

32
    public function __construct(private readonly NormalizerInterface $decorated, private readonly IriConverterInterface $iriConverter, private readonly ResourceClassResolverInterface $resourceClassResolver, private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory)
33
    {
UNCOV
34
    }
2,409✔
35

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

44
    /**
45
     * {@inheritdoc}
46
     */
47
    public function getSupportedTypes(?string $format): array
48
    {
UNCOV
49
        return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
2,002✔
50
    }
51

52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
56
    {
57
        if (isset($context['api_resource'])) {
25✔
58
            $originalResource = $context['api_resource'];
×
59
            unset($context['api_resource']);
×
60
        }
61

62
        $normalizedData = $this->decorated->normalize($data, $format, $context);
25✔
63
        if (!\is_array($normalizedData) || isset($context['api_attribute'])) {
25✔
64
            return $normalizedData;
25✔
65
        }
66

67
        if (isset($originalResource)) {
×
68
            $resourceClass = $this->resourceClassResolver->getResourceClass($originalResource);
×
69
            $resourceData = [
×
70
                'id' => $this->iriConverter->getIriFromResource($originalResource),
×
71
                'type' => $this->resourceMetadataFactory->create($resourceClass)->getOperation()->getShortName(),
×
72
            ];
×
73
        } else {
74
            $resourceData = [
×
75
                'id' => $this->iriConverter->getIriFromResource($data),
×
76
                'type' => (new \ReflectionClass($this->getObjectClass($data)))->getShortName(),
×
77
            ];
×
78
        }
79

80
        if ($normalizedData) {
×
81
            $resourceData['attributes'] = $normalizedData;
×
82
        }
83

84
        return ['data' => $resourceData];
×
85
    }
86
}
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

© 2026 Coveralls, Inc