Conditions | 6 |
Paths | 32 |
Total Lines | 73 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
167 | protected function _dialog(string $type = null, string $message = null, string $title = null) : string |
||
168 | { |
||
169 | $output = null; |
||
170 | |||
171 | /* html elements */ |
||
172 | |||
173 | $element = new Html\Element(); |
||
174 | $overlayElement = $element |
||
175 | ->copy() |
||
176 | ->init('div', |
||
177 | [ |
||
178 | 'class' => $this->_optionArray['className']['overlay'] |
||
179 | ]); |
||
180 | $dialogElement = $element |
||
181 | ->copy() |
||
182 | ->init('div', |
||
183 | [ |
||
184 | 'class' => $this->_optionArray['className']['component'] |
||
185 | ]); |
||
186 | $titleElement = $element |
||
187 | ->copy() |
||
188 | ->init('h3', |
||
189 | [ |
||
190 | 'class' => $this->_optionArray['className']['title'] |
||
191 | ]) |
||
192 | ->text($title); |
||
193 | $boxElement = $element |
||
194 | ->copy() |
||
195 | ->init('div', |
||
196 | [ |
||
197 | 'class' => $this->_optionArray['className']['box'] |
||
198 | ]); |
||
199 | $textElement = $type === 'alert' || $type === 'confirm' ? $element |
||
200 | ->copy() |
||
201 | ->init('p') |
||
202 | ->text($message) : null; |
||
203 | $fieldElement = $type === 'prompt' ? $element |
||
204 | ->copy() |
||
205 | ->init('input', |
||
206 | [ |
||
207 | 'class' => $this->_optionArray['className']['field'], |
||
208 | 'placeholder' => $message |
||
209 | ]) : null; |
||
210 | $buttonElement = $element |
||
211 | ->copy() |
||
212 | ->init('button', |
||
213 | [ |
||
214 | 'class' => $this->_optionArray['className']['button'] |
||
215 | ]); |
||
216 | $buttonOkElement = $buttonElement |
||
217 | ->copy() |
||
218 | ->addClass($this->_optionArray['className']['buttonOk']) |
||
219 | ->text($this->_language->get('ok')); |
||
220 | $buttonCancelElement = $type === 'confirm' || $type === 'prompt' ? $buttonElement |
||
221 | ->copy() |
||
222 | ->addClass($this->_optionArray['className']['buttonCancel']) |
||
223 | ->text($this->_language->get('cancel')) : null; |
||
224 | |||
225 | /* collect output */ |
||
226 | |||
227 | $output = $overlayElement->html( |
||
228 | $dialogElement->html( |
||
229 | $titleElement . |
||
230 | $boxElement->html( |
||
231 | $textElement . |
||
232 | $fieldElement . |
||
233 | $buttonOkElement . |
||
234 | $buttonCancelElement |
||
235 | ) |
||
236 | ) |
||
237 | ); |
||
238 | return $output; |
||
239 | } |
||
240 | } |
||
241 |
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: