• 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

90.0
/src/Doctrine/Orm/State/CollectionProvider.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\State;
15

16
use ApiPlatform\Doctrine\Common\State\LinksHandlerLocatorTrait;
17
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
18
use ApiPlatform\Doctrine\Orm\Extension\QueryResultCollectionExtensionInterface;
19
use ApiPlatform\Doctrine\Orm\Util\QueryNameGenerator;
20
use ApiPlatform\Metadata\Exception\RuntimeException;
21
use ApiPlatform\Metadata\Operation;
22
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
23
use ApiPlatform\State\ProviderInterface;
24
use Doctrine\ORM\EntityManagerInterface;
25
use Doctrine\Persistence\ManagerRegistry;
26
use Psr\Container\ContainerInterface;
27

28
/**
29
 * Collection state provider using the Doctrine ORM.
30
 *
31
 * @author Kévin Dunglas <kevin@dunglas.fr>
32
 * @author Samuel ROZE <samuel.roze@gmail.com>
33
 */
34
final class CollectionProvider implements ProviderInterface
35
{
36
    use LinksHandlerLocatorTrait;
37
    use LinksHandlerTrait;
38

39
    /**
40
     * @param QueryCollectionExtensionInterface[] $collectionExtensions
41
     */
42
    public function __construct(ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, ManagerRegistry $managerRegistry, private readonly iterable $collectionExtensions = [], ?ContainerInterface $handleLinksLocator = null)
43
    {
44
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
507✔
45
        $this->handleLinksLocator = $handleLinksLocator;
507✔
46
        $this->managerRegistry = $managerRegistry;
507✔
47
    }
48

49
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
50
    {
51
        $entityClass = $operation->getClass();
503✔
52
        if (($options = $operation->getStateOptions()) && $options instanceof Options && $options->getEntityClass()) {
503✔
53
            $entityClass = $options->getEntityClass();
10✔
54
        }
55

56
        /** @var EntityManagerInterface $manager */
57
        $manager = $this->managerRegistry->getManagerForClass($entityClass);
503✔
58

59
        $repository = $manager->getRepository($entityClass);
503✔
60
        if (!method_exists($repository, 'createQueryBuilder')) {
503✔
61
            throw new RuntimeException('The repository class must have a "createQueryBuilder" method.');
×
62
        }
63

64
        $queryBuilder = $repository->createQueryBuilder('o');
503✔
65
        $queryNameGenerator = new QueryNameGenerator();
503✔
66

67
        if ($handleLinks = $this->getLinksHandler($operation)) {
503✔
68
            $handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, ['entityClass' => $entityClass, 'operation' => $operation] + $context);
503✔
69
        } else {
70
            $this->handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, $context, $entityClass, $operation);
×
71
        }
72

73
        foreach ($this->collectionExtensions as $extension) {
503✔
74
            $extension->applyToCollection($queryBuilder, $queryNameGenerator, $entityClass, $operation, $context);
503✔
75

76
            if ($extension instanceof QueryResultCollectionExtensionInterface && $extension->supportsResult($entityClass, $operation, $context)) {
503✔
77
                return $extension->getResult($queryBuilder, $entityClass, $operation, $context);
498✔
78
            }
79
        }
80

UNCOV
81
        return $queryBuilder->getQuery()->getResult();
3✔
82
    }
83
}
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