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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

100.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
    }
52✔
33

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

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

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

UNCOV
57
        if ($required) {
6✔
UNCOV
58
            $restriction['required'] = $required;
5✔
59
        }
60

UNCOV
61
        return $restriction;
6✔
62
    }
63

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

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

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

UNCOV
85
        return array_merge([], ...$propertyRestrictions) ?: new \ArrayObject();
5✔
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