Add IBAN validator with QA workflows
PHP_CodeSniffer / PHP_CodeSniffer (push) Successful in 1m34s
PHPStan / PHPStan with PHP 8.5 prefer-lowest (push) Successful in 1m42s
PHPStan / PHPStan with PHP 8.1 prefer-stable (push) Successful in 1m56s
PHPStan / PHPStan with PHP 8.1 prefer-lowest (push) Successful in 1m56s
PHPStan / PHPStan with PHP 8.5 prefer-stable (push) Successful in 55s
PHPStan / PHPStan with PHP 8.6 prefer-source (push) Successful in 1m0s
PHPUnit / PHPUnit with PHP 8.1 prefer-lowest (push) Successful in 1m19s
PHPUnit / PHPUnit with PHP 8.1 prefer-stable (push) Successful in 1m23s
PHPUnit / PHPUnit with PHP 8.5 prefer-lowest (push) Successful in 55s
Smoke / Produce an output (push) Successful in 17s
PHPUnit / PHPUnit with PHP 8.5 prefer-stable (push) Successful in 57s
Smoke / Consume the output (push) Successful in 13s
PHPUnit / PHPUnit with PHP 8.6 prefer-source (push) Successful in 53s

This commit is contained in:
Christian Todt
2026-09-16 14:22:55 +02:00
commit 1295f234e4
15 changed files with 900 additions and 0 deletions
+51
View File
@@ -0,0 +1,51 @@
<?php
declare(strict_types = 1);
namespace Systopia\PipelineTest;
final class IbanValidator {
private const LENGTHS = [
'AT' => 20,
'BE' => 16,
'CH' => 21,
'DE' => 22,
'ES' => 24,
'FR' => 27,
'IT' => 27,
'LU' => 20,
'NL' => 18,
];
public function isValid(string $iban): bool {
$normalized = $this->normalize($iban);
if (1 !== preg_match('/^[A-Z]{2}[0-9]{2}[A-Z0-9]+$/', $normalized)) {
return FALSE;
}
if (strlen($normalized) !== (self::LENGTHS[substr($normalized, 0, 2)] ?? NULL)) {
return FALSE;
}
return 1 === $this->mod97(substr($normalized, 4) . substr($normalized, 0, 4));
}
public function normalize(string $iban): string {
return strtoupper(str_replace([' ', '-'], '', $iban));
}
private function mod97(string $rearranged): int {
$remainder = 0;
foreach (str_split($rearranged) as $character) {
$digits = ctype_digit($character) ? $character : (string) (ord($character) - 55);
foreach (str_split($digits) as $digit) {
$remainder = ($remainder * 10 + (int) $digit) % 97;
}
}
return $remainder;
}
}