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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

0 of 2 new or added lines in 1 file covered. (0.0%)

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

91.67
/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
    {
UNCOV
32
    }
271✔
33

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

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

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

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

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

UNCOV
68
            if (!$doctrineMetadata->isAssociationInverseSide($property)) {
8✔
UNCOV
69
                continue;
7✔
70
            }
71

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

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

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

UNCOV
86
        return $links;
17✔
87
    }
88

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

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