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

api-platform / core / 14035635597

24 Mar 2025 12:46PM UTC coverage: 8.513% (-7.6%) from 16.086%
14035635597

push

github

web-flow
fix(laravel): defer "filters" dependent services (#7045)

0 of 109 new or added lines in 1 file covered. (0.0%)

3078 existing lines in 187 files now uncovered.

13386 of 157241 relevant lines covered (8.51%)

22.91 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\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
    {
38
        $this->serializePayloadFields = null === $serializePayloadFields ? null : array_flip($serializePayloadFields);
2,016✔
39
    }
40

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

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

53
    public function getSupportedTypes($format): array
54
    {
55
        return $format === static::FORMAT ? [ConstraintViolationListInterface::class => true] : [];
1,887✔
56
    }
57

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

62
        foreach ($constraintViolationList as $violation) {
72✔
63
            $class = \is_object($root = $violation->getRoot()) ? $root::class : null;
69✔
64

65
            if ($this->nameConverter instanceof AdvancedNameConverterInterface || $this->nameConverter instanceof MetadataAwareNameConverter) {
69✔
66
                $propertyPath = $this->nameConverter->normalize($violation->getPropertyPath(), $class, static::FORMAT);
65✔
67
            } elseif ($this->nameConverter instanceof NameConverterInterface) {
4✔
68
                $propertyPath = $this->nameConverter->normalize($violation->getPropertyPath());
2✔
69
            } else {
70
                $propertyPath = $violation->getPropertyPath();
2✔
71
            }
72

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

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

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

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

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