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

api-platform / core / 17581523433

09 Sep 2025 11:44AM UTC coverage: 22.649% (+0.05%) from 22.604%
17581523433

Pull #7374

github

web-flow
Merge 73027e07a into 6db55be8c
Pull Request #7374: fix(jsonld): various json streamer fixes

33 of 35 new or added lines in 2 files covered. (94.29%)

1 existing line in 1 file now uncovered.

12098 of 53416 relevant lines covered (22.65%)

26.45 hits per line

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

81.25
/src/JsonLd/JsonStreamer/ValueTransformer/TypeValueTransformer.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\ValueTransformer;
15

16
use ApiPlatform\Hydra\Collection;
17
use ApiPlatform\Metadata\Exception\RuntimeException;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\Metadata\ResourceClassResolverInterface;
21
use Symfony\Component\JsonStreamer\ValueTransformer\ValueTransformerInterface;
22
use Symfony\Component\TypeInfo\Type;
23

24
final class TypeValueTransformer implements ValueTransformerInterface
25
{
26
    public function __construct(
27
        private readonly ResourceClassResolverInterface $resourceClassResolver,
28
        private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory,
29
    ) {
30
    }
8✔
31

32
    public function transform(mixed $value, array $options = []): mixed
33
    {
34
        if ($options['_current_object'] instanceof Collection) {
8✔
35
            return 'Collection';
2✔
36
        }
37

38
        $dataClass = \is_object($options['data']) ? $options['data']::class : null;
8✔
39
        if (($currentClass = $options['_current_object']::class) === $dataClass) {
8✔
40
            if (!isset($options['operation'])) {
6✔
NEW
41
                throw new RuntimeException('Operation is not defined');
×
42
            }
43

44
            return $this->getOperationType($options['operation']);
6✔
45
        }
46

47
        if (!$this->resourceClassResolver->isResourceClass($currentClass)) {
4✔
NEW
48
            return null;
×
49
        }
50

51
        $op = $this->resourceMetadataCollectionFactory->create($currentClass)->getOperation(httpOperation: true);
4✔
52

53
        return $this->getOperationType($op);
4✔
54
    }
55

56
    public static function getStreamValueType(): Type
57
    {
UNCOV
58
        return Type::string();
×
59
    }
60

61
    private function getOperationType(HttpOperation $operation): array|string
62
    {
63
        if (($t = $operation->getTypes()) && 1 === \count($t)) {
8✔
64
            return $operation->getTypes()[0];
2✔
65
        }
66

67
        return $t ?: $operation->getShortname();
6✔
68
    }
69
}
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