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

api-platform / core / 20969151198

13 Jan 2026 07:07PM UTC coverage: 0.0% (-29.1%) from 29.095%
20969151198

Pull #7669

github

web-flow
Merge 872bbc755 into c8493bbe7
Pull Request #7669: ci - fix testMapPutAllowCreate

0 of 57775 relevant lines covered (0.0%)

0.0 hits per line

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

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

16
use ApiPlatform\State\ApiResource\Error;
17
use ApiPlatform\Validator\Exception\ValidationException;
18
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
19

20
final class ErrorNormalizer implements NormalizerInterface
21
{
22
    use HydraPrefixTrait;
23

24
    public function __construct(private readonly NormalizerInterface $inner, private readonly array $defaultContext = [])
25
    {
26
    }
×
27

28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function normalize(mixed $data, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
32
    {
33
        $context += $this->defaultContext;
×
34
        $normalized = $this->inner->normalize($data, $format, $context);
×
35
        $hydraPrefix = $this->getHydraPrefix($context);
×
36
        if (!$hydraPrefix) {
×
37
            return $normalized;
×
38
        }
39

40
        if ('Error' === $normalized['@type']) {
×
41
            $normalized['@type'] = 'hydra:Error';
×
42
        }
43

44
        if (isset($normalized['description'])) {
×
45
            $normalized['hydra:description'] = $normalized['description'];
×
46
            unset($normalized['description']);
×
47
        }
48

49
        if (isset($normalized['title'])) {
×
50
            $normalized['hydra:title'] = $normalized['title'];
×
51
            // this is confusing as the field is also available in the Problem Detail Json representation
52
            // but we don't want to repeat the title in the response, tldr: use hydra without prefix
53
            unset($normalized['title']);
×
54
        }
55

56
        return $normalized;
×
57
    }
58

59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
63
    {
64
        return $this->inner->supportsNormalization($data, $format, $context)
×
65
            && (is_a($data, Error::class) || is_a($data, ValidationException::class));
×
66
    }
67

68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getSupportedTypes(?string $format): array
72
    {
73
        if (method_exists($this->inner, 'getSupportedTypes')) {
×
74
            return $this->inner->getSupportedTypes($format);
×
75
        }
76

77
        return [];
×
78
    }
79
}
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