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

api-platform / core / 9562658349

18 Jun 2024 09:35AM UTC coverage: 62.637% (+0.4%) from 62.272%
9562658349

push

github

soyuka
Merge 3.4

52 of 55 new or added lines in 6 files covered. (94.55%)

236 existing lines in 20 files now uncovered.

11016 of 17587 relevant lines covered (62.64%)

60.45 hits per line

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

8.7
/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\Serializer\CacheableSupportsMethodInterface;
17
use ApiPlatform\Validator\Exception\ValidationException;
18
use Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface;
19
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
20
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
21
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
22
use Symfony\Component\Serializer\Serializer;
23

24
class ValidationExceptionNormalizer implements NormalizerInterface, CacheableSupportsMethodInterface
25
{
26
    public function __construct(private readonly NormalizerInterface $decorated, private readonly ?NameConverterInterface $nameConverter)
27
    {
28
    }
352✔
29

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

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

UNCOV
44
            $messages[] = ($propertyPath ? "{$propertyPath}: " : '').$violation->getMessage();
×
45
        }
46

47
        $str = implode("\n", $messages);
×
UNCOV
48
        $object->setDetail($str);
×
49

UNCOV
50
        return $this->decorated->normalize($object, $format, $context);
×
51
    }
52

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

58
    public function hasCacheableSupportsMethod(): bool
59
    {
60
        if (method_exists(Serializer::class, 'getSupportedTypes')) {
×
61
            trigger_deprecation(
×
62
                'api-platform/core',
×
63
                '3.1',
×
64
                'The "%s()" method is deprecated, use "getSupportedTypes()" instead.',
×
65
                __METHOD__
×
UNCOV
66
            );
×
67
        }
68

UNCOV
69
        return false;
×
70
    }
71

72
    public function getSupportedTypes($format): array
73
    {
74
        return [ValidationException::class => false];
328✔
75
    }
76
}
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