Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

AdminBundle/Helper/FormWidgets/FormWidget.php (1 issue)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\AdminBundle\Helper\FormWidgets;
4
5
use Doctrine\ORM\EntityManager;
6
use Kunstmaan\AdminBundle\Helper\FormHelper;
7
use Symfony\Component\Form\AbstractType;
8
use Symfony\Component\Form\FormBuilderInterface;
9
use Symfony\Component\Form\FormView;
10
use Symfony\Component\HttpFoundation\Request;
11
12
/**
13
 * The default tab implementation
14
 */
15
class FormWidget implements FormWidgetInterface
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $identifier;
21
22
    /**
23
     * @var AbstractType[]
24
     */
25
    protected $types;
26
27
    /**
28
     * @var array
29
     */
30
    protected $data;
31
32
    /**
33
     * @var array
34
     */
35
    protected $options;
36
37
    /**
38
     * @var FormHelper
39
     */
40
    private $formHelper = null;
41
42
    /**
43
     * @var string
44
     */
45
    protected $template;
46
47
    /**
48
     * @param array $types The types
49
     * @param array $data  The data attached to the types
50
     */
51
    public function __construct(array $types = array(), array $data = array(), array $options = array())
52
    {
53
        $this->types = $types;
54
        $this->data = $data;
55
        $this->options = $options;
56
57
        $this->setTemplate('KunstmaanAdminBundle:FormWidgets\FormWidget:widget.html.twig');
58
    }
59
60
    /**
61
     * @param FormBuilderInterface $builder The form builder
62
     */
63
    public function buildForm(FormBuilderInterface $builder)
64
    {
65
        $data = $builder->getData();
66
67
        foreach ($this->types as $name => $type) {
68
            $builder->add($name, $type, $this->options[$name]);
0 ignored issues
show
$type is of type object<Symfony\Component\Form\AbstractType>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
69
            $data[$name] = $this->data[$name];
70
        }
71
72
        $builder->setData($data);
73
    }
74
75
    /**
76
     * @param Request $request
77
     */
78
    public function bindRequest(Request $request)
79
    {
80
    }
81
82
    /**
83
     * @param EntityManager $em
84
     */
85
    public function persist(EntityManager $em)
86
    {
87
        foreach ($this->data as $item) {
88
            $em->persist($item);
89
        }
90
    }
91
92
    /**
93
     * @param FormView $formView
94
     *
95
     * @return array
96
     */
97
    public function getFormErrors(FormView $formView)
98
    {
99
        $formViews = array();
100
        foreach ($this->types as $name => $type) {
101
            $formViews[] = $formView[$name];
102
        }
103
104
        $formHelper = $this->getFormHelper();
105
106
        return $formHelper->getRecursiveErrorMessages($formViews);
107
    }
108
109
    /**
110
     * @return FormHelper
111
     */
112
    protected function getFormHelper()
113
    {
114
        if (is_null($this->formHelper)) {
115
            $this->formHelper = new FormHelper();
116
        }
117
118
        return $this->formHelper;
119
    }
120
121
    /**
122
     * @param string $template
123
     */
124
    public function setTemplate($template)
125
    {
126
        $this->template = $template;
127
    }
128
129
    /**
130
     * @return string
131
     */
132
    public function getTemplate()
133
    {
134
        return $this->template;
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140
    public function setIdentifier($identifier)
141
    {
142
        $this->identifier = $identifier;
143
144
        return $this;
145
    }
146
147
    /**
148
     * @return string
149
     */
150
    public function getIdentifier()
151
    {
152
        return $this->identifier;
153
    }
154
155
    /**
156
     * @param string $name
157
     * @param string $type
158
     * @param null   $data
159
     * @param array  $options
160
     *
161
     * @return FormWidget
162
     */
163
    public function addType($name, $type, $data = null, $options = array())
164
    {
165
        $this->types[$name] = $type;
166
        $this->data[$name] = $data;
167
        $this->options[$name] = $options;
168
169
        return $this;
170
    }
171
172
    /**
173
     * @return AbstractType[]
174
     */
175
    public function getTypes()
176
    {
177
        return $this->types;
178
    }
179
180
    /**
181
     * @return array
182
     */
183
    public function getData()
184
    {
185
        return $this->data;
186
    }
187
188
    /**
189
     * @param Request $request
190
     *
191
     * @return array
192
     */
193
    public function getExtraParams(Request $request)
194
    {
195
        return array();
196
    }
197
198
    /**
199
     * @return array
200
     */
201
    public function getOptions()
202
    {
203
        return $this->options;
204
    }
205
}
206