Completed
Pull Request — master (#472)
by Théo
03:07
created

ItemDataProvider::getItem()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 5
nc 2
nop 4
1
<?php
2
3
/*
4
 *  This file is part of the API Platform project.
5
 *
6
 *  (c) Kévin Dunglas <[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
namespace ApiPlatform\Core\Http;
13
14
use ApiPlatform\Core\Api\ItemDataProviderInterface;
15
use ApiPlatform\Core\Exception\ExceptionInterface;
16
use ApiPlatform\Core\Exception\InvalidArgumentException;
17
use ApiPlatform\Core\Exception\NotFoundHttpException;
18
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
19
20
/**
21
 * @author Théo FIDRY <[email protected]>
22
 */
23
final class ItemDataProvider implements ItemDataProviderInterface
24
{
25
    /**
26
     * @var ItemDataProviderInterface
27
     */
28
    private $decoratedProvider;
29
30
    public function __construct(ItemDataProviderInterface $decoratedProvider)
31
    {
32
        $this->decoratedProvider = $decoratedProvider;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     *
38
     * @throws ResourceClassNotSupportedException
39
     * @throws NotFoundHttpException
40
     * @throws ExceptionInterface
41
     */
42
    public function getItem(string $resourceClass, $id, string $operationName = null, bool $fetchData = false)
43
    {
44
        $data = $this->decoratedProvider->getItem($resourceClass, $id, $operationName, true);
45
        if (null !== $data) {
46
            return $data;
47
        }
48
49
        throw new NotFoundHttpException('Not Found');
50
    }
51
}
52