Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
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 3
    public function __construct(array $types = array(), array $data = array(), array $options = array())
52
    {
53 3
        $this->types = $types;
54 3
        $this->data = $data;
55 3
        $this->options = $options;
56
57 3
        $this->setTemplate('@KunstmaanAdmin/FormWidgets/FormWidget/widget.html.twig');
58 3
    }
59
60
    /**
61
     * @param FormBuilderInterface $builder The form builder
62
     */
63 1
    public function buildForm(FormBuilderInterface $builder)
64
    {
65 1
        $data = $builder->getData();
66
67 1
        foreach ($this->types as $name => $type) {
68 1
            $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 1
            $data[$name] = $this->data[$name];
70
        }
71
72 1
        $builder->setData($data);
73 1
    }
74
75
    /**
76
     * @param Request $request
77
     */
78 1
    public function bindRequest(Request $request)
79
    {
80 1
    }
81
82
    /**
83
     * @param EntityManager $em
84
     */
85 1
    public function persist(EntityManager $em)
86
    {
87 1
        foreach ($this->data as $item) {
88 1
            $em->persist($item);
89
        }
90 1
    }
91
92
    /**
93
     * @param FormView $formView
94
     *
95
     * @return array
96
     */
97 2
    public function getFormErrors(FormView $formView)
98
    {
99 2
        $formViews = array();
100 2
        foreach ($this->types as $name => $type) {
101 1
            $formViews[] = $formView[$name];
102
        }
103
104 2
        $formHelper = $this->getFormHelper();
105
106 2
        return $formHelper->getRecursiveErrorMessages($formViews);
107
    }
108
109
    /**
110
     * @return FormHelper
111
     */
112 2
    protected function getFormHelper()
113
    {
114 2
        if (\is_null($this->formHelper)) {
115 2
            $this->formHelper = new FormHelper();
116
        }
117
118 2
        return $this->formHelper;
119
    }
120
121
    /**
122
     * @param string $template
123
     */
124 3
    public function setTemplate($template)
125
    {
126 3
        $this->template = $template;
127 3
    }
128
129
    /**
130
     * @return string
131
     */
132 1
    public function getTemplate()
133
    {
134 1
        return $this->template;
135
    }
136
137
    /**
138
     * {@inheritdoc}
139
     */
140 1
    public function setIdentifier($identifier)
141
    {
142 1
        $this->identifier = $identifier;
143
144 1
        return $this;
145
    }
146
147
    /**
148
     * @return string
149
     */
150 1
    public function getIdentifier()
151
    {
152 1
        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 2
    public function addType($name, $type, $data = null, $options = array())
164
    {
165 2
        $this->types[$name] = $type;
166 2
        $this->data[$name] = $data;
167 2
        $this->options[$name] = $options;
168
169 2
        return $this;
170
    }
171
172
    /**
173
     * @return AbstractType[]
174
     */
175 1
    public function getTypes()
176
    {
177 1
        return $this->types;
178
    }
179
180
    /**
181
     * @return array
182
     */
183 1
    public function getData()
184
    {
185 1
        return $this->data;
186
    }
187
188
    /**
189
     * @param Request $request
190
     *
191
     * @return array
192
     */
193 1
    public function getExtraParams(Request $request)
194
    {
195 1
        return array();
196
    }
197
198
    /**
199
     * @return array
200
     */
201 1
    public function getOptions()
202
    {
203 1
        return $this->options;
204
    }
205
}
206