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

api-platform / core / 15955912273

29 Jun 2025 01:51PM UTC coverage: 22.057% (-0.03%) from 22.082%
15955912273

Pull #7249

github

web-flow
Merge d9904d788 into a42034dc3
Pull Request #7249: chore: solve some phpstan issues

0 of 9 new or added lines in 8 files covered. (0.0%)

11540 existing lines in 372 files now uncovered.

11522 of 52237 relevant lines covered (22.06%)

11.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
    {
UNCOV
32
    }
292✔
33

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

49
        // TODO: remove in 5.x
UNCOV
50
        if (!method_exists(PropertyInfoExtractor::class, 'getType')) {
85✔
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 {
UNCOV
64
            if (!$propertyMetadata->getNativeType()) {
85✔
UNCOV
65
                $propertyMetadata = $propertyMetadata->withNativeType($this->propertyInfo->getType($resourceClass, $property, $options));
85✔
66
            }
67
        }
68

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

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

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

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

UNCOV
86
        return $propertyMetadata;
85✔
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

© 2026 Coveralls, Inc