• 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

95.83
/src/Doctrine/Orm/Metadata/Resource/DoctrineOrmLinkFactory.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\Resource;
15

16
use ApiPlatform\Metadata\Link;
17
use ApiPlatform\Metadata\Metadata;
18
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
19
use ApiPlatform\Metadata\Resource\Factory\LinkFactoryInterface;
20
use ApiPlatform\Metadata\Resource\Factory\PropertyLinkFactoryInterface;
21
use ApiPlatform\Metadata\ResourceClassResolverInterface;
22
use Doctrine\ORM\EntityManagerInterface;
23
use Doctrine\Persistence\ManagerRegistry;
24

25
/**
26
 * @internal
27
 */
28
final class DoctrineOrmLinkFactory implements LinkFactoryInterface, PropertyLinkFactoryInterface
29
{
30
    public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory, private readonly ResourceClassResolverInterface $resourceClassResolver, private readonly LinkFactoryInterface&PropertyLinkFactoryInterface $linkFactory)
31
    {
32
    }
1,345✔
33

34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function createLinkFromProperty(Metadata $operation, string $property): Link
38
    {
UNCOV
39
        return $this->linkFactory->createLinkFromProperty($operation, $property);
1✔
40
    }
41

42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function createLinksFromIdentifiers(Metadata $operation): array
46
    {
47
        return $this->linkFactory->createLinksFromIdentifiers($operation);
101✔
48
    }
49

50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function createLinksFromRelations(Metadata $operation): array
54
    {
55
        $links = $this->linkFactory->createLinksFromRelations($operation);
85✔
56

57
        $resourceClass = $operation->getClass();
85✔
58
        if (!($manager = $this->managerRegistry->getManagerForClass($resourceClass)) instanceof EntityManagerInterface) {
85✔
59
            return $links;
32✔
60
        }
61

62
        foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $property) {
59✔
63
            $doctrineMetadata = $manager->getClassMetadata($resourceClass);
59✔
64
            if (!$doctrineMetadata->hasAssociation($property)) {
59✔
65
                continue;
59✔
66
            }
67

68
            if (!$doctrineMetadata->isAssociationInverseSide($property)) {
30✔
69
                continue;
28✔
70
            }
71

72
            if (!($mappedBy = $doctrineMetadata->getAssociationMappedByTargetField($property))) {
19✔
73
                continue;
×
74
            }
75

76
            $relationClass = $doctrineMetadata->getAssociationTargetClass($property);
19✔
77
            if (!$this->resourceClassResolver->isResourceClass($relationClass)) {
19✔
78
                continue;
9✔
79
            }
80

81
            $link = new Link(fromProperty: $property, toProperty: $mappedBy, fromClass: $resourceClass, toClass: $relationClass);
11✔
82
            $link = $this->completeLink($link);
11✔
83
            $links[] = $link;
11✔
84
        }
85

86
        return $links;
59✔
87
    }
88

89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function createLinksFromAttributes(Metadata $operation): array
93
    {
94
        return $this->linkFactory->createLinksFromAttributes($operation);
85✔
95
    }
96

97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function completeLink(Link $link): Link
101
    {
102
        return $this->linkFactory->completeLink($link);
44✔
103
    }
104
}
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