From ab1f5d255a5d6a8d0e6e0ce8a7f4e15310dcbf68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Kobza?= Date: Fri, 7 Jul 2023 09:41:36 +0200 Subject: [PATCH] Adding a PT company registration number --- src/CompanyRegistrationNumber.php | 15 ++++++++++++++- tests/CompanyRegistrationNumberTest.phpt | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/CompanyRegistrationNumber.php b/src/CompanyRegistrationNumber.php index bd2acfd..d988413 100644 --- a/src/CompanyRegistrationNumber.php +++ b/src/CompanyRegistrationNumber.php @@ -48,7 +48,8 @@ private function isValid( $this->isValidCH($value) || $this->isValidDE($value) || $this->isValidHR($value) || - $this->isValidNL($value); + $this->isValidNL($value) || + $this->isValidPT($value); } private function isValidCH( @@ -315,4 +316,16 @@ private function isValidNL( return (bool) \preg_match('#^(\d{9}B\d{2}|\d{8})$#', $value); } + private function isValidPT( + string $value + ): bool { + $value = (string) \preg_replace( + '#\s+#', + '', + $value + ); + + return (bool) \preg_match('#^\d{9}$#', $value); + } + } diff --git a/tests/CompanyRegistrationNumberTest.phpt b/tests/CompanyRegistrationNumberTest.phpt index f7a46f9..5f5949d 100644 --- a/tests/CompanyRegistrationNumberTest.phpt +++ b/tests/CompanyRegistrationNumberTest.phpt @@ -51,6 +51,7 @@ final class CompanyRegistrationNumberTest extends TestCase '32145678934', //HR '33127977', // NL '001632553B28', // NL + '500271615', // PT ]; foreach ($validValues as $validValue) {