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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 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
    {
UNCOV
31
    }
952✔
32

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

41
    public function getSupportedTypes($format): array
42
    {
UNCOV
43
        return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
806✔
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
    {
51
        if (isset($context['api_resource'])) {
2✔
52
            $originalResource = $context['api_resource'];
×
53
            unset($context['api_resource']);
×
54
        }
55

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

61
        if (!isset($originalResource)) {
2✔
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
UNCOV
82
        return self::FORMAT === $format;
1✔
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
    {
UNCOV
92
        throw new LogicException(\sprintf('%s is a read-only format.', self::FORMAT));
1✔
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