Conditions | 4 |
Paths | 4 |
Total Lines | 161 |
Code Lines | 127 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
244 | public function configureFields(string $pageName): iterable |
||
245 | { |
||
246 | //Documents |
||
247 | $documentsPanel = FormField::addPanel('payment_order.group.documents'); |
||
248 | $printed_form = VichyFileField::new('printed_form_file', 'payment_order.printed_form.label'); |
||
249 | $references = VichyFileField::new('references_file', 'payment_order.references.label'); |
||
250 | |||
251 | //Basic informations |
||
252 | $infoPanel = FormField::addPanel('payment_order.group.info'); |
||
253 | $id = IntegerField::new('id', 'payment_order.id.label'); |
||
254 | $firstName = TextField::new('first_name', 'payment_order.first_name.label'); |
||
255 | $lastName = TextField::new('last_name', 'payment_order.last_name.label'); |
||
256 | $contact_email = EmailField::new('contact_email', 'payment_order.contact_email.label') |
||
257 | ->setFormTypeOption('empty_data', '') |
||
258 | ->setRequired(false); |
||
259 | $department = AssociationField::new('department', 'payment_order.department.label') |
||
260 | ->setFormTypeOption('attr', [ |
||
261 | 'data-widget' => 'select2', |
||
262 | ]); |
||
263 | $departmentName = TextareaField::new('department.name', 'payment_order.department.label_short'); |
||
264 | $amount = MoneyField::new('amount', 'payment_order.amount.label') |
||
265 | ->setCurrency('EUR') |
||
266 | ->setStoredAsCents(true); |
||
267 | $projectName = TextField::new('project_name', 'payment_order.project_name.label'); |
||
268 | $funding_id = TextField::new('funding_id', 'payment_order.funding_id.label') |
||
269 | ->setRequired(false) |
||
270 | ->setFormTypeOption('empty_data', ''); |
||
271 | //Use short name for index |
||
272 | $funding_id_index = TextField::new('funding_id', 'payment_order.funding_id.label_short') |
||
273 | ->setHelp('payment_order.funding_id.label'); |
||
274 | $fsr_kom = BooleanField::new('fsr_kom_resolution', 'payment_order.fsr_kom.label') |
||
275 | ->setRequired(false); |
||
276 | $resolution_date = DateField::new('resolution_date', 'payment_order.resolution_date.label') |
||
277 | ->setRequired(false); |
||
278 | $comment = TextEditorField::new('comment', 'payment_order.comment.label') |
||
279 | ->setRequired(false) |
||
280 | ->setFormTypeOption('empty_data', ''); |
||
281 | $lastModified = DateTimeField::new('last_modified', 'last_modified'); |
||
282 | $creationDate = DateTimeField::new('creation_date', 'creation_date'); |
||
283 | |||
284 | //Status informations |
||
285 | $statusPanel = FormField::addPanel('payment_order.group.status'); |
||
286 | $mathematicallyCorrect = BooleanField::new('mathematically_correct', 'payment_order.mathematically_correct.label') |
||
287 | ->setHelp('payment_order.mathematically_correct.help') |
||
288 | //Disable fields (and show coloumns as read only tags) if user does not have proper permissions to change |
||
289 | //factually and mathematically correct status |
||
290 | ->setFormTypeOption('disabled', !$this->isGranted('ROLE_PO_MATHEMATICALLY')) |
||
291 | ->renderAsSwitch($this->isGranted('ROLE_PO_MATHEMATICALLY')); |
||
292 | $exported = BooleanField::new('exported', 'payment_order.exported.label') |
||
293 | ->setHelp('payment_order.exported.help'); |
||
294 | $factuallyCorrect = BooleanField::new('factually_correct', 'payment_order.factually_correct.label') |
||
295 | ->setHelp('payment_order.factually_correct.help') |
||
296 | ->setFormTypeOption('disabled', !$this->isGranted('ROLE_PO_FACTUALLY')) |
||
297 | ->renderAsSwitch($this->isGranted('ROLE_PO_FACTUALLY')); |
||
298 | $confirmed_1 = DateTimeField::new('confirm1_timestamp', 'payment_order.confirmed_1.label'); |
||
299 | $confirmed_2 = DateTimeField::new('confirm2_timestamp', 'payment_order.confirmed_2.label'); |
||
300 | |||
301 | //Payee informations |
||
302 | $payeePanel = FormField::addPanel('payment_order.group.receiver'); |
||
303 | $bankInfoAccountOwner = TextField::new('bank_info.account_owner', 'bank_info.account_owner.label'); |
||
304 | $bankInfoStreet = TextField::new('bank_info.street', 'bank_info.street.label'); |
||
305 | $bankInfoZipCode = TextField::new('bank_info.zip_code', 'bank_info.zip_code.label'); |
||
306 | $bankInfoCity = TextField::new('bank_info.city', 'bank_info.city.label'); |
||
307 | |||
308 | //Payee bank account infos |
||
309 | $bankInfoPanel = FormField::addPanel('payment_order.group.bank_info'); |
||
310 | $bankInfoIban = TextField::new('bank_info.iban', 'bank_info.iban.label'); |
||
311 | $bankInfoBic = TextField::new('bank_info.bic', 'bank_info.bic.label') |
||
312 | ->setRequired(false) |
||
313 | ->setFormTypeOption('empty_data', ''); |
||
314 | $bankInfoBankName = TextField::new('bank_info.bank_name', 'bank_info.bank_name.label'); |
||
315 | $bankInfoReference = TextField::new('bank_info.reference', 'bank_info.reference.label') |
||
316 | ->setRequired(false) |
||
317 | ->setFormTypeOption('empty_data', ''); |
||
318 | |||
319 | if (Crud::PAGE_INDEX === $pageName) { |
||
320 | return [$id, $projectName, $departmentName, $amount, $mathematicallyCorrect, $factuallyCorrect, $funding_id_index, $creationDate]; |
||
321 | } |
||
322 | |||
323 | if (Crud::PAGE_DETAIL === $pageName) { |
||
324 | return [ |
||
325 | //Documents section |
||
326 | $documentsPanel, |
||
327 | $printed_form, |
||
328 | $references, |
||
329 | //Basic informations |
||
330 | $infoPanel, |
||
331 | $id, |
||
332 | $firstName, |
||
333 | $lastName, |
||
334 | $contact_email, |
||
335 | $projectName, |
||
336 | $department, |
||
337 | $amount, |
||
338 | $funding_id, |
||
339 | $resolution_date, |
||
340 | $fsr_kom, |
||
341 | $comment, |
||
342 | $lastModified, |
||
343 | $creationDate, |
||
344 | //Status infos |
||
345 | $statusPanel, |
||
346 | $mathematicallyCorrect, |
||
347 | $exported, |
||
348 | $factuallyCorrect, |
||
349 | $confirmed_1, |
||
350 | $confirmed_2, |
||
351 | //Payee informations |
||
352 | $payeePanel, |
||
353 | $bankInfoAccountOwner, |
||
354 | $bankInfoStreet, |
||
355 | $bankInfoZipCode, |
||
356 | $bankInfoCity, |
||
357 | //Banking informations |
||
358 | $bankInfoPanel, |
||
359 | $bankInfoIban, |
||
360 | $bankInfoBic, |
||
361 | $bankInfoBankName, |
||
362 | $bankInfoReference, |
||
363 | ]; |
||
364 | } |
||
365 | |||
366 | if (Crud::PAGE_EDIT === $pageName) { |
||
367 | return [ |
||
368 | //Documents section |
||
369 | $documentsPanel, |
||
370 | $printed_form, |
||
371 | $references, |
||
372 | //Basic informations |
||
373 | $infoPanel, |
||
374 | $firstName, |
||
375 | $lastName, |
||
376 | $contact_email, |
||
377 | $projectName, |
||
378 | $department, |
||
379 | $amount, |
||
380 | $funding_id, |
||
381 | $resolution_date, |
||
382 | $fsr_kom, |
||
383 | $comment, |
||
384 | //Status infos |
||
385 | $statusPanel, |
||
386 | $mathematicallyCorrect, |
||
387 | $exported, |
||
388 | $factuallyCorrect, |
||
389 | //Payee informations |
||
390 | $payeePanel, |
||
391 | $bankInfoAccountOwner, |
||
392 | $bankInfoStreet, |
||
393 | $bankInfoZipCode, |
||
394 | $bankInfoCity, |
||
395 | //Banking informations |
||
396 | $bankInfoPanel, |
||
397 | $bankInfoIban, |
||
398 | $bankInfoBic, |
||
399 | $bankInfoBankName, |
||
400 | $bankInfoReference, |
||
401 | ]; |
||
402 | } |
||
403 | |||
404 | throw new RuntimeException('It should not be possible to reach this point...'); |
||
405 | } |
||
422 |