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

api-platform / core / 13200284839

07 Feb 2025 12:56PM UTC coverage: 0.0% (-8.2%) from 8.164%
13200284839

Pull #6952

github

web-flow
Merge 519fbf8cc into 62377f880
Pull Request #6952: fix: errors retrieval and documentation

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

10757 existing lines in 366 files now uncovered.

0 of 47781 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/ItemProvider.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\QueryItemExtensionInterface;
18
use ApiPlatform\Doctrine\Orm\Extension\QueryResultItemExtensionInterface;
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
 * Item 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 ItemProvider implements ProviderInterface
35
{
36
    use LinksHandlerLocatorTrait;
37
    use LinksHandlerTrait;
38

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

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

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

UNCOV
59
        $fetchData = $context['fetch_data'] ?? true;
×
UNCOV
60
        if (!$fetchData && \array_key_exists('id', $uriVariables)) {
×
61
            // todo : if uriVariables don't contain the id, this fails. This should behave like it does in the following code
62
            return $manager->getReference($entityClass, $uriVariables);
×
63
        }
64

UNCOV
65
        $repository = $manager->getRepository($entityClass);
×
UNCOV
66
        if (!method_exists($repository, 'createQueryBuilder')) {
×
67
            throw new RuntimeException('The repository class must have a "createQueryBuilder" method.');
×
68
        }
69

UNCOV
70
        $queryBuilder = $repository->createQueryBuilder('o');
×
UNCOV
71
        $queryNameGenerator = new QueryNameGenerator();
×
72

UNCOV
73
        if ($handleLinks = $this->getLinksHandler($operation)) {
×
UNCOV
74
            $handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, ['entityClass' => $entityClass, 'operation' => $operation] + $context);
×
75
        } else {
76
            $this->handleLinks($queryBuilder, $uriVariables, $queryNameGenerator, $context, $entityClass, $operation);
×
77
        }
78

UNCOV
79
        foreach ($this->itemExtensions as $extension) {
×
UNCOV
80
            $extension->applyToItem($queryBuilder, $queryNameGenerator, $entityClass, $uriVariables, $operation, $context);
×
81

UNCOV
82
            if ($extension instanceof QueryResultItemExtensionInterface && $extension->supportsResult($entityClass, $operation, $context)) {
×
83
                return $extension->getResult($queryBuilder, $entityClass, $operation, $context);
×
84
            }
85
        }
86

UNCOV
87
        return $queryBuilder->getQuery()->getOneOrNullResult();
×
88
    }
89
}
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