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

PageTemplateOutputDataTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 21
ccs 0
cts 8
cp 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A supportsTransformation() 0 3 2
A transform() 0 4 1
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