Passed
Push — develop ( 75d1fe...ccc913 )
by Daniel
06:14
created

FormFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 11
cts 11
cp 1
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\Content\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 3
    public function __construct(
27
        FormFactoryInterface $formFactory,
28
        RouterInterface $router
29
    ) {
30 3
        $this->formFactory = $formFactory;
31 3
        $this->router = $router;
32 3
    }
33
34
    /**
35
     * @param Form $component
36
     * @return FormInterface
37
     */
38 2
    public function create(Form $component): FormInterface
39
    {
40 2
        return $this->formFactory->create(
41 2
            $component->getFormType(),
42 2
            null,
43
            [
44 2
                'method' => 'POST',
45 2
                'action' => $this->router->generate('silverback_api_component_form_submit', [
46 2
                    'id' => $component->getId()
47
                ])
48
            ]
49
        );
50
    }
51
}
52