• 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

100.0
/src/Serializer/AbstractConstraintViolationListNormalizer.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\Serializer;
15

16
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
17
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
18
use Symfony\Component\Validator\ConstraintViolation;
19
use Symfony\Component\Validator\ConstraintViolationListInterface;
20

21
/**
22
 * Common features regarding Constraint Violation normalization.
23
 *
24
 * @author Kévin Dunglas <dunglas@gmail.com>
25
 *
26
 * @internal
27
 */
28
abstract class AbstractConstraintViolationListNormalizer implements NormalizerInterface
29
{
30
    public const FORMAT = null; // Must be overridden
31

32
    private readonly ?array $serializePayloadFields;
33

34
    public function __construct(?array $serializePayloadFields = null, private readonly ?NameConverterInterface $nameConverter = null)
35
    {
UNCOV
36
        $this->serializePayloadFields = null === $serializePayloadFields ? null : array_flip($serializePayloadFields);
2,415✔
37
    }
38

39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
43
    {
UNCOV
44
        if (!($context['api_error_resource'] ?? false)) {
119✔
UNCOV
45
            return false;
2✔
46
        }
47

UNCOV
48
        return static::FORMAT === $format && $data instanceof ConstraintViolationListInterface;
119✔
49
    }
50

51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getSupportedTypes(?string $format): array
55
    {
UNCOV
56
        return $format === static::FORMAT ? [ConstraintViolationListInterface::class => true] : [];
2,181✔
57
    }
58

59
    protected function getMessagesAndViolations(ConstraintViolationListInterface $constraintViolationList): array
60
    {
UNCOV
61
        $violations = $messages = [];
121✔
62

UNCOV
63
        foreach ($constraintViolationList as $violation) {
121✔
UNCOV
64
            $class = \is_object($root = $violation->getRoot()) ? $root::class : null;
118✔
65

UNCOV
66
            if ($this->nameConverter) {
118✔
UNCOV
67
                $propertyPath = $this->nameConverter->normalize($violation->getPropertyPath(), $class, static::FORMAT);
116✔
68
            } else {
UNCOV
69
                $propertyPath = $violation->getPropertyPath();
2✔
70
            }
71

UNCOV
72
            $violationData = [
118✔
UNCOV
73
                'propertyPath' => $propertyPath,
118✔
UNCOV
74
                'message' => $violation->getMessage(),
118✔
UNCOV
75
                'code' => $violation->getCode(),
118✔
UNCOV
76
            ];
118✔
77

UNCOV
78
            if ($hint = $violation->getParameters()['hint'] ?? false) {
118✔
UNCOV
79
                $violationData['hint'] = $hint;
2✔
80
            }
81

UNCOV
82
            $constraint = $violation instanceof ConstraintViolation ? $violation->getConstraint() : null;
118✔
83
            if (
UNCOV
84
                [] !== $this->serializePayloadFields
118✔
85
                && $constraint
UNCOV
86
                && $constraint->payload
118✔
87
                // If some fields are whitelisted, only them are added
UNCOV
88
                && $payloadFields = null === $this->serializePayloadFields ? $constraint->payload : array_intersect_key($constraint->payload, $this->serializePayloadFields)
118✔
89
            ) {
UNCOV
90
                $violationData['payload'] = $payloadFields;
4✔
91
            }
92

UNCOV
93
            $violations[] = $violationData;
118✔
UNCOV
94
            $messages[] = ($violationData['propertyPath'] ? "{$violationData['propertyPath']}: " : '').$violationData['message'];
118✔
95
        }
96

UNCOV
97
        return [$messages, $violations];
121✔
98
    }
99
}
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