Conditions | 9 |
Paths | 70 |
Total Lines | 78 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 |
||
57 | public function export(Request $request, EntityManagerInterface $entityManager) |
||
58 | { |
||
59 | $this->denyAccessUnlessGranted('ROLE_EXPORT_PAYMENT_ORDERS'); |
||
60 | |||
61 | $ids = $request->query->get('ids'); |
||
62 | $id_array = explode(',', $ids); |
||
63 | //Retrieve all payment orders which should be retrieved from DB: |
||
64 | $payment_orders = []; |
||
65 | foreach ($id_array as $id) { |
||
66 | $payment_orders[] = $entityManager->find(PaymentOrder::class, $id); |
||
67 | } |
||
68 | |||
69 | $form = $this->createForm(SepaExportType::class); |
||
70 | |||
71 | $form->handleRequest($request); |
||
72 | |||
73 | if ($form->isSubmitted() && $form->isValid()) { |
||
74 | //Determine the Values to use |
||
75 | $data = $form->getData(); |
||
76 | //If user has selected a bank account preset, then use the data from it |
||
77 | if ($data['bank_account'] instanceof BankAccount) { |
||
78 | $iban = $data['bank_account']->getIban(); |
||
79 | $bic = $data['bank_account']->getBic(); |
||
80 | $name = $data['bank_account']->getExportAccountName(); |
||
81 | } else { //Use the manual inputted data |
||
82 | $iban = $data['iban']; |
||
83 | $bic = $data['bic']; |
||
84 | $name = $data['name']; |
||
85 | } |
||
86 | |||
87 | try { |
||
88 | $xml_files = $this->sepaExporter->export( |
||
89 | $payment_orders, |
||
90 | [ |
||
91 | 'iban' => $iban, |
||
92 | 'bic' => $bic, |
||
93 | 'name' => $name, |
||
94 | 'mode' => $data['mode'], |
||
95 | ] |
||
96 | ); |
||
97 | |||
98 | $response = null; |
||
|
|||
99 | |||
100 | //Download as file |
||
101 | if (1 === count($xml_files)) { |
||
102 | $xml_string = array_values($xml_files)[0]; |
||
103 | $filename = 'export_'.date('Y-m-d_H-i-s').'.xml'; |
||
104 | $response = $this->getDownloadResponse($xml_string, $filename); |
||
105 | } else { |
||
106 | $data = []; |
||
107 | foreach ($xml_files as $key => $content) { |
||
108 | $data[$key . '.xml'] = $content; |
||
109 | } |
||
110 | |||
111 | return ZIPBinaryFileResponseFacade::createZIPResponseFromData( |
||
112 | $data, |
||
113 | 'export_'.date('Y-m-d_H-i-s').'.zip' |
||
114 | ); |
||
115 | } |
||
116 | |||
117 | //Set export flag |
||
118 | foreach ($payment_orders as $paymentOrder) { |
||
119 | $paymentOrder->setExported(true); |
||
120 | } |
||
121 | $this->entityManager->flush(); |
||
122 | |||
123 | return $response; |
||
124 | } catch (SEPAExportAutoModeNotPossible $exception) { |
||
125 | //Show error if auto mode is not possible |
||
126 | $this->addFlash('danger', |
||
127 | $this->translator->trans('sepa_export.error.department_missing_account') |
||
128 | .': '.$exception->getWrongDepartment()->getName()); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | return $this->render('admin/payment_order/export/export.html.twig', [ |
||
133 | 'payment_orders' => $payment_orders, |
||
134 | 'form' => $form->createView(), |
||
135 | ]); |
||
150 |