From fb7b3539cec8e13d8279c73ef31696ed9466d48f Mon Sep 17 00:00:00 2001 From: Alex Schickedanz Date: Tue, 23 Feb 2021 00:07:35 +0100 Subject: [PATCH] Add support for keys `pstladr` and `cdtrpstladr`. Both are aliases for `dbtrpstladr`. --- CHANGE_LOG.md | 3 +++ src/SepaUtilities.php | 4 +++- tests/SepaUtilitiesTest.php | 27 ++++++++++++++++----------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/CHANGE_LOG.md b/CHANGE_LOG.md index 5bdec9d..6d2c618 100644 --- a/CHANGE_LOG.md +++ b/CHANGE_LOG.md @@ -1,6 +1,9 @@ Sephpa - Change Log =============== +## 1.3.2 - Feb 23, 21 +- Added support for keys `pstladr` and `cdtrpstladr`. Both are aliases for `dbtrpstladr`. + ## 1.3.1 - Feb 14, 21 - Fixed: sanitizing of new `adrline` inputs was broken in case an array was used. - SepaUtilities are now tested on PHP 8.0. diff --git a/src/SepaUtilities.php b/src/SepaUtilities.php index dbf1ee3..46dcb61 100644 --- a/src/SepaUtilities.php +++ b/src/SepaUtilities.php @@ -643,7 +643,7 @@ private static function getValFromMultiDimInput(array &$input, $keys) * 'ultmtcdrt','ultmtdbtr','rmtinf','orgnldbtracct_iban','iban','bic', * 'ccy','amendment', 'btchbookg','instdamt','seqtp','lclinstrm', * 'elctrncsgntr','reqdexctndt','purp','ctgypurp','orgnldbtragt', 'adrline' - * 'ctry', 'dbtrpstladr' + * 'ctry', 'dbtrpstladr', 'cdtrpstladr', 'pstladr' * @param mixed $input * @param array $options See `checkBIC()`, `checkIBAN()` and `checkLocalInstrument()` for * details. In addition one can use the key `version`, which is relevant @@ -727,6 +727,8 @@ public static function check(string $field, $input, array $options = null) case 'ref': case 'orgnldbtragt': return $input; // nothing to check here case 'ctry': return self::checkCountryCode($input); + case 'pstladr': + case 'cdtrpstladr': case 'dbtrpstladr': if(is_array($input) && count($input) > 0 && count($input) <= 2) { foreach($input as $key => &$value) diff --git a/tests/SepaUtilitiesTest.php b/tests/SepaUtilitiesTest.php index be413ed..7b8d169 100644 --- a/tests/SepaUtilitiesTest.php +++ b/tests/SepaUtilitiesTest.php @@ -521,17 +521,22 @@ public function testAdrLine() self::assertFalse(SepaUtilities::check('adrLine', ['test1','test2','test3'])); } - public function testDbtrPstlAdr() + public function testPstlAdr() { - // valid - self::assertSame(['ctry' => 'DE'], SepaUtilities::check('dbtrpstladr', ['ctry' => 'dE'])); - self::assertSame(['adrline' => 'test'], SepaUtilities::check('dbtrpstladr', ['adrline' => 'test'])); - self::assertSame(['adrline' => ['test']], SepaUtilities::check('dbtrpstladr', ['adrline' => ['test']])); - self::assertSame(['ctry' => 'DE', 'adrLine' => ['test']], SepaUtilities::check('dbtrpstladr', ['ctry' => 'dE', 'adrLine' => ['test']])); - - // invalid - self::assertFalse(SepaUtilities::check('dbtrpstladr', [])); - self::assertFalse(SepaUtilities::check('dbtrpstladr', ['test' => 1])); - self::assertFalse(SepaUtilities::check('dbtrpstladr', ['ctry' => 'dE', 'adrline' => ['test'], 'somethingelse' => 1])); + foreach(['dbtrpstladr', 'cdtrpstladr', 'pstladr'] as $key) + { + // valid + self::assertSame(['ctry' => 'DE'], SepaUtilities::check($key, ['ctry' => 'dE'])); + self::assertSame(['adrline' => 'test'], SepaUtilities::check($key, ['adrline' => 'test'])); + self::assertSame(['adrline' => ['test']], SepaUtilities::check($key, ['adrline' => ['test']])); + self::assertSame(['ctry' => 'DE', 'adrLine' => ['test']], SepaUtilities::check($key, ['ctry' => 'dE', 'adrLine' => ['test']])); + + // invalid + self::assertFalse(SepaUtilities::check($key, [])); + self::assertFalse(SepaUtilities::check($key, ['test' => 1])); + self::assertFalse(SepaUtilities::check($key, ['ctry' => 'dE', + 'adrline' => ['test'], + 'somethingelse' => 1])); + } } }