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

api-platform / core / 10740459985

06 Sep 2024 02:47PM UTC coverage: 6.92% (-0.2%) from 7.159%
10740459985

push

github

web-flow
fix(laravel): docs _format and open swagger ui (#6595)

0 of 90 new or added lines in 11 files covered. (0.0%)

1910 existing lines in 69 files now uncovered.

11347 of 163980 relevant lines covered (6.92%)

14.18 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
use Symfony\Component\Serializer\Serializer;
21

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

30
    public function __construct(private readonly NormalizerInterface $decorated, private readonly IriConverterInterface $iriConverter)
31
    {
UNCOV
32
    }
2,624✔
33

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

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

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

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

62
        if (!isset($originalResource)) {
7✔
63
            return $data;
7✔
64
        }
65

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

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

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

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