From 42f42fb8b2f16540972ed84928cbc6a377152f31 Mon Sep 17 00:00:00 2001 From: Jonas Braun Date: Tue, 16 Jul 2024 17:27:17 +0200 Subject: [PATCH] Add Syntax Check to Slovakia --- spec/loophp/Tin/CountryHandler/SlovakiaSpec.php | 4 ++++ src/CountryHandler/Slovakia.php | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/spec/loophp/Tin/CountryHandler/SlovakiaSpec.php b/spec/loophp/Tin/CountryHandler/SlovakiaSpec.php index 8b73c66..e607f05 100644 --- a/spec/loophp/Tin/CountryHandler/SlovakiaSpec.php +++ b/spec/loophp/Tin/CountryHandler/SlovakiaSpec.php @@ -18,4 +18,8 @@ class SlovakiaSpec extends AbstractAlgorithmSpec public const VALID_NUMBER = '7711167420'; public const VALID_NUMBER2 = '281203054'; + + public const VALID_NUMBER3 = '2822030541'; + + public const INVALID_SYNTAX = '2812030541'; } diff --git a/src/CountryHandler/Slovakia.php b/src/CountryHandler/Slovakia.php index 1532b34..2a4aafd 100644 --- a/src/CountryHandler/Slovakia.php +++ b/src/CountryHandler/Slovakia.php @@ -24,14 +24,28 @@ final class Slovakia extends CountryHandler */ public const LENGTH = 10; + public const PATTERN = '([1-9]\\d[234789]\\d{7})|(\\d{2}[0156]\\d[0-3]\\d{4,5})'; + protected function hasValidLength(string $tin): bool { $c1c2 = substr($tin, 0, 2); if (54 > $c1c2) { - return $this->matchLength($tin, self::LENGTH - 1); + return $this->matchLength($tin, self::LENGTH) || $this->matchLength($tin, self::LENGTH - 1); } return parent::hasValidLength($tin); } + + public function hasValidRule(string $tin): bool + { + if (strlen($tin) === 10 + && (int) $tin % 11 === 0) { + return true; + } + if (strlen($tin) === 10) { + return ((int) substr($tin, 0, 9) % 11) % 10 === (int) substr($tin, 9, 1); + } + return strlen($tin) === 9; + } }