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

PageMiddleware::getSubscribedServices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
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\Page;
6
use Silverback\ApiComponentBundle\Repository\LayoutRepository;
7
8
class PageMiddleware extends AbstractMiddleware
9
{
10
    public function process($page, array $context = array())
11
    {
12
        /** @var LayoutRepository $repository */
13
        $repository = $this->container->get(LayoutRepository::class);
14
        $page->setLayout($repository->findOneBy(['default' => true]));
15
    }
16
17
    public function supportsData($data): bool
18
    {
19
        return $data instanceof Page && !$data->getLayout();
20
    }
21
22
    public static function getSubscribedServices(): array
23
    {
24
        return [
25
            '?' . LayoutRepository::class
26
        ];
27
    }
28
}
29