FormAware   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFormFactory() 0 4 1
A setFormFactory() 0 4 1
A createForm() 0 4 1
A createFormBuilder() 0 4 1
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