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

api-platform / core / 15775135891

20 Jun 2025 08:42AM UTC coverage: 22.065% (+0.2%) from 21.876%
15775135891

push

github

soyuka
Merge 4.1

13 of 103 new or added lines in 10 files covered. (12.62%)

868 existing lines in 35 files now uncovered.

11487 of 52060 relevant lines covered (22.06%)

21.72 hits per line

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

0.0
/src/Elasticsearch/Serializer/ItemNormalizer.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\Elasticsearch\Serializer;
15

16
use Symfony\Component\Serializer\Exception\LogicException;
17
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
18
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
19
use Symfony\Component\Serializer\SerializerAwareInterface;
20
use Symfony\Component\Serializer\SerializerInterface;
21

22
/**
23
 * Item normalizer decorator that prevents {@see \ApiPlatform\Serializer\ItemNormalizer}
24
 * from taking over for the {@see DocumentNormalizer::FORMAT} format because of priorities.
25
 *
26
 * @experimental
27
 */
28
final class ItemNormalizer implements NormalizerInterface, DenormalizerInterface, SerializerAwareInterface
29
{
30
    public const FORMAT = 'elasticsearch';
31

32
    public function __construct(private readonly NormalizerInterface $decorated)
33
    {
34
    }
×
35

36
    /**
37
     * {@inheritdoc}
38
     *
39
     * @throws LogicException
40
     */
41
    public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
42
    {
43
        if (!$this->decorated instanceof DenormalizerInterface) {
×
44
            throw new LogicException(\sprintf('The decorated normalizer must be an instance of "%s".', DenormalizerInterface::class));
×
45
        }
46

47
        return $this->decorated->denormalize($data, $type, $format, $context);
×
48
    }
49

50
    /**
51
     * {@inheritdoc}
52
     *
53
     * @throws LogicException
54
     */
55
    public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
56
    {
57
        if (!$this->decorated instanceof DenormalizerInterface) {
×
58
            throw new LogicException(\sprintf('The decorated normalizer must be an instance of "%s".', DenormalizerInterface::class));
×
59
        }
60

61
        return DocumentNormalizer::FORMAT !== $format && $this->decorated->supportsDenormalization($data, $type, $format, $context);
×
62
    }
63

64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function normalize(mixed $object, ?string $format = null, array $context = []): \ArrayObject|array|string|int|float|bool|null
68
    {
69
        return $this->decorated->normalize($object, $format, $context);
×
70
    }
71

72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
76
    {
77
        return DocumentNormalizer::FORMAT !== $format && $this->decorated->supportsNormalization($data, $format);
×
78
    }
79

80
    public function getSupportedTypes($format): array
81
    {
UNCOV
82
        return DocumentNormalizer::FORMAT !== $format ? $this->decorated->getSupportedTypes($format) : [];
×
83
    }
84

85
    /**
86
     * {@inheritdoc}
87
     *
88
     * @throws LogicException
89
     */
90
    public function setSerializer(SerializerInterface $serializer): void
91
    {
UNCOV
92
        if (!$this->decorated instanceof SerializerAwareInterface) {
×
UNCOV
93
            throw new LogicException(\sprintf('The decorated normalizer must be an instance of "%s".', SerializerAwareInterface::class));
×
94
        }
95

UNCOV
96
        $this->decorated->setSerializer($serializer);
×
97
    }
98
}
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