Skip to content

Commit

Permalink
some code reformatting / inlined a method
Browse files Browse the repository at this point in the history
  • Loading branch information
fruitl00p committed Mar 18, 2019
1 parent 9e0bcb8 commit b04cdd9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 22 deletions.
16 changes: 8 additions & 8 deletions src/Parser/Banking/Mt940/Engine/Hsbc.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function parseStatementAccount()
{
$results = [];
if (preg_match('/:25:([0-9X]+)*/', $this->getCurrentStatementData(), $results)
&& ! empty($results[1])
&& !empty($results[1])
) {
return $this->sanitizeAccount($results[1]);
}
Expand Down Expand Up @@ -149,21 +149,21 @@ protected function parseTransactionAccountName()
// SEPA MT940 Structured
if (preg_match('#/NAME/(.+?)\n?/(REMI|ADDR|ISDT|CSID)/#ms', $this->getCurrentTransactionData(), $results)) {
$accountName = trim($results[1]);
if ( ! empty($accountName)) {
if (!empty($accountName)) {
return $this->sanitizeAccountName($accountName);
}
}

if (preg_match('/^:61:.*? (.+)/m', $this->getCurrentTransactionData(), $results)) {
$accountName = trim($results[1]);
if ( ! empty($accountName)) {
if (!empty($accountName)) {
return $this->sanitizeAccountName($accountName);
}
}

if (preg_match('/(.*) Betaalautomaat/', $this->parseTransactionDescription(), $results)) {
$accountName = trim($results[1]);
if ( ! empty($accountName)) {
if (!empty($accountName)) {
return $this->sanitizeAccountName($accountName);
}
}
Expand Down Expand Up @@ -224,12 +224,12 @@ protected function sanitizeDescription($string)
{
$description = parent::sanitizeDescription($string);
if (strpos($description, '/REMI/') !== false
&& preg_match('#/REMI/(.*?)(/((PURP|ISDT|CSID|RTRN)/)|$)#s', $description, $results) && ! empty($results[1])
&& preg_match('#/REMI/(.*?)(/((PURP|ISDT|CSID|RTRN)/)|$)#s', $description, $results) && !empty($results[1])
) {
return $results[1];
}
if (strpos($description, '/EREF/') !== false
&& preg_match('#/EREF/(.*?)/(ORDP)/#s', $description, $results) && ! empty($results[1])
&& preg_match('#/EREF/(.*?)/(ORDP)/#s', $description, $results) && !empty($results[1])
) {
return $results[1];
}
Expand All @@ -246,9 +246,9 @@ protected function sanitizeDescription($string)
*/
protected function sanitizeDebitCredit($string)
{
$debitOrCredit = strtoupper(substr((string) $string, -1, 1));
$debitOrCredit = strtoupper(substr((string)$string, -1, 1));
if ($debitOrCredit !== Transaction::DEBIT && $debitOrCredit !== Transaction::CREDIT) {
trigger_error('wrong value for debit/credit ('.$string.')', E_USER_ERROR);
trigger_error('wrong value for debit/credit (' . $string . ')', E_USER_ERROR);
$debitOrCredit = '';
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Banking/Mt940/Engine/Rabo.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected function sanitizeDescription($string)
}

if (strpos($description, '/PREF/') !== false
&& preg_match('#/PREF/(.*)/?#s', $description, $results) && !empty($results[1])
&& preg_match('#/PREF/(.*)/?#s', $description, $results) && !empty($results[1])
) {
return $results[1];
}
Expand Down
31 changes: 22 additions & 9 deletions src/Parser/Banking/Mt940/Engine/Sns.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

namespace Kingsquare\Parser\Banking\Mt940\Engine;

use Kingsquare\Parser\Banking\Mt940\Engine;

/**
* **CAUTION** This is an untested / experimental engine for SNS
*
*
* @package Kingsquare\Parser\Banking\Mt940\Engine
* @author Paul Olthof ([email protected])
* @license http://opensource.org/licenses/MIT MIT
Expand All @@ -19,11 +23,18 @@ protected function parseStatementBank()
return 'SNS';
}

/**
* @override just return the unsanitized IBAN string
* @inheritdoc
*/
protected function sanitizeAccount($string)
{
return $string;
}

/**
* @inheritdoc
*/
protected function parseTransactionAccount()
{
$results = [];
Expand All @@ -36,6 +47,9 @@ protected function parseTransactionAccount()
return '';
}

/**
* @inheritdoc
*/
protected function parseTransactionAccountName()
{
$results = [];
Expand All @@ -48,26 +62,25 @@ protected function parseTransactionAccountName()
return '';
}

/**
* @override filter out the first two meta-data lines
* @inheritdoc
*/
protected function parseTransactionDescription()
{
$results = [];
if (preg_match_all('/[\n]:86:(.*?)(?=\n(:6(1|2))|$)/s', $this->getCurrentTransactionData(), $results)
&& !empty($results[1])
) {
$this->filterMetaDataFromDescription($results);
// filter out meta data
$lines = explode("\r\n", $results[1][0]);
unset($lines[0], $lines[1]);
$results[1][0] = implode("\r\n", $lines);

return $this->sanitizeDescription(implode(PHP_EOL, $results[1]));
}

return '';
}

private function filterMetaDataFromDescription(&$results)
{
$lines = explode("\r\n", $results[1][0]);
unset($lines[0]);
unset($lines[1]);
$results[1][0] = implode("\r\n", $lines);
}

}
8 changes: 4 additions & 4 deletions src/Parser/Banking/Mt940/Engine/Spk.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected function parseStatementBank()
*/
protected function parseStatementStartPrice()
{
return parent::parseStatementPrice('60[FM]');
return $this->parseStatementPrice('60[FM]');
}

/**
Expand All @@ -39,7 +39,7 @@ protected function parseStatementStartPrice()
*/
protected function parseStatementStartTimestamp()
{
return parent::parseTimestampFromStatement('60[FM]');
return $this->parseTimestampFromStatement('60[FM]');
}

/**
Expand All @@ -49,7 +49,7 @@ protected function parseStatementStartTimestamp()
*/
protected function parseStatementEndTimestamp()
{
return parent::parseTimestampFromStatement('60[FM]');
return $this->parseTimestampFromStatement('60[FM]');
}

/**
Expand All @@ -59,7 +59,7 @@ protected function parseStatementEndTimestamp()
*/
protected function parseStatementEndPrice()
{
return parent::parseStatementPrice('62[FM]');
return $this->parseStatementPrice('62[FM]');
}

/**
Expand Down

0 comments on commit b04cdd9

Please sign in to comment.