Completed
Push — v2 ( 41359e...4c6274 )
by Daniel
03:47
created

PageTemplateOutputDataTransformer::transform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\DataTransformer;
6
7
use ApiPlatform\Core\DataTransformer\DataTransformerInterface;
8
use Silverback\ApiComponentBundle\Entity\Core\PageTemplate;
9
use Silverback\ApiComponentBundle\Repository\Core\LayoutRepository;
10
11
/**
12
 * @author Daniel West <[email protected]>
13
 */
14
class PageTemplateOutputDataTransformer implements DataTransformerInterface
15
{
16
    private LayoutRepository $layoutRepository;
17
18
    public function __construct(LayoutRepository $layoutRepository)
19
    {
20
        $this->layoutRepository = $layoutRepository;
21
    }
22
23
    /**
24
     * @param PageTemplate $object
25
     */
26
    public function transform($object, string $to, array $context = [])
27
    {
28
        $object->layout = $this->layoutRepository->findDefault();
29
        return $object;
30
    }
31
32
    public function supportsTransformation($data, string $to, array $context = []): bool
33
    {
34
        return $data instanceof PageTemplate && !$data->layout;
35
    }
36
}
37