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

api-platform / core / 9348911355

03 Jun 2024 10:58AM UTC coverage: 66.524% (-0.3%) from 66.816%
9348911355

push

github

soyuka
chore: skip behat deprecation

16418 of 24680 relevant lines covered (66.52%)

40.32 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\Symfony\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
    }
152✔
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) {
×
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) {
×
39
                $propertyPath = $this->nameConverter->normalize($violation->getPropertyPath());
×
40
            } else {
41
                $propertyPath = $violation->getPropertyPath();
×
42
            }
43

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

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

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

53
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
54
    {
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__
×
66
            );
×
67
        }
68

69
        return false;
×
70
    }
71

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