• 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

92.31
/src/Symfony/Routing/SkolemIriConverter.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\Symfony\Routing;
15

16
use ApiPlatform\Metadata\Exception\ItemNotFoundException;
17
use ApiPlatform\Metadata\IriConverterInterface;
18
use ApiPlatform\Metadata\Operation;
19
use ApiPlatform\Metadata\UrlGeneratorInterface;
20
use Symfony\Component\Routing\RouterInterface;
21

22
/**
23
 * {@inheritdoc}
24
 *
25
 * @author Antoine Bluchet <soyuka@gmail.com>
26
 */
27
final class SkolemIriConverter implements IriConverterInterface
28
{
29
    public static $skolemUriTemplate = '/.well-known/genid/{id}';
30

31
    private $objectHashMap;
32
    private $classHashMap = [];
33
    private $router;
34

35
    public function __construct(RouterInterface $router)
36
    {
UNCOV
37
        $this->router = $router;
952✔
UNCOV
38
        $this->objectHashMap = new \SplObjectStorage();
952✔
39
    }
40

41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getResourceFromIri(string $iri, array $context = [], ?Operation $operation = null): object
45
    {
46
        throw new ItemNotFoundException(\sprintf('Item not found for "%s".', $iri));
×
47
    }
48

49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getIriFromResource(object|string $resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): ?string
53
    {
UNCOV
54
        $referenceType = $operation ? ($operation->getUrlGenerationStrategy() ?? $referenceType) : $referenceType;
81✔
UNCOV
55
        if (($isObject = \is_object($resource)) && $this->objectHashMap->contains($resource)) {
81✔
UNCOV
56
            return $this->router->generate('api_genid', ['id' => $this->objectHashMap[$resource]], $referenceType);
15✔
57
        }
58

UNCOV
59
        if (\is_string($resource) && isset($this->classHashMap[$resource])) {
81✔
UNCOV
60
            return $this->router->generate('api_genid', ['id' => $this->classHashMap[$resource]], $referenceType);
4✔
61
        }
62

UNCOV
63
        $id = bin2hex(random_bytes(10));
81✔
64

UNCOV
65
        if ($isObject) {
81✔
UNCOV
66
            $this->objectHashMap[$resource] = $id;
51✔
67
        } else {
UNCOV
68
            $this->classHashMap[$resource] = $id;
31✔
69
        }
70

UNCOV
71
        return $this->router->generate('api_genid', ['id' => $id], $referenceType);
81✔
72
    }
73
}
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