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

api-platform / core / 18343625207

08 Oct 2025 11:48AM UTC coverage: 24.542% (-0.02%) from 24.561%
18343625207

push

github

web-flow
fix(state): object mapper on delete operation (#7447)

fixes #7434

1 of 49 new or added lines in 2 files covered. (2.04%)

7084 existing lines in 207 files now uncovered.

14004 of 57061 relevant lines covered (24.54%)

26.01 hits per line

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

9.09
/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
    }
694✔
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);
×
42
    }
43

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

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

62
        $data = $this->decorated->normalize($object, $format, $context);
×
63
        if (!\is_array($data) || isset($context['api_attribute'])) {
×
64
            return $data;
×
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($object),
×
76
                'type' => (new \ReflectionClass($this->getObjectClass($object)))->getShortName(),
×
77
            ];
×
78
        }
79

80
        if ($data) {
×
81
            $resourceData['attributes'] = $data;
×
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

© 2025 Coveralls, Inc