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

api-platform / core / 17582447659

09 Sep 2025 12:23PM UTC coverage: 22.592% (-0.01%) from 22.604%
17582447659

push

github

web-flow
fix(jsonld): various json streamer fixes (#7374)

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

27 existing lines in 9 files now uncovered.

12071 of 53430 relevant lines covered (22.59%)

13.33 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
    }
4✔
31

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

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

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

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

51
        /** @var HttpOperation $op */
52
        $op = $this->resourceMetadataCollectionFactory->create($currentClass)->getOperation(httpOperation: true);
2✔
53

54
        return $this->getOperationType($op);
2✔
55
    }
56

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

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

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