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

DynamicPageMiddleware::supportsData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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 Silverback\ApiComponentBundle\Entity\Content\Page\Dynamic\AbstractDynamicPage;
6
use Silverback\ApiComponentBundle\Repository\ComponentLocationRepository;
7
8
class DynamicPageMiddleware extends AbstractMiddleware
9
{
10
    public function process($page, array $context = array())
11
    {
12
        /** @var ComponentLocationRepository $repository */
13
        $repository = $this->container->get(ComponentLocationRepository::class);
14
        $locations = $repository->findByDynamicPage($page);
15
        if (!empty($locations)) {
16
            $page->setComponentLocations($locations);
17
        }
18
    }
19
20
    public function supportsData($data): bool
21
    {
22
        return $data instanceof AbstractDynamicPage;
23
    }
24
25
    public static function getSubscribedServices(): array
26
    {
27
        return [
28
            '?' . ComponentLocationRepository::class
29
        ];
30
    }
31
}
32