Skip to content

Commit

Permalink
- Monolog now optional (just a suggestion in composer.json now)
Browse files Browse the repository at this point in the history
- Fix for bookingDate parsing. Not every bank returns the booking date in their MT940
  • Loading branch information
mschindler committed Sep 1, 2016
1 parent 5c213ad commit 3ab41c9
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 99 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
},
"require": {
"php": ">=5.3.2",
"monolog/monolog": "^1.18"
"psr/log": "~1.0"
},
"require-dev": {
},
"suggest": {
"monolog/monolog": "Allow sending log messages to a variety of different handlers"
}
}
82 changes: 2 additions & 80 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions lib/Fhp/Dialog/Dialog.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
use Fhp\Segment\HKIDN;
use Fhp\Segment\HKSYN;
use Fhp\Segment\HKVVB;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

/**
* Class Dialog
Expand Down Expand Up @@ -168,16 +168,16 @@ protected function logMessage($type, $code, $message)
{
switch (substr($code, 0, 1)) {
case '0':
$level = Logger::INFO;
$level = LogLevel::INFO;
break;
case "3":
$level = Logger::WARNING;
$level = LogLevel::WARNING;
break;
case "9":
$level = Logger::ERROR;
$level = LogLevel::ERROR;
break;
default:
$level = Logger::INFO;
$level = LogLevel::INFO;
}

$this->logger->log($level, '[' . $type . '] ' . $message);
Expand Down
16 changes: 5 additions & 11 deletions lib/Fhp/FinTs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
use Fhp\Segment\HKKAZ;
use Fhp\Segment\HKSAL;
use Fhp\Segment\HKSPA;
use Monolog\Handler\ErrorLogHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

/**
* Class FinTs
* Class FinTs.
*
* @package Fhp
*/
class FinTs
{
const DEFAULT_COUNTRY_CODE = 280;
const LOGGER_NAME = 'Fhp';

/** @var Logger */
/** @var LoggerInterface */
protected $logger;
/** @var string */
protected $server;
Expand Down Expand Up @@ -71,6 +70,7 @@ public function __construct(
) {
$this->server = $server;
$this->port = $port;
$this->logger = null == $logger ? new NullLogger() : $logger;

// escaping of bank code not really needed here as it should
// never have special chars. But we just do it to ensure
Expand All @@ -85,12 +85,6 @@ public function __construct(

$this->adapter = new Curl($this->server, $this->port);
$this->connection = new Connection($this->adapter);

if (null == $logger) {
$this->logger = new Logger(static::LOGGER_NAME);
$handler = new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, Logger::INFO);
$this->logger->pushHandler($handler);
}
}

/**
Expand Down
8 changes: 7 additions & 1 deletion lib/Fhp/Parser/MT940.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,13 @@ protected function parseToArray()
// 0509 = booking date
$year = substr($transaction, 0, 2);
$valutaDate = $this->getDate($year . substr($transaction, 2, 6));
$bookingDate = $this->getDate($year . substr($transaction, 6, 10));

$bookingDate = substr($transaction, 6, 10);
if (preg_match('/^\d{4}$/', $bookingDate)) {
$bookingDate = $this->getDate($year . $bookingDate);
} else {
$bookingDate = null;
}

$trx[count($trx) - 1]['booking_date'] = $bookingDate;
$trx[count($trx) - 1]['valuta_date'] = $valutaDate;
Expand Down
1 change: 0 additions & 1 deletion lib/Fhp/Response/GetSEPAAccounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function getSEPAAccounts()
protected function createModelFromArray(array $array)
{
$account = new SEPAAccount();
$account->setIsSepaCapable($array[0] == 'J' ? true : false);
$account->setIban($array[1]);
$account->setBic($array[2]);
$account->setAccountNumber($array[3]);
Expand Down

0 comments on commit 3ab41c9

Please sign in to comment.