Passed
Push — feature/uploadable ( 83c8f5...1b5232 )
by Daniel
13:05
created

RouteDataProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A supports() 0 3 1
A getItem() 0 3 1
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\DataProvider\Item;
15
16
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
17
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
18
use Silverback\ApiComponentsBundle\Entity\Core\Route;
19
use Silverback\ApiComponentsBundle\Repository\Core\RouteRepository;
20
21
/**
22
 * @author Daniel West <[email protected]>
23
 */
24
class RouteDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface
25
{
26
    private RouteRepository $routeRepository;
27
28 2
    public function __construct(RouteRepository $routeRepository)
29
    {
30 2
        $this->routeRepository = $routeRepository;
31 2
    }
32
33 1
    public function getItem(string $resourceClass, $id, string $operationName = null, array $context = [])
34
    {
35 1
        return $this->routeRepository->findOneByIdOrRoute($id);
36
    }
37
38 1
    public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
39
    {
40 1
        return Route::class === $resourceClass;
41
    }
42
}
43