Skip to content

Commit

Permalink
correct the check if 28C is null or is zero (#32)
Browse files Browse the repository at this point in the history
a fix for #31
  • Loading branch information
twitnic authored Jun 10, 2020
1 parent 9e06d67 commit df28b8d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@
"description": "An MT940 bank statement parser for PHP",
"keywords": ["mt940", "parser", "parsing"],
"license": "MIT",
"authors": [{
"name": "Sander Marechal",
"email": "[email protected]",
"homepage": "http://www.jejik.com"
}],
"authors": [
{
"name": "Sander Marechal",
"email": "[email protected]",
"homepage": "http://www.jejik.com"
},
{
"name": "Powercloud GmbH / Dominic Richter",
"email": "[email protected]",
"homepage": "https://www.powercloud.de"
}
],
"require": {
"php": ">=7.1.0"
},
Expand Down
11 changes: 6 additions & 5 deletions lib/Jejik/MT940/Parser/AbstractParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public function getTransactionReferenceNumber(string $text): string
public function isBLZAllowed($text): bool
{
$this->checkCRLF($text);
if ($account = $this->getLine('25', $text)) {
$account = $this->getLine('25', $text);
if (!is_null($account)) {
$accountExploded = explode('/', $account);
if (isset($accountExploded[0]) && in_array($accountExploded[0], $this->getAllowedBLZ())) {
return true;
Expand Down Expand Up @@ -143,7 +144,7 @@ protected function getLine(
int $offset = 0,
int &$position = null,
int &$length = null
): string {
): ?string {
$pcre = '/(?:^|\r\n)\:(' . $id . ')\:' // ":<id>:" at the start of a line
. '(.+)' // Contents of the line
. '(:?$|\r\n\:[[:alnum:]]{2,3}\:)' // End of the text or next ":<id>:"
Expand All @@ -160,8 +161,7 @@ protected function getLine(
}
}


return '';
return null;
}

/**
Expand Down Expand Up @@ -301,7 +301,8 @@ protected function statementBody(string $text): ?Statement
*/
protected function statementNumber(string $text): ?string
{
if ($number = $this->getLine('28|28C', $text)) {
$number = $this->getLine('28|28C', $text);
if (!is_null($number)) {
return $number;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Jejik/MT940/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ public function createClosingBalance(): BalanceInterface
* @param mixed $interface The interface the class must implement //TODO mixed is a workaround for StdClass
* @param array $params Parameters to pass to the callable
*
* @return object An object that implements the interface
* @return Account|Statement|Balance An object that implements the interface
*/
protected function createObject($className, $interface, $params = [])
{
Expand Down

0 comments on commit df28b8d

Please sign in to comment.