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

api-platform / core / 20847864477

09 Jan 2026 09:47AM UTC coverage: 29.1% (+0.005%) from 29.095%
20847864477

Pull #7649

github

web-flow
Merge b342dd5db into d640d106b
Pull Request #7649: feat(validator): uuid/ulid parameter validation

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

15050 existing lines in 491 files now uncovered.

16996 of 58406 relevant lines covered (29.1%)

81.8 hits per line

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

90.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
    {
UNCOV
26
    }
2,411✔
27

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

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

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

UNCOV
49
        if (isset($normalized['title'])) {
255✔
UNCOV
50
            $normalized['hydra:title'] = $normalized['title'];
255✔
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
UNCOV
53
            unset($normalized['title']);
255✔
54
        }
55

UNCOV
56
        return $normalized;
255✔
57
    }
58

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

68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getSupportedTypes(?string $format): array
72
    {
UNCOV
73
        if (method_exists($this->inner, 'getSupportedTypes')) {
2,116✔
UNCOV
74
            return $this->inner->getSupportedTypes($format);
2,116✔
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