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

api-platform / core / 19799200245

30 Nov 2025 12:55PM UTC coverage: 25.257% (+1.2%) from 24.059%
19799200245

push

github

web-flow
chore: support symfony 8 (#7561)

17 of 211 new or added lines in 28 files covered. (8.06%)

265 existing lines in 25 files now uncovered.

14551 of 57612 relevant lines covered (25.26%)

27.67 hits per line

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

70.83
/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\PropertyInfoExtractor;
20
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
21
use Symfony\Component\PropertyInfo\Type;
22

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

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

49
        // TODO: remove in 5.x
50
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
231✔
51
            if (!$propertyMetadata->getBuiltinTypes()) {
×
NEW
52
                $types = $this->propertyInfo->getTypes($resourceClass, $property, $options) ?? []; // @phpstan-ignore-line
×
53

54
                foreach ($types as $i => $type) {
×
55
                    // Temp fix for https://github.com/symfony/symfony/pull/52699
56
                    if (ArrayCollection::class === $type->getClassName()) {
×
57
                        $types[$i] = new Type($type->getBuiltinType(), $type->isNullable(), $type->getClassName(), true, $type->getCollectionKeyTypes(), $type->getCollectionValueTypes());
×
58
                    }
59
                }
60

61
                $propertyMetadata = $propertyMetadata->withBuiltinTypes($types);
×
62
            }
63
        } else {
64
            if (!$propertyMetadata->getNativeType()) {
231✔
65
                $propertyMetadata = $propertyMetadata->withNativeType($this->propertyInfo->getType($resourceClass, $property, $options));
231✔
66
            }
67
        }
68

69
        if (null === $propertyMetadata->getDescription() && null !== $description = $this->propertyInfo->getShortDescription($resourceClass, $property, $options)) {
231✔
70
            $propertyMetadata = $propertyMetadata->withDescription($description);
42✔
71
        }
72

73
        if (null === $propertyMetadata->isReadable() && null !== $readable = $this->propertyInfo->isReadable($resourceClass, $property, $options)) {
231✔
74
            $propertyMetadata = $propertyMetadata->withReadable($readable);
231✔
75
        }
76

77
        // A property might not be writable and we can still want to update it,
78
        // this leaves the choice to the SerializerPropertyMetadataFactory
79
        if (false === ($options['api_allow_update'] ?? false) && null === $propertyMetadata->isWritable() && null !== $writable = $this->propertyInfo->isWritable($resourceClass, $property, $options)) {
231✔
80
            $propertyMetadata = $propertyMetadata->withWritable($writable);
229✔
81
        }
82

83
        /* @phpstan-ignore-next-line */
84
        if (null === $propertyMetadata->isInitializable() && null !== $initializable = $this->propertyInfo->isInitializable($resourceClass, $property, $options)) {
231✔
85
            $propertyMetadata = $propertyMetadata->withInitializable($initializable);
231✔
86
        }
87

88
        return $propertyMetadata;
231✔
89
    }
90
}
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

© 2026 Coveralls, Inc