Completed
Push — master ( d7020d...a4700d )
by Daniel
06:50
created

FormDataTransformer::transform()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Silverback\ApiComponentBundle\DataTransformer;
4
5
use Silverback\ApiComponentBundle\Entity\Component\Form\Form;
6
use Silverback\ApiComponentBundle\Factory\Form\FormViewFactory;
7
8
final class FormDataTransformer extends AbstractDataTransformer
9
{
10
    /**
11
     * @param Form $object
12
     */
13
    public function transform($object, array $context = []): Form
14
    {
15
        /** @var FormViewFactory $factory */
16
        $factory = $this->container->get(FormViewFactory::class);
17
        $object->setForm($factory->create($object));
18
        return $object;
19
    }
20
21
    public function supportsTransformation($data, array $context = []): bool
22
    {
23
        return $data instanceof Form && !$data->getForm();
24
    }
25
26
    public static function getSubscribedServices(): array
27
    {
28
        return [
29
            '?' . FormViewFactory::class
30
        ];
31
    }
32
}
33