From fa84ac9bc98675831bb082aa1dc97a9dad00b292 Mon Sep 17 00:00:00 2001 From: Robin Speekenbrink Date: Mon, 18 Mar 2019 15:49:31 +0100 Subject: [PATCH] moved the parsing of type and simplified the parsing method --- .../Transaction/Type.php} | 15 +--- src/Parser/Banking/Mt940/Engine/Knab.php | 48 +++++------- src/Parser/Banking/Mt940/Engine/Rabo.php | 77 ++++++++----------- 3 files changed, 51 insertions(+), 89 deletions(-) rename src/{Objects/TransactionType.php => Banking/Transaction/Type.php} (76%) diff --git a/src/Objects/TransactionType.php b/src/Banking/Transaction/Type.php similarity index 76% rename from src/Objects/TransactionType.php rename to src/Banking/Transaction/Type.php index 835d9b1..1f5ffef 100644 --- a/src/Objects/TransactionType.php +++ b/src/Banking/Transaction/Type.php @@ -1,31 +1,20 @@ Type::SEPA_TRANSFER, + 544 => Type::SEPA_TRANSFER, + 547 => Type::SEPA_TRANSFER, + 64 => Type::SEPA_DIRECTDEBIT, + 93 => Type::BANK_COSTS, + 13 => Type::PAYMENT_TERMINAL, + 30 => Type::PAYMENT_TERMINAL, + 'MSC' => Type::BANK_INTEREST, + 'TRF' => Type::UNKNOWN, + ]; + $code = $this->parseTransactionCode(); - switch ($code) { - case 541: - case 544: - case 547: - $result = TransactionType::get(TransactionType::SEPA_TRANSFER); - break; - case 64: - $result = TransactionType::get(TransactionType::SEPA_DIRECTDEBIT); - break; - case 93: - $result = TransactionType::get(TransactionType::BANK_COSTS); - break; - case 13: - case 30: - $result = TransactionType::get(TransactionType::PAYMENT_TERMINAL); - break; - case "MSC": - $result = TransactionType::get(TransactionType::BANK_INTEREST); - break; - case "TRF": - $result = TransactionType::get(TransactionType::UNKNOWN); - break; - default: - var_dump($code); - var_dump($this->getCurrentTransactionData()); die(); - throw new \RuntimeException("Don't know code $code for RABOBANK"); + if (array_key_exists($code, $map)) { + return $map[$code]; } - - return $result; + throw new \RuntimeException("Don't know code $code for this bank"); } } diff --git a/src/Parser/Banking/Mt940/Engine/Rabo.php b/src/Parser/Banking/Mt940/Engine/Rabo.php index 7e4efba..a22e3ba 100644 --- a/src/Parser/Banking/Mt940/Engine/Rabo.php +++ b/src/Parser/Banking/Mt940/Engine/Rabo.php @@ -3,6 +3,7 @@ namespace Kingsquare\Parser\Banking\Mt940\Engine; use Kingsquare\Parser\Banking\Mt940\Engine; +use Kingsquare\Banking\Transaction\Type; /** * @author Kingsquare (source@kingsquare.nl) @@ -159,58 +160,40 @@ public static function isApplicable($string) return strpos(strtok($string, "\r\n\t"), ':940:') !== false; } + /** + * @return int + */ protected function parseTransactionType() { + static $map = [ + 102 => Type::SEPA_TRANSFER, // "Betaalopdracht IDEAL" + 541 => Type::SEPA_TRANSFER, + 544 => Type::SEPA_TRANSFER, + 547 => Type::SEPA_TRANSFER, + 504 => Type::SAVINGS_TRANSFER, + 691 => Type::SAVINGS_TRANSFER, + 64 => Type::SEPA_DIRECTDEBIT, + 93 => Type::BANK_COSTS, + 12 => Type::PAYMENT_TERMINAL, + 13 => Type::PAYMENT_TERMINAL, + 30 => Type::PAYMENT_TERMINAL, + 29 => Type::ATM_WITHDRAWAL, + 31 => Type::ATM_WITHDRAWAL, + 79 => Type::UNKNOWN, + 'MSC' => Type::BANK_INTEREST, + ]; + $code = $this->parseTransactionCode(); - switch ($code) { - case 541: - case 544: - case 102: // "Betaalopdracht IDEAL" - case 547: - $result = TransactionType::get(TransactionType::SEPA_TRANSFER); - break; - - case 504: - case 691: - $result = TransactionType::get(TransactionType::SAVINGS_TRANSFER); - break; - case 64: - $result = TransactionType::get(TransactionType::SEPA_DIRECTDEBIT); - break; - case 93: - $result = TransactionType::get(TransactionType::BANK_COSTS); - break; - case 13: - case 12: - case 30: - $result = TransactionType::get(TransactionType::PAYMENT_TERMINAL); - break; - case 29: - case 31: - $result = TransactionType::get(TransactionType::ATM_WITHDRAWAL); - break; - case "MSC": - $result = TransactionType::get(TransactionType::BANK_INTEREST); - break; - case 404: // "Buitenland transactie credit" - if (stripos($this->getCurrentTransactionData(), 'eurobetaling') !== false) { - $result = TransactionType::get(TransactionType::SEPA_TRANSFER); - } else { - $result = TransactionType::get(TransactionType::TRANSFER); - } - - break; - case 79: // "Acceptgiro Mobiel Bankieren" - $result = TransactionType::get(TransactionType::UNKNOWN); - break; - - default: - var_dump($code); - var_dump($this->getCurrentTransactionData()); die(); - throw new \RuntimeException("Don't know code $code for RABOBANK"); + if ($code === 404) { + return (stripos($this->getCurrentTransactionData(), + 'eurobetaling') !== false) ? Type::SEPA_TRANSFER : Type::TRANSFER; + } + + if (array_key_exists($code, $map)) { + return $map[$code]; } - return $result; + throw new \RuntimeException("Don't know code $code for this bank"); } }