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

api-platform / core / 19799301771

30 Nov 2025 01:04PM UTC coverage: 25.229% (-0.03%) from 25.257%
19799301771

push

github

web-flow
fix(metadata): repeatable attribute mutators (#7542)

14557 of 57700 relevant lines covered (25.23%)

28.11 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 = isset($options['data']) && \is_object($options['data']) ? $options['data']::class : null;
8✔
39
        if (($currentClass = $options['_current_object']::class) === $dataClass) {
8✔
40
            if (!isset($options['operation'])) {
6✔
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✔
48
            return null;
×
49
        }
50

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

54
        return $this->getOperationType($op);
4✔
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)) {
8✔
65
            return $operation->getTypes()[0];
2✔
66
        }
67

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