• 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

47.62
/src/Hal/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\Hal\Serializer;
15

16
use ApiPlatform\Metadata\IriConverterInterface;
17
use Symfony\Component\Serializer\Exception\LogicException;
18
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
19
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
20

21
/**
22
 * Decorates the output with JSON HAL metadata when appropriate, but otherwise
23
 * just passes through to the decorated normalizer.
24
 */
25
final class ObjectNormalizer implements NormalizerInterface, DenormalizerInterface
26
{
27
    public const FORMAT = 'jsonhal';
28

29
    public function __construct(private readonly NormalizerInterface $decorated, private readonly IriConverterInterface $iriConverter)
30
    {
31
    }
1,164✔
32

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

41
    public function getSupportedTypes($format): array
42
    {
43
        return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
976✔
44
    }
45

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

UNCOV
56
        $data = $this->decorated->normalize($object, $format, $context);
2✔
UNCOV
57
        if (!\is_array($data)) {
2✔
58
            return $data;
×
59
        }
60

UNCOV
61
        if (!isset($originalResource)) {
2✔
UNCOV
62
            return $data;
2✔
63
        }
64

65
        $metadata = [
×
66
            '_links' => [
×
67
                'self' => [
×
68
                    'href' => $this->iriConverter->getIriFromResource($originalResource),
×
69
                ],
×
70
            ],
×
71
        ];
×
72

73
        return $metadata + $data;
×
74
    }
75

76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
80
    {
81
        // prevent the use of lower priority normalizers (e.g. serializer.normalizer.object) for this format
82
        return self::FORMAT === $format;
2✔
83
    }
84

85
    /**
86
     * {@inheritdoc}
87
     *
88
     * @throws LogicException
89
     */
90
    public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
91
    {
92
        throw new LogicException(\sprintf('%s is a read-only format.', self::FORMAT));
2✔
93
    }
94
}
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