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

FormFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A create() 0 9 1
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