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

api-platform / core / 10315659289

09 Aug 2024 07:49AM UTC coverage: 7.841% (-0.006%) from 7.847%
10315659289

push

github

soyuka
style: cs fixes

70 of 529 new or added lines in 176 files covered. (13.23%)

160 existing lines in 58 files now uncovered.

12688 of 161818 relevant lines covered (7.84%)

26.86 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) {
×
NEW
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) {
×
NEW
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 = []): array
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
    {
82
        // @deprecated remove condition when support for symfony versions under 6.3 is dropped
83
        if (!method_exists($this->decorated, 'getSupportedTypes')) {
×
84
            return [
×
85
                DocumentNormalizer::FORMAT => null,
×
86
            ];
×
87
        }
88

89
        return DocumentNormalizer::FORMAT !== $format ? $this->decorated->getSupportedTypes($format) : [];
×
90
    }
91

92
    /**
93
     * {@inheritdoc}
94
     *
95
     * @throws LogicException
96
     */
97
    public function setSerializer(SerializerInterface $serializer): void
98
    {
99
        if (!$this->decorated instanceof SerializerAwareInterface) {
×
NEW
100
            throw new LogicException(\sprintf('The decorated normalizer must be an instance of "%s".', SerializerAwareInterface::class));
×
101
        }
102

103
        $this->decorated->setSerializer($serializer);
×
104
    }
105
}
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

© 2026 Coveralls, Inc