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

api-platform / core / 10367357205

13 Aug 2024 09:38AM UTC coverage: 7.027% (-0.8%) from 7.84%
10367357205

push

github

soyuka
chore: align dependencies across components

11371 of 161813 relevant lines covered (7.03%)

22.93 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,248✔
32

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

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

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

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

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

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

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

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

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