Skip to content

Commit 111a75b

Browse files
Add supported Country check (#46)
* Add supported Country check * Fix coding style --------- Co-authored-by: Jonas Braun <[email protected]>
1 parent af4935e commit 111a75b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/TIN.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ final class TIN
4848
/**
4949
* @var array<string, class-string>
5050
*/
51-
private $algorithms = [
51+
private static $algorithms = [
5252
'AT' => Austria::class,
5353
'BE' => Belgium::class,
5454
'BG' => Bulgaria::class,
@@ -109,6 +109,17 @@ public static function fromSlug(string $slug): TIN
109109
return new self($slug);
110110
}
111111

112+
public static function isCountrySupported(string $countryCode): bool
113+
{
114+
foreach (self::$algorithms as $algorithm) {
115+
if (true === $algorithm::supports($countryCode)) {
116+
return true;
117+
}
118+
}
119+
120+
return false;
121+
}
122+
112123
public function isValid(bool $strict = false): bool
113124
{
114125
try {
@@ -125,7 +136,7 @@ public function isValid(bool $strict = false): bool
125136
*/
126137
private function getAlgorithm(string $country, ?string $tin = null): CountryHandlerInterface
127138
{
128-
foreach ($this->algorithms as $algorithm) {
139+
foreach (self::$algorithms as $algorithm) {
129140
if (true === $algorithm::supports($country)) {
130141
$handler = new $algorithm($tin);
131142

0 commit comments

Comments
 (0)