-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the `is_bic` check to the validation rules. This enhancement ensures validation of Bank Identifier Codes (BIC), enforcing data accuracy for banking codes. Also updated schema examples and unit tests.
- Loading branch information
Showing
9 changed files
with
134 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,7 @@ | |
|
||
"phone" : "ALL", | ||
"is_iban" : true, | ||
"is_bic" : true, | ||
|
||
"is_version" : true, | ||
"is_punct" : true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,7 @@ | |
|
||
'phone' => 'ALL', | ||
'is_iban' => true, | ||
'is_bic' => true, | ||
|
||
'is_version' => true, | ||
'is_punct' => true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,7 @@ columns: | |
|
||
phone: ALL | ||
is_iban: true | ||
is_bic: true | ||
|
||
is_version: true | ||
is_punct: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\CsvBlueprint\Rules\Cell; | ||
|
||
final class IsBic extends AbstractCellRule | ||
{ | ||
public function getHelpMeta(): array | ||
{ | ||
return [ | ||
[], | ||
[ | ||
self::DEFAULT => [ | ||
'true', | ||
'Validates a Bank Identifier Code (BIC) according to ISO 9362 standards. ' . | ||
'See: https://en.wikipedia.org/wiki/ISO_9362', | ||
], | ||
], | ||
]; | ||
} | ||
|
||
public function validateRule(string $cellValue): ?string | ||
{ | ||
if ($cellValue === '') { | ||
return null; | ||
} | ||
|
||
if (\preg_match('/^[A-Za-z]{4}[A-Za-z]{2}[A-Za-z0-9]{2}([A-Za-z0-9]{3})?$/', $cellValue) === 0) { | ||
return "The value \"<c>{$cellValue}</c>\" is not a valid BIC number (ISO 9362)."; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\PHPUnit\Rules\Cell; | ||
|
||
use JBZoo\CsvBlueprint\Rules\Cell\IsBic; | ||
use JBZoo\PHPUnit\Rules\TestAbstractCellRule; | ||
|
||
use function JBZoo\PHPUnit\isSame; | ||
|
||
final class IsBicTest extends TestAbstractCellRule | ||
{ | ||
protected string $ruleClass = IsBic::class; | ||
|
||
public function testPositive(): void | ||
{ | ||
$rule = $this->create(true); | ||
isSame(null, $rule->validate('')); | ||
|
||
$valid = [ | ||
'', | ||
'DEUTDEFF', // Deutsche Bank primary office, Frankfurt, Germany | ||
'NEDSZAJJXXX', // Nedbank in Johannesburg, South Africa, with primary office code | ||
'BNPAFRPP', // BNP Paribas primary office, Paris, France | ||
'CHASUS33', // JPMorgan Chase Bank, New York, USA | ||
'HSBCGB2L', // HSBC Bank, London, UK | ||
'UNCRIT2B912', // UniCredit Bank, Milan, Italy, specific branch | ||
'DABADKKK', // Danske Bank, Copenhagen, Denmark | ||
'NORDEAHH', // Nordea, Helsinki, Finland | ||
'AIBKIE2D', // AIB Bank, Dublin, Ireland | ||
'CTBAAU2S', // Commonwealth Bank of Australia, Sydney, Australia | ||
]; | ||
|
||
foreach ($valid as $value) { | ||
isSame('', $rule->test($value), $value); | ||
} | ||
|
||
$rule = $this->create(false); | ||
isSame(null, $rule->validate(' 1')); | ||
} | ||
|
||
public function testNegative(): void | ||
{ | ||
$rule = $this->create(true); | ||
|
||
$invalid = [ | ||
';', | ||
' ', | ||
'ZZ32 5000 5880 7742', | ||
'123456789', | ||
'aBc 123', | ||
'aBc-123', | ||
]; | ||
|
||
foreach ($invalid as $value) { | ||
isSame( | ||
"The value \"{$value}\" is not a valid BIC number (ISO 9362).", | ||
$rule->test($value), | ||
$value, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters