FormAware::createForm()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Linio\Controller;
6
7
use Symfony\Component\Form\Extension\Core\Type\FormType;
8
use Symfony\Component\Form\Form;
9
use Symfony\Component\Form\FormBuilderInterface;
10
use Symfony\Component\Form\FormFactory;
11
use Symfony\Component\Form\FormTypeInterface;
12
13
trait FormAware
14
{
15
    /**
16
     * @var FormFactory
17
     */
18
    protected $formFactory;
19
20
    /**
21
     * @return FormFactory
22
     */
23
    public function getFormFactory()
24
    {
25
        return $this->formFactory;
26
    }
27
28
    /**
29
     * @param FormFactory $formFactory
30
     */
31
    public function setFormFactory(FormFactory $formFactory)
32
    {
33
        $this->formFactory = $formFactory;
34
    }
35
36
    /**
37
     * Creates and returns a Form instance from the type of the form.
38
     *
39
     * @param string|FormTypeInterface $type    The built type of the form
40
     * @param mixed                    $data    The initial data for the form
41
     * @param array                    $options Options for the form
42
     *
43
     * @return Form
44
     */
45
    public function createForm($type, $data = null, array $options = [])
46
    {
47
        return $this->formFactory->create($type, $data, $options);
48
    }
49
50
    /**
51
     * Creates and returns a form builder instance.
52
     *
53
     * @param mixed $data    The initial data for the form
54
     * @param array $options Options for the form
55
     *
56
     * @return FormBuilderInterface
57
     */
58
    public function createFormBuilder($data = null, array $options = [])
59
    {
60
        return $this->formFactory->createBuilder(FormType::class, $data, $options);
61
    }
62
}
63