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