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

api-platform / core / 16705318661

03 Aug 2025 01:05PM UTC coverage: 0.0% (-21.9%) from 21.944%
16705318661

Pull #7317

github

web-flow
Merge 1ca8642ff into d06b1a0a0
Pull Request #7317: Fix/4372 skip null values in hal

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

11680 existing lines in 376 files now uncovered.

0 of 51817 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/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
×
UNCOV
45
            ->getManagerRegistry()
×
UNCOV
46
            ->getManagerForClass($resourceClass);
×
47

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

52
        return new ClassMetadataInfo($resourceClass);
×
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