Passed
Push — develop ( b22678...97e476 )
by Daniel
08:45
created

CollectionMiddleware::getSubscribedServices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Serializer\Middleware;
4
5
use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface;
6
use Silverback\ApiComponentBundle\Entity\Component\Collection\Collection;
7
use Symfony\Component\HttpFoundation\Request;
8
9
class CollectionMiddleware extends AbstractMiddleware
10
{
11
    public function process($collectionEntity, array $context = array())
12
    {
13
        /** @var ContextAwareCollectionDataProviderInterface $dataProvider */
14
        $dataProvider = $this->container->get(ContextAwareCollectionDataProviderInterface::class);
15
        $dataProviderContext = [];
16
        $collection = $dataProvider->getCollection($collectionEntity->getResource(), Request::METHOD_GET, $dataProviderContext);
17
        $collectionEntity->setCollection($collection);
18
    }
19
20
    public function supportsData($data): bool
21
    {
22
        return $data instanceof Collection;
23
    }
24
25
    public static function getSubscribedServices(): array
26
    {
27
        return [
28
            '?' . ContextAwareCollectionDataProviderInterface::class
29
        ];
30
    }
31
}
32