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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

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

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 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
    }
708✔
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);
166✔
39

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

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

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

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

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

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

62
                break;
×
63
            }
64
        }
65

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

UNCOV
70
        return $propertyMetadata;
132✔
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

© 2025 Coveralls, Inc