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

api-platform / core / 16050929464

03 Jul 2025 12:51PM UTC coverage: 22.065% (+0.2%) from 21.821%
16050929464

push

github

soyuka
chore: todo improvement

11516 of 52192 relevant lines covered (22.06%)

22.08 hits per line

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

80.0
/src/Symfony/Validator/Serializer/ValidationExceptionNormalizer.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\Symfony\Validator\Serializer;
15

16
use ApiPlatform\Validator\Exception\ValidationException;
17
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
18
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
19
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
20
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
21

22
class ValidationExceptionNormalizer implements NormalizerInterface
23
{
24
    public function __construct(private readonly NormalizerInterface $decorated, private readonly ?NameConverterInterface $nameConverter)
25
    {
26
    }
520✔
27

28
    public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
29
    {
30
        $messages = [];
42✔
31
        foreach ($object->getConstraintViolationList() as $violation) {
42✔
32
            $class = \is_object($root = $violation->getRoot()) ? $root::class : null;
42✔
33

34
            if ($this->nameConverter instanceof AdvancedNameConverterInterface || $this->nameConverter instanceof MetadataAwareNameConverter) {
42✔
35
                $propertyPath = $this->nameConverter->normalize($violation->getPropertyPath(), $class, $format);
42✔
36
            } elseif ($this->nameConverter instanceof NameConverterInterface) {
×
37
                $propertyPath = $this->nameConverter->normalize($violation->getPropertyPath());
×
38
            } else {
39
                $propertyPath = $violation->getPropertyPath();
×
40
            }
41

42
            $messages[] = ($propertyPath ? "{$propertyPath}: " : '').$violation->getMessage();
42✔
43
        }
44

45
        $str = implode("\n", $messages);
42✔
46
        $object->setDetail($str);
42✔
47

48
        return $this->decorated->normalize($object, $format, $context);
42✔
49
    }
50

51
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
52
    {
53
        return $data instanceof ValidationException && $this->decorated->supportsNormalization($data, $format, $context);
42✔
54
    }
55

56
    /**
57
     * @param string|null $format
58
     */
59
    public function getSupportedTypes($format): array
60
    {
61
        return [ValidationException::class => false];
478✔
62
    }
63
}
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