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

DynamicPageMiddleware   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 21
ccs 0
cts 10
cp 0
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 7 2
A getSubscribedServices() 0 4 1
A supportsData() 0 3 1
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