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

api-platform / core / 13814792797

12 Mar 2025 03:09PM UTC coverage: 5.889% (-1.4%) from 7.289%
13814792797

Pull #7012

github

web-flow
Merge 199d44919 into 284937039
Pull Request #7012: doc: comment typo in ApiResource.php

10048 of 170615 relevant lines covered (5.89%)

5.17 hits per line

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

0.0
/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
    {
31
    }
×
32

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

40
        if (null !== $propertyMetadata->isIdentifier()) {
×
41
            return $propertyMetadata;
×
42
        }
43

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

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

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

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

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

62
                break;
×
63
            }
64
        }
65

66
        if (null === $propertyMetadata->isIdentifier()) {
×
67
            $propertyMetadata = $propertyMetadata->withIdentifier(false);
×
68
        }
69

70
        return $propertyMetadata;
×
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