Skip to content

Commit

Permalink
Add support for keys pstladr and cdtrpstladr.
Browse files Browse the repository at this point in the history
Both are aliases for `dbtrpstladr`.
  • Loading branch information
AbcAeffchen committed Feb 22, 2021
1 parent 01fe412 commit fb7b353
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
3 changes: 3 additions & 0 deletions CHANGE_LOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/SepaUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 16 additions & 11 deletions tests/SepaUtilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
}
}
}

0 comments on commit fb7b353

Please sign in to comment.