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

api-platform / core / 16050929464

03 Jul 2025 12:51PM UTC coverage: 22.065% (+0.2%) from 21.821%
16050929464

push

github

soyuka
chore: todo improvement

11516 of 52192 relevant lines covered (22.06%)

22.08 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
    }
590✔
33

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

49
        // TODO: remove in 5.x
50
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
172✔
51
            if (!$propertyMetadata->getBuiltinTypes()) {
×
52
                $types = $this->propertyInfo->getTypes($resourceClass, $property, $options) ?? [];
×
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()) {
172✔
65
                $propertyMetadata = $propertyMetadata->withNativeType($this->propertyInfo->getType($resourceClass, $property, $options));
172✔
66
            }
67
        }
68

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

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

77
        if (null === $propertyMetadata->isWritable() && null !== $writable = $this->propertyInfo->isWritable($resourceClass, $property, $options)) {
172✔
78
            $propertyMetadata = $propertyMetadata->withWritable($writable);
172✔
79
        }
80

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

86
        return $propertyMetadata;
172✔
87
    }
88
}
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