Skip to content

Commit

Permalink
Merge pull request #36 from axlon/canary-islands
Browse files Browse the repository at this point in the history
[3.x] Add support for the Canary Islands
  • Loading branch information
axlon authored Sep 10, 2024
2 parents acd390f + 04601f9 commit 20b5483
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/PostalCodeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

class PostalCodeValidator
{
/**
* The country codes that are aliases for other country codes.
*/
private const ALIASES = [
'IC' => 'ES',
];

/**
* The matching patterns.
*
Expand Down Expand Up @@ -101,6 +108,10 @@ public function patternFor(string $countryCode): ?string
{
$countryCode = strtoupper($countryCode);

if (array_key_exists($countryCode, self::ALIASES)) {
$countryCode = self::ALIASES[$countryCode];
}

return $this->patternOverrides[$countryCode]
?? $this->patterns[$countryCode]
?? null;
Expand All @@ -117,6 +128,7 @@ public function supports(string $countryCode): bool
$countryCode = strtoupper($countryCode);

return array_key_exists($countryCode, $this->patternOverrides)
|| array_key_exists($countryCode, $this->patterns);
|| array_key_exists($countryCode, $this->patterns)
|| array_key_exists($countryCode, self::ALIASES);
}
}
8 changes: 8 additions & 0 deletions tests/Unit/PostalCodeValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ protected function setUp(): void
);
}

/**
* @link https://github.com/axlon/laravel-postal-code-validation/issues/35
*/
public function testCanaryIslands(): void
{
$this->assertTrue($this->validator->passes('IC', '38580'));
}

/**
* Test if the shipped examples pass validation.
*
Expand Down

0 comments on commit 20b5483

Please sign in to comment.