Passed
Push — develop ( 53a66f...07e04a )
by Daniel
05:35
created

FormFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 7
cp 0
crap 2
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Factory\Form;
4
5
use Silverback\ApiComponentBundle\Entity\Component\Form\Form;
6
use Symfony\Component\Form\FormFactoryInterface;
7
use Symfony\Component\Form\FormInterface;
8
use Symfony\Component\Routing\RouterInterface;
9
10
class FormFactory
11
{
12
    /**
13
     * @var FormFactoryInterface
14
     */
15
    private $formFactory;
16
17
    /**
18
     * @var RouterInterface
19
     */
20
    private $router;
21
22
    /**
23
     * @param FormFactoryInterface $formFactory
24
     * @param RouterInterface $router
25
     */
26
    public function __construct(
27
        FormFactoryInterface $formFactory,
28
        RouterInterface $router
29
    ) {
30
        $this->formFactory = $formFactory;
31
        $this->router = $router;
32
    }
33
34
    /**
35
     * @param Form $component
36
     * @return FormInterface
37
     */
38
    public function create(Form $component): FormInterface
39
    {
40
        return $this->formFactory->create(
41
            $component->getFormType(),
42
            null,
43
            [
44
                'method' => 'POST',
45
                'action' => $this->router->generate('silverback_api_component_form_submit', [
46
                    'id' => $component->getId()
47
                ])
48
            ]
49
        );
50
    }
51
}
52