• 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

40.0
/src/Doctrine/Orm/PropertyHelperTrait.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;
15

16
use ApiPlatform\Doctrine\Orm\Util\QueryBuilderHelper;
17
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
18
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
19
use Doctrine\ORM\Mapping\ClassMetadata as ClassMetadataInfo;
20
use Doctrine\ORM\QueryBuilder;
21
use Doctrine\Persistence\ManagerRegistry;
22
use Doctrine\Persistence\Mapping\ClassMetadata;
23

24
/**
25
 * Helper trait regarding a property in an entity using the resource metadata.
26
 *
27
 * @author Kévin Dunglas <dunglas@gmail.com>
28
 * @author Théo FIDRY <theo.fidry@gmail.com>
29
 */
30
trait PropertyHelperTrait
31
{
32
    abstract protected function getManagerRegistry(): ?ManagerRegistry;
33

34
    /**
35
     * Splits the given property into parts.
36
     */
37
    abstract protected function splitPropertyParts(string $property, string $resourceClass): array;
38

39
    /**
40
     * Gets class metadata for the given resource.
41
     */
42
    protected function getClassMetadata(string $resourceClass): ClassMetadata
43
    {
UNCOV
44
        $manager = $this
228✔
UNCOV
45
            ->getManagerRegistry()
228✔
UNCOV
46
            ->getManagerForClass($resourceClass);
228✔
47

UNCOV
48
        if ($manager) {
228✔
UNCOV
49
            return $manager->getClassMetadata($resourceClass);
96✔
50
        }
51

52
        return new ClassMetadataInfo($resourceClass);
133✔
53
    }
54

55
    /**
56
     * Adds the necessary joins for a nested property.
57
     *
58
     * @throws InvalidArgumentException If property is not nested
59
     *
60
     * @return array An array where the first element is the join $alias of the leaf entity,
61
     *               the second element is the $field name
62
     *               the third element is the $associations array
63
     */
64
    protected function addJoinsForNestedProperty(string $property, string $rootAlias, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $resourceClass, string $joinType): array
65
    {
66
        $propertyParts = $this->splitPropertyParts($property, $resourceClass);
×
67
        $parentAlias = $rootAlias;
×
68
        $alias = null;
×
69

70
        foreach ($propertyParts['associations'] as $association) {
×
71
            $alias = QueryBuilderHelper::addJoinOnce($queryBuilder, $queryNameGenerator, $parentAlias, $association, $joinType);
×
72
            $parentAlias = $alias;
×
73
        }
74

75
        if (null === $alias) {
×
76
            throw new InvalidArgumentException(\sprintf('Cannot add joins for property "%s" - property is not nested.', $property));
×
77
        }
78

79
        return [$alias, $propertyParts['field'], $propertyParts['associations']];
×
80
    }
81
}
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