Completed
Push — master ( d7020d...a4700d )
by Daniel
06:50
created

PageDataTransformer::getSubscribedServices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\DataTransformer;
4
5
use Silverback\ApiComponentBundle\Entity\Content\Page\StaticPage;
6
use Silverback\ApiComponentBundle\Repository\Layout\LayoutRepository;
7
8
final class PageDataTransformer extends AbstractDataTransformer
9
{
10
    /**
11
     * @param StaticPage $object
12
     */
13
    public function transform($object, array $context = []): StaticPage
14
    {
15
        /** @var LayoutRepository $repository */
16
        $repository = $this->container->get(LayoutRepository::class);
17
        $object->setLayout($repository->findOneBy(['default' => true]));
18
        return $object;
19
    }
20
21
    public function supportsTransformation($data, array $context = []): bool
22
    {
23
        return $data instanceof StaticPage && !$data->getLayout();
24
    }
25
26
    public static function getSubscribedServices(): array
27
    {
28
        return [
29
            '?' . LayoutRepository::class
30
        ];
31
    }
32
}
33