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

supportsTransformation()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 6
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