Conditions | 4 |
Paths | 4 |
Total Lines | 51 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
54 | public function configureFields(string $pageName): iterable |
||
55 | { |
||
56 | $xml_file = VichyFileField::new('xml_file', 'sepa_export.xml_file'); |
||
57 | $id = IdField::new('id', 'sepa_export.id'); |
||
58 | $number_of_payments = NumberField::new('number_of_payments', 'sepa_export.number_of_payments'); |
||
59 | $initiator_bic = TextField::new('initiator_bic', 'sepa_export.initiator_bic'); |
||
60 | $initiator_iban = TextField::new('initiator_iban', 'sepa_export.initiator_iban'); |
||
61 | $booking_date = DateTimeField::new('booking_date', 'sepa_export.booking_date'); |
||
62 | $total_sum = MoneyField::new('total_sum', 'sepa_export.total_sum') |
||
63 | ->setCurrency('EUR') |
||
64 | ->setStoredAsCents(true); |
||
65 | $sepa_message_id = TextField::new('sepa_message_id', 'sepa_export.message_id'); |
||
66 | $description = TextField::new('description', 'sepa_export.description'); |
||
67 | $comment = TextEditorField::new('comment', 'sepa_export.comment'); |
||
68 | $group_ulid = TextField::new('group_ulid', 'sepa_export.group_ulid')->onlyOnDetail(); |
||
69 | $last_modified = DateTimeField::new('last_modified', 'last_modified'); |
||
70 | $creationDate = DateTimeField::new('creation_date', 'creation_date')->onlyOnDetail(); |
||
71 | $associated_payment_orders = AssociationField::new('associated_payment_orders') |
||
72 | ->setTemplatePath('admin/field/sepa_export_association.html.twig') |
||
73 | ->setCrudController(PaymentOrderCrudController::class); |
||
74 | |||
75 | |||
76 | if (Crud::PAGE_INDEX === $pageName) { |
||
77 | return [$id, $number_of_payments, $total_sum, $description, $initiator_iban, $booking_date]; |
||
78 | } |
||
79 | |||
80 | if (Crud::PAGE_DETAIL === $pageName) { |
||
81 | return [ |
||
82 | $xml_file, |
||
83 | |||
84 | FormField::addPanel('sepa_export.infos')->collapsible(), |
||
85 | $id, |
||
86 | $number_of_payments, |
||
87 | $total_sum, |
||
88 | $initiator_iban, |
||
89 | $initiator_bic, |
||
90 | $description, |
||
91 | $booking_date, |
||
92 | $associated_payment_orders, |
||
93 | $comment, |
||
94 | |||
95 | FormField::addPanel('sepa_export.advanced')->collapsible(), |
||
96 | $sepa_message_id, |
||
97 | $group_ulid, |
||
98 | $last_modified, |
||
99 | $creationDate, |
||
100 | ]; |
||
101 | } |
||
102 | |||
103 | if (Crud::PAGE_EDIT === $pageName) { |
||
104 | return [$comment]; |
||
105 | } |
||
108 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: