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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

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

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

100.0
/src/Hydra/Serializer/EntrypointNormalizer.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\Hydra\Serializer;
15

16
use ApiPlatform\Documentation\Entrypoint;
17
use ApiPlatform\Metadata\CollectionOperationInterface;
18
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
19
use ApiPlatform\Metadata\Exception\OperationNotFoundException;
20
use ApiPlatform\Metadata\IriConverterInterface;
21
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
22
use ApiPlatform\Metadata\UrlGeneratorInterface;
23
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
24

25
/**
26
 * Normalizes the API entrypoint.
27
 *
28
 * @author Kévin Dunglas <dunglas@gmail.com>
29
 */
30
final class EntrypointNormalizer implements NormalizerInterface
31
{
32
    public const FORMAT = 'jsonld';
33

34
    public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory, private readonly IriConverterInterface $iriConverter, private readonly UrlGeneratorInterface $urlGenerator)
35
    {
UNCOV
36
    }
950✔
37

38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function normalize(mixed $object, ?string $format = null, array $context = []): array
42
    {
UNCOV
43
        $entrypoint = [
7✔
UNCOV
44
            '@context' => $this->urlGenerator->generate('api_jsonld_context', ['shortName' => 'Entrypoint']),
7✔
UNCOV
45
            '@id' => $this->urlGenerator->generate('api_entrypoint'),
7✔
UNCOV
46
            '@type' => 'Entrypoint',
7✔
UNCOV
47
        ];
7✔
48

UNCOV
49
        foreach ($object->getResourceNameCollection() as $resourceClass) {
7✔
UNCOV
50
            $resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
7✔
51

UNCOV
52
            foreach ($resourceMetadata as $resource) {
7✔
UNCOV
53
                if ($resource->getExtraProperties()['is_alternate_resource_metadata'] ?? false) {
7✔
UNCOV
54
                    continue;
6✔
55
                }
56

UNCOV
57
                foreach ($resource->getOperations() as $operation) {
7✔
UNCOV
58
                    $key = lcfirst($resource->getShortName());
7✔
UNCOV
59
                    if (true === $operation->getHideHydraOperation() || !$operation instanceof CollectionOperationInterface || isset($entrypoint[$key])) {
7✔
UNCOV
60
                        continue;
7✔
61
                    }
62

63
                    try {
UNCOV
64
                        $entrypoint[$key] = $this->iriConverter->getIriFromResource($resourceClass, UrlGeneratorInterface::ABS_PATH, $operation); // @phpstan-ignore-line phpstan issue as type is CollectionOperationInterface & Operation
6✔
65
                    } catch (InvalidArgumentException|OperationNotFoundException) {
1✔
66
                        // Ignore resources without GET operations
67
                    }
68
                }
69
            }
70
        }
71

UNCOV
72
        ksort($entrypoint);
7✔
73

UNCOV
74
        return $entrypoint;
7✔
75
    }
76

77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
81
    {
UNCOV
82
        return self::FORMAT === $format && $data instanceof Entrypoint;
7✔
83
    }
84

85
    public function getSupportedTypes($format): array
86
    {
UNCOV
87
        return self::FORMAT === $format ? [Entrypoint::class => true] : [];
865✔
88
    }
89
}
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

© 2025 Coveralls, Inc