• 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

83.33
/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 ApiPlatform\State\Util\StateOptionsTrait;
25
use Doctrine\ORM\EntityManagerInterface;
26
use Doctrine\Persistence\ManagerRegistry;
27
use Psr\Container\ContainerInterface;
28

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

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

51
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable
52
    {
UNCOV
53
        $entityClass = $this->getStateOptionsClass($operation, $operation->getClass(), Options::class);
104✔
54

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

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

UNCOV
63
        $queryBuilder = $repository->createQueryBuilder('o');
104✔
UNCOV
64
        $queryNameGenerator = new QueryNameGenerator();
104✔
65

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

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

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

80
        return $queryBuilder->getQuery()->getResult();
×
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