Skip to content

Commit

Permalink
Add Syntax Check to Slovakia
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbraunc24 committed Jul 16, 2024
1 parent af4935e commit 42f42fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spec/loophp/Tin/CountryHandler/SlovakiaSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
16 changes: 15 additions & 1 deletion src/CountryHandler/Slovakia.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 42f42fb

Please sign in to comment.