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

api-platform / core / 14954769666

11 May 2025 10:14AM UTC coverage: 0.0% (-8.5%) from 8.457%
14954769666

Pull #7135

github

web-flow
Merge bf21e0bc7 into 4dd0cdfc4
Pull Request #7135: fix(symfony,laravel): InvalidUriVariableException status code (e400)

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

11040 existing lines in 370 files now uncovered.

0 of 48303 relevant lines covered (0.0%)

0.0 hits per line

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

0.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 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;
×
UNCOV
47
        $this->handleLinksLocator = $handleLinksLocator;
×
UNCOV
48
        $this->managerRegistry = $managerRegistry;
×
49
    }
50

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

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

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

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

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

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

UNCOV
75
            if ($extension instanceof QueryResultCollectionExtensionInterface && $extension->supportsResult($entityClass, $operation, $context)) {
×
UNCOV
76
                return $extension->getResult($queryBuilder, $entityClass, $operation, $context);
×
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