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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 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
    {
34
    }
1,160✔
35

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

44
    public function getSupportedTypes($format): array
45
    {
46
        return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
979✔
47
    }
48

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

UNCOV
59
        $data = $this->decorated->normalize($object, $format, $context);
11✔
UNCOV
60
        if (!\is_array($data) || isset($context['api_attribute'])) {
11✔
UNCOV
61
            return $data;
11✔
62
        }
63

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

77
        if ($data) {
×
78
            $resourceData['attributes'] = $data;
×
79
        }
80

81
        return ['data' => $resourceData];
×
82
    }
83
}
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