Skip to content

Commit

Permalink
Add Syntax Check to Slovakia (#45)
Browse files Browse the repository at this point in the history
* Add Syntax Check to Slovakia

* Fix codestyle

* Refactor validRule of Slovakia

---------

Co-authored-by: Jonas Braun <[email protected]>
  • Loading branch information
iekadou and jonasbraunc24 authored Jul 17, 2024
1 parent 111a75b commit d3a6a1e
Show file tree
Hide file tree
Showing 2 changed files with 22 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 @@ -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';
}
19 changes: 18 additions & 1 deletion src/CountryHandler/Slovakia.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace loophp\Tin\CountryHandler;

use function strlen;

/**
* Slovakia.
*/
Expand All @@ -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);
Expand Down

0 comments on commit d3a6a1e

Please sign in to comment.