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

api-platform / core / 15023181448

14 May 2025 02:19PM UTC coverage: 0.0% (-8.4%) from 8.418%
15023181448

Pull #7139

github

web-flow
Merge 9f45709da into 1862d03b7
Pull Request #7139: refactor(symfony): remove obsolete option `validator.query-parameter-validation`

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

11266 existing lines in 366 files now uncovered.

0 of 50828 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/Symfony/Validator/Metadata/Property/Restriction/PropertySchemaCollectionRestriction.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\Metadata\Property\Restriction;
15

16
use ApiPlatform\Metadata\ApiProperty;
17
use Symfony\Component\Validator\Constraint;
18
use Symfony\Component\Validator\Constraints\Collection;
19
use Symfony\Component\Validator\Constraints\Optional;
20
use Symfony\Component\Validator\Constraints\Required;
21

22
/**
23
 * @author Tomas Norkūnas <norkunas.tom@gmail.com>
24
 */
25
final class PropertySchemaCollectionRestriction implements PropertySchemaRestrictionMetadataInterface
26
{
27
    /**
28
     * @param iterable<PropertySchemaRestrictionMetadataInterface> $restrictionsMetadata
29
     */
30
    public function __construct(private readonly iterable $restrictionsMetadata = [])
31
    {
UNCOV
32
    }
×
33

34
    /**
35
     * {@inheritdoc}
36
     *
37
     * @param Collection $constraint
38
     */
39
    public function create(Constraint $constraint, ApiProperty $propertyMetadata): array
40
    {
41
        $restriction = [
×
42
            'type' => 'object',
×
43
            'properties' => new \ArrayObject(),
×
44
            'additionalProperties' => $constraint->allowExtraFields,
×
45
        ];
×
46
        $required = [];
×
47

48
        foreach ($constraint->fields as $field => $baseConstraint) {
×
49
            /** @var Required|Optional $baseConstraint */
50
            if ($baseConstraint instanceof Required && !$constraint->allowMissingFields) {
×
51
                $required[] = $field;
×
52
            }
53

54
            $restriction['properties'][$field] = $this->mergeConstraintRestrictions($baseConstraint, $propertyMetadata);
×
55
        }
56

57
        if ($required) {
×
58
            $restriction['required'] = $required;
×
59
        }
60

61
        return $restriction;
×
62
    }
63

64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function supports(Constraint $constraint, ApiProperty $propertyMetadata): bool
68
    {
UNCOV
69
        return $constraint instanceof Collection;
×
70
    }
71

72
    private function mergeConstraintRestrictions(Required|Optional $constraint, ApiProperty $propertyMetadata): array|\ArrayObject
73
    {
74
        $propertyRestrictions = [];
×
75
        $nestedConstraints = $constraint->constraints;
×
76

77
        foreach ($nestedConstraints as $nestedConstraint) {
×
78
            foreach ($this->restrictionsMetadata as $restrictionMetadata) {
×
79
                if ($restrictionMetadata->supports($nestedConstraint, $propertyMetadata->withExtraProperties(($propertyMetadata->getExtraProperties() ?? []) + ['nested_schema' => true])) && !empty($nestedConstraintRestriction = $restrictionMetadata->create($nestedConstraint, $propertyMetadata))) {
×
80
                    $propertyRestrictions[] = $nestedConstraintRestriction;
×
81
                }
82
            }
83
        }
84

85
        return array_merge([], ...$propertyRestrictions) ?: new \ArrayObject();
×
86
    }
87
}
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