diff --git a/spec/loophp/Tin/CountryHandler/SlovakiaSpec.php b/spec/loophp/Tin/CountryHandler/SlovakiaSpec.php index 8b73c66..23735cb 100644 --- a/spec/loophp/Tin/CountryHandler/SlovakiaSpec.php +++ b/spec/loophp/Tin/CountryHandler/SlovakiaSpec.php @@ -15,7 +15,11 @@ class SlovakiaSpec extends AbstractAlgorithmSpec { public const INVALID_NUMBER_LENGTH = '77111674201'; + public const INVALID_SYNTAX = '2812030541'; + public const VALID_NUMBER = '7711167420'; public const VALID_NUMBER2 = '281203054'; + + public const VALID_NUMBER3 = '2822030541'; } diff --git a/src/CountryHandler/Slovakia.php b/src/CountryHandler/Slovakia.php index 1532b34..50a4daf 100644 --- a/src/CountryHandler/Slovakia.php +++ b/src/CountryHandler/Slovakia.php @@ -9,6 +9,8 @@ namespace loophp\Tin\CountryHandler; +use function strlen; + /** * Slovakia. */ @@ -24,12 +26,27 @@ 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})'; + + public function hasValidRule(string $tin): bool + { + if (strlen($tin) === 10) { + if ((int) $tin % 11 === 0) { + return true; + } + + return (int) substr($tin, 9, 1) === ((int) substr($tin, 0, 9) % 11) % 10; + } + + return true; + } + 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);