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

api-platform / core / 20847864477

09 Jan 2026 09:47AM UTC coverage: 29.1% (+0.005%) from 29.095%
20847864477

Pull #7649

github

web-flow
Merge b342dd5db into d640d106b
Pull Request #7649: feat(validator): uuid/ulid parameter validation

0 of 4 new or added lines in 1 file covered. (0.0%)

15050 existing lines in 491 files now uncovered.

16996 of 58406 relevant lines covered (29.1%)

81.8 hits per line

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

100.0
/src/JsonLd/JsonStreamer/WritePropertyMetadataLoader.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\JsonLd\JsonStreamer;
15

16
use ApiPlatform\Hydra\Collection;
17
use ApiPlatform\Hydra\IriTemplate;
18
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
19
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
20
use ApiPlatform\Metadata\ResourceClassResolverInterface;
21
use ApiPlatform\Metadata\Util\TypeHelper;
22
use Symfony\Component\JsonStreamer\Mapping\PropertyMetadata;
23
use Symfony\Component\JsonStreamer\Mapping\PropertyMetadataLoaderInterface;
24
use Symfony\Component\TypeInfo\Type;
25

26
final class WritePropertyMetadataLoader implements PropertyMetadataLoaderInterface
27
{
28
    public function __construct(
29
        private readonly PropertyMetadataLoaderInterface $loader,
30
        private readonly ResourceClassResolverInterface $resourceClassResolver,
31
        private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory,
32
        private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory,
33
    ) {
UNCOV
34
    }
2,008✔
35

36
    public function load(string $className, array $options = [], array $context = []): array
37
    {
UNCOV
38
        $properties = $this->loader->load($className, $options, $context);
6✔
39

UNCOV
40
        if (IriTemplate::class === $className) {
6✔
UNCOV
41
            return $properties;
2✔
42
        }
43

UNCOV
44
        if (Collection::class !== $className && !$this->resourceClassResolver->isResourceClass($className)) {
6✔
UNCOV
45
            return $properties;
2✔
46
        }
47

UNCOV
48
        $originalClassName = TypeHelper::getClassName($context['original_type']);
6✔
UNCOV
49
        $hasIri = true;
6✔
UNCOV
50
        $virtualProperty = 'id';
6✔
51

UNCOV
52
        foreach ($this->propertyNameCollectionFactory->create($originalClassName) as $property) {
6✔
UNCOV
53
            $propertyMetadata = $this->propertyMetadataFactory->create($originalClassName, $property);
6✔
UNCOV
54
            if ($propertyMetadata->isIdentifier()) {
6✔
UNCOV
55
                $virtualProperty = $property;
6✔
56
            }
57

UNCOV
58
            if ($className === $originalClassName) {
6✔
UNCOV
59
                continue;
6✔
60
            }
61

UNCOV
62
            if ($propertyMetadata->getNativeType()->isIdentifiedBy($className)) {
4✔
UNCOV
63
                $hasIri = $propertyMetadata->getGenId();
2✔
UNCOV
64
                $virtualProperty = iterator_to_array($this->propertyNameCollectionFactory->create($className))[0];
2✔
65
            }
66
        }
67

UNCOV
68
        if ($hasIri) {
6✔
UNCOV
69
            $properties['@id'] = new PropertyMetadata(
6✔
UNCOV
70
                $virtualProperty, // virtual property
6✔
UNCOV
71
                Type::mixed(), // virtual property
6✔
UNCOV
72
                ['api_platform.jsonld.json_streamer.write.value_transformer.iri'],
6✔
UNCOV
73
            );
6✔
74
        }
75

UNCOV
76
        $properties['@type'] = new PropertyMetadata(
6✔
UNCOV
77
            $virtualProperty, // virtual property
6✔
UNCOV
78
            Type::mixed(), // virtual property
6✔
UNCOV
79
            ['api_platform.jsonld.json_streamer.write.value_transformer.type'],
6✔
UNCOV
80
        );
6✔
81

UNCOV
82
        if ($className !== $originalClassName) {
6✔
UNCOV
83
            return $properties;
4✔
84
        }
85

UNCOV
86
        if (Collection::class === $originalClassName || ($this->resourceClassResolver->isResourceClass($originalClassName) && !isset($context['generated_classes'][Collection::class]))) {
6✔
UNCOV
87
            $properties['@context'] = new PropertyMetadata(
6✔
UNCOV
88
                $virtualProperty, // virual property
6✔
UNCOV
89
                Type::string(), // virtual property
6✔
UNCOV
90
                ['api_platform.jsonld.json_streamer.write.value_transformer.context'],
6✔
UNCOV
91
            );
6✔
92
        }
93

UNCOV
94
        return $properties;
6✔
95
    }
96
}
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