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

api-platform / core / 10972028624

21 Sep 2024 11:01AM UTC coverage: 7.833% (-0.001%) from 7.834%
10972028624

push

github

dunglas
Merge branch '3.4' into 4.0

12915 of 164879 relevant lines covered (7.83%)

27.03 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
    {
31
    }
2,687✔
32

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

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

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

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

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

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

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

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

78
        return $propertyMetadata;
676✔
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

© 2026 Coveralls, Inc