• 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

95.24
/src/Metadata/Property/Factory/PropertyInfoPropertyMetadataFactory.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\Metadata\Property\Factory;
15

16
use ApiPlatform\Metadata\ApiProperty;
17
use ApiPlatform\Metadata\Exception\PropertyNotFoundException;
18
use Doctrine\Common\Collections\ArrayCollection;
19
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
20
use Symfony\Component\PropertyInfo\Type;
21

22
/**
23
 * PropertyInfo metadata loader decorator.
24
 *
25
 * @author Kévin Dunglas <dunglas@gmail.com>
26
 */
27
final class PropertyInfoPropertyMetadataFactory implements PropertyMetadataFactoryInterface
28
{
29
    public function __construct(private readonly PropertyInfoExtractorInterface $propertyInfo, private readonly ?PropertyMetadataFactoryInterface $decorated = null)
30
    {
UNCOV
31
    }
979✔
32

33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function create(string $resourceClass, string $property, array $options = []): ApiProperty
37
    {
UNCOV
38
        if (null === $this->decorated) {
240✔
39
            $propertyMetadata = new ApiProperty();
×
40
        } else {
41
            try {
UNCOV
42
                $propertyMetadata = $this->decorated->create($resourceClass, $property, $options);
240✔
UNCOV
43
            } catch (PropertyNotFoundException) {
239✔
UNCOV
44
                $propertyMetadata = new ApiProperty();
239✔
45
            }
46
        }
47

UNCOV
48
        if (!$propertyMetadata->getBuiltinTypes()) {
240✔
UNCOV
49
            $types = $this->propertyInfo->getTypes($resourceClass, $property, $options) ?? [];
240✔
50

UNCOV
51
            foreach ($types as $i => $type) {
240✔
52
                // Temp fix for https://github.com/symfony/symfony/pull/52699
UNCOV
53
                if (ArrayCollection::class === $type->getClassName()) {
225✔
UNCOV
54
                    $types[$i] = new Type($type->getBuiltinType(), $type->isNullable(), $type->getClassName(), true, $type->getCollectionKeyTypes(), $type->getCollectionValueTypes());
4✔
55
                }
56
            }
57

UNCOV
58
            $propertyMetadata = $propertyMetadata->withBuiltinTypes($types);
240✔
59
        }
60

UNCOV
61
        if (null === $propertyMetadata->getDescription() && null !== $description = $this->propertyInfo->getShortDescription($resourceClass, $property, $options)) {
240✔
UNCOV
62
            $propertyMetadata = $propertyMetadata->withDescription($description);
76✔
63
        }
64

UNCOV
65
        if (null === $propertyMetadata->isReadable() && null !== $readable = $this->propertyInfo->isReadable($resourceClass, $property, $options)) {
240✔
UNCOV
66
            $propertyMetadata = $propertyMetadata->withReadable($readable);
239✔
67
        }
68

UNCOV
69
        if (null === $propertyMetadata->isWritable() && null !== $writable = $this->propertyInfo->isWritable($resourceClass, $property, $options)) {
240✔
UNCOV
70
            $propertyMetadata = $propertyMetadata->withWritable($writable);
239✔
71
        }
72

73
        /* @phpstan-ignore-next-line */
UNCOV
74
        if (null === $propertyMetadata->isInitializable() && null !== $initializable = $this->propertyInfo->isInitializable($resourceClass, $property, $options)) {
240✔
UNCOV
75
            $propertyMetadata = $propertyMetadata->withInitializable($initializable);
240✔
76
        }
77

UNCOV
78
        return $propertyMetadata;
240✔
79
    }
80
}
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