| Conditions | 3 |
| Paths | 3 |
| Total Lines | 55 |
| Code Lines | 43 |
| 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 |
||
| 28 | public function generate(): string |
||
| 29 | { |
||
| 30 | $writer = new XMLWriter(); |
||
| 31 | $writer->openMemory(); |
||
| 32 | $writer->startDocument('1.0', 'UTF-8', 'no'); |
||
| 33 | $writer->setIndent(true); |
||
| 34 | $writer->setIndentString(' '); |
||
| 35 | |||
| 36 | // Write OFX declaration |
||
| 37 | $writer->writeRaw( |
||
| 38 | '<?OFX' |
||
| 39 | . ' OFXHEADER="200"' |
||
| 40 | . ' VERSION="211"' |
||
| 41 | . ' SECURITY="NONE"' |
||
| 42 | . ' OLDFILEUID="NONE"' |
||
| 43 | . ' NEWFILEUID="12345678901234567890123456789012"?>' |
||
| 44 | . "\n" |
||
| 45 | ); |
||
| 46 | |||
| 47 | $writer->startElement('OFX'); |
||
| 48 | $this->createSignOn($writer); |
||
| 49 | |||
| 50 | // Banks |
||
| 51 | foreach ($this->banks as $bank) { |
||
| 52 | $writer->startElement('BANKMSGSRSV1'); |
||
| 53 | $writer->startElement('STMTTRNRS'); |
||
| 54 | $writer->startElement('TRNUID'); |
||
| 55 | $writer->text($bank->getTransactionUid()); |
||
| 56 | $writer->endElement(); // TRNUID |
||
| 57 | $writer->startElement('STMTRS'); |
||
| 58 | $writer->startElement('CURDEF'); |
||
| 59 | $writer->text($bank->getStatement()->getCurrency()); |
||
| 60 | $writer->endElement(); // CURDEF |
||
| 61 | $this->createBankAccountFrom($writer, $bank); |
||
| 62 | $writer->startElement('BANKTRANLIST'); |
||
| 63 | $writer->startElement('DTSTART'); |
||
| 64 | $writer->text($bank->getStatement()->getStartDate()->format('YmdHis')); |
||
| 65 | $writer->endElement(); // DTSTART |
||
| 66 | $writer->startElement('DTEND'); |
||
| 67 | $writer->text($bank->getStatement()->getEndDate()->format('YmdHis')); |
||
| 68 | $writer->endElement(); // DTEND |
||
| 69 | foreach ($bank->getStatement()->getTransactions() as $transaction) { |
||
| 70 | $this->createTransaction($writer, $transaction); |
||
| 71 | } |
||
| 72 | $writer->endElement(); // BANKTRANLIST |
||
| 73 | $this->createLedgerBalance($writer, $bank); |
||
| 74 | $writer->endElement(); // STMTRS |
||
| 75 | $writer->endElement(); // STMTTRNRS |
||
| 76 | $writer->endElement(); // BANKMSGSRSV1 |
||
| 77 | } |
||
| 78 | |||
| 79 | $writer->endElement(); // OFX |
||
| 80 | $writer->endDocument(); |
||
| 81 | |||
| 82 | return $writer->outputMemory(true); |
||
| 83 | } |
||
| 190 |