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

PageDataTransformer::supportsTransformation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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