Skip to content

Commit

Permalink
Add supported Country check (#46)
Browse files Browse the repository at this point in the history
* Add supported Country check

* Fix coding style

---------

Co-authored-by: Jonas Braun <[email protected]>
  • Loading branch information
iekadou and jonasbraunc24 authored Jul 17, 2024
1 parent af4935e commit 111a75b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/TIN.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class TIN
/**
* @var array<string, class-string>
*/
private $algorithms = [
private static $algorithms = [
'AT' => Austria::class,
'BE' => Belgium::class,
'BG' => Bulgaria::class,
Expand Down Expand Up @@ -109,6 +109,17 @@ public static function fromSlug(string $slug): TIN
return new self($slug);
}

public static function isCountrySupported(string $countryCode): bool
{
foreach (self::$algorithms as $algorithm) {
if (true === $algorithm::supports($countryCode)) {
return true;
}
}

return false;
}

public function isValid(bool $strict = false): bool
{
try {
Expand All @@ -125,7 +136,7 @@ public function isValid(bool $strict = false): bool
*/
private function getAlgorithm(string $country, ?string $tin = null): CountryHandlerInterface
{
foreach ($this->algorithms as $algorithm) {
foreach (self::$algorithms as $algorithm) {
if (true === $algorithm::supports($country)) {
$handler = new $algorithm($tin);

Expand Down

0 comments on commit 111a75b

Please sign in to comment.