Passed
Push — v2 ( 5505d3...8372d3 )
by Daniel
04:27 queued 22s
created

FormOutputDataTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
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 22
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 5 1
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Component Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Silverback\ApiComponentBundle\DataTransformer;
15
16
use ApiPlatform\Core\DataTransformer\DataTransformerInterface;
17
use Silverback\ApiComponentBundle\Entity\Component\Form;
18
use Silverback\ApiComponentBundle\Factory\FormViewFactory;
19
20
/**
21
 * @author Daniel West <[email protected]>
22
 */
23
class FormOutputDataTransformer implements DataTransformerInterface
24
{
25
    private FormViewFactory $formViewFactory;
26
27
    public function __construct(FormViewFactory $formViewFactory)
28
    {
29
        $this->formViewFactory = $formViewFactory;
30
    }
31
32
    /**
33
     * @param Form $form
34
     */
35
    public function transform($form, string $to, array $context = [])
36
    {
37
        $form->formView = $this->formViewFactory->create($form);
38
39
        return $form;
40
    }
41
42
    public function supportsTransformation($data, string $to, array $context = []): bool
43
    {
44
        return $data instanceof Form && Form::class === $to;
45
    }
46
}
47