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

api-platform / core / 17581213192

09 Sep 2025 11:31AM UTC coverage: 0.0% (-22.6%) from 22.604%
17581213192

Pull #7374

github

web-flow
Merge 0f1360e1a into 6db55be8c
Pull Request #7374: fix(jsonld): various json streamer fixes

0 of 34 new or added lines in 2 files covered. (0.0%)

12081 existing lines in 401 files now uncovered.

0 of 52792 relevant lines covered (0.0%)

0.0 hits per line

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

0.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\AdvancedNameConverterInterface;
17
use Symfony\Component\Serializer\NameConverter\MetadataAwareNameConverter;
18
use Symfony\Component\Serializer\NameConverter\NameConverterInterface;
19
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
20
use Symfony\Component\Validator\ConstraintViolation;
21
use Symfony\Component\Validator\ConstraintViolationListInterface;
22

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

34
    private readonly ?array $serializePayloadFields;
35

36
    public function __construct(?array $serializePayloadFields = null, private readonly ?NameConverterInterface $nameConverter = null)
37
    {
UNCOV
38
        $this->serializePayloadFields = null === $serializePayloadFields ? null : array_flip($serializePayloadFields);
×
39
    }
40

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

UNCOV
50
        return static::FORMAT === $format && $data instanceof ConstraintViolationListInterface;
×
51
    }
52

53
    /**
54
     * @param string|null $format
55
     */
56
    public function getSupportedTypes($format): array
57
    {
UNCOV
58
        return $format === static::FORMAT ? [ConstraintViolationListInterface::class => true] : [];
×
59
    }
60

61
    protected function getMessagesAndViolations(ConstraintViolationListInterface $constraintViolationList): array
62
    {
UNCOV
63
        $violations = $messages = [];
×
64

UNCOV
65
        foreach ($constraintViolationList as $violation) {
×
UNCOV
66
            $class = \is_object($root = $violation->getRoot()) ? $root::class : null;
×
67

UNCOV
68
            if ($this->nameConverter instanceof AdvancedNameConverterInterface || $this->nameConverter instanceof MetadataAwareNameConverter) {
×
UNCOV
69
                $propertyPath = $this->nameConverter->normalize($violation->getPropertyPath(), $class, static::FORMAT);
×
UNCOV
70
            } elseif ($this->nameConverter instanceof NameConverterInterface) {
×
UNCOV
71
                $propertyPath = $this->nameConverter->normalize($violation->getPropertyPath());
×
72
            } else {
UNCOV
73
                $propertyPath = $violation->getPropertyPath();
×
74
            }
75

UNCOV
76
            $violationData = [
×
UNCOV
77
                'propertyPath' => $propertyPath,
×
UNCOV
78
                'message' => $violation->getMessage(),
×
UNCOV
79
                'code' => $violation->getCode(),
×
UNCOV
80
            ];
×
81

UNCOV
82
            if ($hint = $violation->getParameters()['hint'] ?? false) {
×
UNCOV
83
                $violationData['hint'] = $hint;
×
84
            }
85

UNCOV
86
            $constraint = $violation instanceof ConstraintViolation ? $violation->getConstraint() : null;
×
87
            if (
UNCOV
88
                [] !== $this->serializePayloadFields
×
89
                && $constraint
UNCOV
90
                && $constraint->payload
×
91
                // If some fields are whitelisted, only them are added
UNCOV
92
                && $payloadFields = null === $this->serializePayloadFields ? $constraint->payload : array_intersect_key($constraint->payload, $this->serializePayloadFields)
×
93
            ) {
UNCOV
94
                $violationData['payload'] = $payloadFields;
×
95
            }
96

UNCOV
97
            $violations[] = $violationData;
×
UNCOV
98
            $messages[] = ($violationData['propertyPath'] ? "{$violationData['propertyPath']}: " : '').$violationData['message'];
×
99
        }
100

UNCOV
101
        return [$messages, $violations];
×
102
    }
103
}
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