• 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

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
    ) {
UNCOV
30
    }
8✔
31

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

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

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

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

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

UNCOV
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
    {
UNCOV
64
        if (($t = $operation->getTypes()) && 1 === \count($t)) {
8✔
UNCOV
65
            return $operation->getTypes()[0];
2✔
66
        }
67

UNCOV
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