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

PageMiddleware::supportsData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
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