Completed
Push — master ( 003c1a...870291 )
by Tomáš
06:24
created

ControllerFormTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 31
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
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
/*
6
 * This file is part of Symplify
7
 * Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
8
 */
9
10
namespace Symplify\ControllerAutowire\Controller\Form;
11
12
use Symfony\Component\Form\Extension\Core\Type\FormType;
13
use Symfony\Component\Form\FormBuilder;
14
use Symfony\Component\Form\FormFactoryInterface;
15
use Symfony\Component\Form\FormInterface;
16
17
trait ControllerFormTrait
18
{
19
    /**
20
     * @var FormFactoryInterface
21
     */
22
    private $formFactory;
23
24
    public function setFormFactory(FormFactoryInterface $formFactory)
25
    {
26
        $this->formFactory = $formFactory;
27
    }
28
29
    /**
30
     * @param string $type
31
     * @param mixed  $data
32
     * @param array  $options
33
     */
34
    protected function createForm(string $type, $data = null, array $options = []) : FormInterface
35
    {
36
        return $this->formFactory->create($type, $data, $options);
37
    }
38
39
    /**
40
     * @param mixed $data
41
     * @param array $options
42
     */
43
    protected function createFormBuilder($data = null, array $options = []) : FormBuilder
44
    {
45
        return $this->formFactory->createBuilder(FormType::class, $data, $options);
46
    }
47
}
48