Skip to content

Commit

Permalink
minor refactor of the Triodos engine
Browse files Browse the repository at this point in the history
A bit more DRY way of parsing out the description onto 'parts'
  • Loading branch information
fruitl00p committed Mar 23, 2015
1 parent 0187b58 commit a742cc6
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions src/Parser/Banking/Mt940/Engine/Triodos.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Triodos extends Engine
{
/**
* returns the name of the bank
*
* @return string
*/
protected function parseStatementBank()
Expand All @@ -21,6 +22,7 @@ protected function parseStatementBank()

/**
* Overloaded: the bankaccount is always prefixed
*
* @inheritdoc
*/
protected function parseStatementAccount()
Expand All @@ -36,6 +38,7 @@ protected function parseStatementAccount()

/**
* Overloaded: According to spec, field :28: is always 1
*
* @inheritdoc
*/
protected function parseStatementNumber()
Expand All @@ -45,20 +48,22 @@ protected function parseStatementNumber()

/**
* Overloaded: According to spec, field :28: is always 000
*
* @inheritdoc
*/
protected function parseTransactionCode()
{
return '000';
}


/**
* Overloaded: It might be IBAN or not and depending on that return a different part of the description
*
* @inheritdoc
*/
protected function parseTransactionAccount()
{

$description = parent::parseTransactionDescription();
$parts = explode('>', $description);
array_shift($parts); // remove 000 prefix
$parts = $this->getDescriptionParts();
$account = $parts[0];
if (preg_match('#[A-Z]{2}[0-9]{2}[A-Z]{4}(.*)#', $parts[2], $results)) {
$account = $parts[2];
Expand All @@ -69,11 +74,14 @@ protected function parseTransactionAccount()
return $this->sanitizeAccount($account);
}

/**
* Overloaded: It might be IBAN or not and depending on that return a different part of the description
*
* @inheritdoc
*/
protected function parseTransactionAccountName()
{
$description = parent::parseTransactionDescription();
$parts = explode('>', $description);
array_shift($parts); // remove 000 prefix
$parts = $this->getDescriptionParts();
array_shift($parts); // remove BBAN / BIC code
if (preg_match('#[A-Z]{2}[0-9]{2}[A-Z]{4}(.*)#', $parts[1], $results)) {
array_shift($parts); // remove IBAN too
Expand All @@ -85,13 +93,12 @@ protected function parseTransactionAccountName()

/**
* Crude parsing of the combined iban / non iban description field
*
* @inheritdoc
*/
protected function parseTransactionDescription()
{
$description = parent::parseTransactionDescription();
$parts = explode('>', $description);
array_shift($parts); // remove 000 prefix
$parts = $this->getDescriptionParts();
array_shift($parts); // remove BBAN / BIC code
if (preg_match('#[A-Z]{2}[0-9]{2}[A-Z]{4}(.*)#', $parts[1], $results)) {
array_shift($parts); // remove IBAN too
Expand All @@ -106,13 +113,32 @@ protected function parseTransactionDescription()
return $this->sanitizeDescription(implode('', $parts));
}

/**
* In Triodos everything is put into :86: field with '>\d{2}' seperators
* This method parses that out and returns the array
*
* @return array
*/
private function getDescriptionParts() {
$description = parent::parseTransactionDescription();
$parts = explode('>', $description);
array_shift($parts); // remove 000 prefix
return $parts;
}

/**
* Overloaded: Do not skip a header
*
* @inheritdoc
*/
protected function parseStatementData()
{
return preg_split('/(^:20:|^-X{,3}$|\Z)/sm', $this->getRawData(), -1, PREG_SPLIT_NO_EMPTY);
return preg_split(
'/(^:20:|^-X{,3}$|\Z)/sm',
$this->getRawData(),
-1,
PREG_SPLIT_NO_EMPTY
);
}

}

0 comments on commit a742cc6

Please sign in to comment.