Test Failed
Push — main ( 991081...ce2270 )
by Daniel
17:15
created

IriConverter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getResourceFromIri() 0 3 1
A getIriFromResource() 0 7 3
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
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 Silverback\ApiComponentsBundle\ApiPlatform\Api;
15
16
use ApiPlatform\Api\IriConverterInterface;
17
use ApiPlatform\Api\UrlGeneratorInterface;
18
use ApiPlatform\Metadata\Operation;
19
use Silverback\ApiComponentsBundle\Entity\Core\Route;
20
21
/**
22
 * @author Daniel West <[email protected]>
23
 */
24
class IriConverter implements IriConverterInterface
25
{
26
    public function __construct(private IriConverterInterface $decorated)
27
    {
28
    }
29
30
    public function getResourceFromIri(string $iri, array $context = [], ?Operation $operation = null): object
31
    {
32
        return $this->decorated->getResourceFromIri($iri, $context, $operation);
33
    }
34
35
    public function getIriFromResource($resource, int $referenceType = UrlGeneratorInterface::ABS_PATH, ?Operation $operation = null, array $context = []): ?string
36
    {
37
        if ($resource instanceof Route && ($path = $resource->getPath())) {
38
            return '/_/routes/' . $path;
39
        }
40
41
        return $this->decorated->getIriFromResource($resource, $referenceType, $operation, $context);
42
    }
43
}
44