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

api-platform / core / 10729306835

05 Sep 2024 10:46PM UTC coverage: 7.655% (-0.01%) from 7.665%
10729306835

push

github

web-flow
Merge pull request #6586 from soyuka/merge-342

Merge 3.4

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

8760 existing lines in 277 files now uncovered.

12505 of 163357 relevant lines covered (7.66%)

22.84 hits per line

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

89.47
/src/Doctrine/Odm/Metadata/Property/DoctrineMongoDbOdmPropertyMetadataFactory.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\Odm\Metadata\Property;
15

16
use ApiPlatform\Metadata\ApiProperty;
17
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
18
use Doctrine\ODM\MongoDB\DocumentManager;
19
use Doctrine\Persistence\ManagerRegistry;
20

21
/**
22
 * Use Doctrine metadata to populate the identifier property.
23
 *
24
 * @author Kévin Dunglas <dunglas@gmail.com>
25
 * @author Alan Poulain <contact@alanpoulain.eu>
26
 */
27
final class DoctrineMongoDbOdmPropertyMetadataFactory implements PropertyMetadataFactoryInterface
28
{
29
    public function __construct(private readonly ManagerRegistry $managerRegistry, private readonly PropertyMetadataFactoryInterface $decorated)
30
    {
UNCOV
31
    }
1,408✔
32

33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function create(string $resourceClass, string $property, array $options = []): ApiProperty
37
    {
UNCOV
38
        $propertyMetadata = $this->decorated->create($resourceClass, $property, $options);
320✔
39

UNCOV
40
        if (null !== $propertyMetadata->isIdentifier()) {
320✔
UNCOV
41
            return $propertyMetadata;
8✔
42
        }
43

UNCOV
44
        $manager = $this->managerRegistry->getManagerForClass($resourceClass);
320✔
UNCOV
45
        if (!$manager instanceof DocumentManager) {
320✔
UNCOV
46
            return $propertyMetadata;
78✔
47
        }
48

UNCOV
49
        $doctrineClassMetadata = $manager->getClassMetadata($resourceClass);
256✔
UNCOV
50
        $identifiers = $doctrineClassMetadata->getIdentifier();
256✔
51

UNCOV
52
        foreach ($identifiers as $identifier) {
256✔
UNCOV
53
            if ($identifier === $property) {
256✔
UNCOV
54
                $propertyMetadata = $propertyMetadata->withIdentifier(true);
188✔
55

UNCOV
56
                if (null !== $propertyMetadata->isWritable()) {
188✔
UNCOV
57
                    break;
188✔
58
                }
59

60
                $propertyMetadata = $propertyMetadata->withWritable(false);
×
61

62
                break;
×
63
            }
64
        }
65

UNCOV
66
        if (null === $propertyMetadata->isIdentifier()) {
256✔
UNCOV
67
            $propertyMetadata = $propertyMetadata->withIdentifier(false);
254✔
68
        }
69

UNCOV
70
        return $propertyMetadata;
256✔
71
    }
72
}
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

© 2026 Coveralls, Inc