Completed
Push — master ( 8253ba...a023d2 )
by Daniel
16:49 queued 05:23
created

FormFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 50
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createFormView() 0 4 1
A __construct() 0 6 1
A createForm() 0 9 1
1
<?php
2
3
namespace Silverback\ApiComponentBundle\Factory;
4
5
use Silverback\ApiComponentBundle\Entity\Component\Form\Form;
6
use Silverback\ApiComponentBundle\Entity\Component\Form\FormView;
7
use Symfony\Component\Form\FormFactoryInterface;
8
use Symfony\Component\Form\FormInterface;
9
use Symfony\Component\Routing\RouterInterface;
10
11
class FormFactory
12
{
13
    /**
14
     * @var FormFactoryInterface
15
     */
16
    private $formFactory;
17
18
    /**
19
     * @var RouterInterface
20
     */
21
    private $router;
22
23
    /**
24
     * @param FormFactoryInterface $formFactory
25
     * @param RouterInterface $router
26
     */
27
    public function __construct(
28
        FormFactoryInterface $formFactory,
29
        RouterInterface $router
30
    ) {
31
        $this->formFactory = $formFactory;
32
        $this->router = $router;
33
    }
34
35
    /**
36
     * @param Form $component
37
     * @return \Symfony\Component\Form\FormInterface
38
     */
39
    public function createForm(Form $component): FormInterface
40
    {
41
        return $this->formFactory->create(
42
            $component->getFormType(),
43
            null,
44
            [
45
                'method' => 'POST',
46
                'action' => $this->router->generate('silverback_api_component_form_submit', [
47
                    'id' => $component->getId()
48
                ])
49
            ]
50
        );
51
    }
52
53
    /**
54
     * @param Form $component
55
     * @return FormView
56
     */
57
    public function createFormView(Form $component)
58
    {
59
        $form = $this->createForm($component);
60
        return new FormView($form->createView());
61
    }
62
}
63