Passed
Push — v2 ( 5505d3...8372d3 )
by Daniel
04:27 queued 22s
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
/*
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