Conditions | 6 |
Paths | 8 |
Total Lines | 69 |
Code Lines | 32 |
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 |
||
51 | public function exportUsingGivenIBAN(array $payment_orders, string $debtor_iban, string $debtor_bic, string $debtor_account_name): SEPAExport |
||
52 | { |
||
53 | //We need IBAN without spaces |
||
54 | $debtor_iban = str_replace(" ", "", $debtor_iban); |
||
55 | |||
56 | $groupHeader = $this->group_header_helper->getGroupHeader($debtor_bic); |
||
57 | $sepaFile = new CustomerCreditTransferFile($groupHeader); |
||
58 | |||
59 | $payment = new PaymentInformation( |
||
60 | md5(random_bytes(50)), //Use a random payment identifier ID |
||
61 | $debtor_iban, |
||
62 | $debtor_bic, |
||
63 | $debtor_account_name |
||
64 | ); |
||
65 | |||
66 | //Disable batch booking, as the commerzbank does not show details for "Sammelüberweisungen" |
||
67 | $payment->setBatchBooking(false); |
||
68 | |||
69 | //Add each payment order as transaction |
||
70 | foreach ($payment_orders as $payment_order) { |
||
71 | //Ensure that type is correct |
||
72 | if (!$payment_order instanceof PaymentOrder) { |
||
73 | throw new \InvalidArgumentException('$payment_orders must be an array of PaymentOrder elements!'); |
||
74 | } |
||
75 | |||
76 | //Ensure that the ID is available |
||
77 | if (!$payment_order->getId() === null) { |
||
78 | throw new \InvalidArgumentException('A payment order that should be exported misses an ID. All payment orders must have been persisted!'); |
||
79 | } |
||
80 | |||
81 | $transfer = new CustomerCreditTransferInformation( |
||
82 | $payment_order->getAmount(), |
||
83 | $payment_order->getBankInfo()->getIbanWithoutSpaces(), |
||
84 | $payment_order->getBankInfo()->getAccountOwner() |
||
85 | ); |
||
86 | |||
87 | //BIC is optional, only set it if it was set. |
||
88 | if (!empty($payment_order->getBankInfo()->getBic())) { |
||
89 | $transfer->setBic($payment_order->getBankInfo()->getBic()); |
||
90 | } |
||
91 | |||
92 | //We use the ID String of the payment order as end to end reference |
||
93 | $transfer->setEndToEndIdentification($payment_order->getIDString()); |
||
94 | //Set the reference ID of the payment order as |
||
95 | $transfer->setRemittanceInformation($payment_order->getBankInfo()->getReference()); |
||
96 | |||
97 | $payment->addTransfer($transfer); |
||
98 | } |
||
99 | |||
100 | //Add payment infos to SEPA file |
||
101 | $sepaFile->addPaymentInformation($payment); |
||
102 | |||
103 | // We have to use the format 'pain.001.001.03' |
||
104 | $domBuilder = DomBuilderFactory::createDomBuilder($sepaFile, 'pain.001.001.03'); |
||
105 | |||
106 | if (!$domBuilder instanceof BaseDomBuilder) { |
||
107 | throw new \RuntimeException('$domBuilder must be an BaseDomBuilder instance!'); |
||
108 | } |
||
109 | |||
110 | //Create a temporary file with the XML content |
||
111 | $xml_string = $domBuilder->asXml(); |
||
112 | |||
113 | //We use the format YYYYMMDDHHmmss_MsgID.xml |
||
114 | $original_filename = sprintf("%s_%s.xml", |
||
115 | (new \DateTime())->format('YmdHis'), |
||
116 | $groupHeader->getMessageIdentification(), |
||
117 | ); |
||
118 | |||
119 | return SEPAExport::createFromXMLString($xml_string, $original_filename); |
||
120 | } |
||
123 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.