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

api-platform / core / 14008635868

22 Mar 2025 12:39PM UTC coverage: 8.52% (+0.005%) from 8.515%
14008635868

Pull #7042

github

web-flow
Merge fdd88ef56 into 47a6dffbb
Pull Request #7042: Purge parent collections in inheritance cases

4 of 9 new or added lines in 1 file covered. (44.44%)

540 existing lines in 57 files now uncovered.

13394 of 157210 relevant lines covered (8.52%)

22.93 hits per line

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

76.0
/src/Doctrine/Orm/Metadata/Property/DoctrineOrmPropertyMetadataFactory.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\Doctrine\Orm\Metadata\Property;
15

16
use ApiPlatform\Metadata\ApiProperty;
17
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
18
use Doctrine\ORM\Mapping\ClassMetadata;
19
use Doctrine\ORM\Mapping\FieldMapping;
20
use Doctrine\Persistence\ManagerRegistry;
21

22
/**
23
 * Use Doctrine metadata to populate the identifier property.
24
 *
25
 * @author Kévin Dunglas <dunglas@gmail.com>
26
 */
27
final class DoctrineOrmPropertyMetadataFactory implements PropertyMetadataFactoryInterface
28
{
29
    public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly PropertyMetadataFactoryInterface $decorated)
30
    {
31
    }
1,345✔
32

33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function create(string $resourceClass, string $property, array $options = []): ApiProperty
37
    {
38
        $propertyMetadata = $this->decorated->create($resourceClass, $property, $options);
346✔
39

40
        if (null !== $propertyMetadata->isIdentifier()) {
346✔
UNCOV
41
            return $propertyMetadata;
4✔
42
        }
43

44
        $manager = $this->managerRegistry->getManagerForClass($resourceClass);
346✔
45
        if (!$manager) {
346✔
46
            return $propertyMetadata;
156✔
47
        }
48
        $doctrineClassMetadata = $manager->getClassMetadata($resourceClass);
224✔
49

50
        $identifiers = $doctrineClassMetadata->getIdentifier();
224✔
51
        foreach ($identifiers as $identifier) {
224✔
52
            if ($identifier === $property) {
224✔
53
                $propertyMetadata = $propertyMetadata->withIdentifier(true);
179✔
54

55
                if (null !== $propertyMetadata->isWritable()) {
179✔
56
                    break;
179✔
57
                }
58

59
                if ($doctrineClassMetadata instanceof ClassMetadata) {
×
60
                    $writable = $doctrineClassMetadata->isIdentifierNatural();
×
61
                } else {
62
                    $writable = false;
×
63
                }
64

65
                $propertyMetadata = $propertyMetadata->withWritable($writable);
×
66

67
                break;
×
68
            }
69
        }
70

71
        if ($doctrineClassMetadata instanceof ClassMetadata && \in_array($property, $doctrineClassMetadata->getFieldNames(), true)) {
224✔
72
            $fieldMapping = $doctrineClassMetadata->getFieldMapping($property);
213✔
73
            if (class_exists(FieldMapping::class) && $fieldMapping instanceof FieldMapping) {
213✔
74
                $propertyMetadata = $propertyMetadata->withDefault($fieldMapping->default ?? $propertyMetadata->getDefault());
213✔
75
            } else {
76
                $propertyMetadata = $propertyMetadata->withDefault($fieldMapping['options']['default'] ?? $propertyMetadata->getDefault());
×
77
            }
78
        }
79

80
        return $propertyMetadata;
224✔
81
    }
82
}
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