From b6ec153f88b593d52c20a98bd012f53fd60966ef Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 26 May 2025 19:53:19 +0800 Subject: yue-z only supports HK or Macau suffix --- tests/RegistrationNumberTest.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/RegistrationNumberTest.php b/tests/RegistrationNumberTest.php index a6cbbd8..6516eb3 100644 --- a/tests/RegistrationNumberTest.php +++ b/tests/RegistrationNumberTest.php @@ -423,10 +423,6 @@ final class RegistrationNumberTest extends TestCase ['粤Z00000港'], ['粤Z0000澳'], ['粤Z00000澳'], - ['粤Z0000试'], - ['粤Z00000试'], - ['粤Z0000超'], - ['粤Z00000超'], ]; } @@ -439,6 +435,16 @@ final class RegistrationNumberTest extends TestCase ['粤E0006假'], ['粤E0006港'], ['粤E0000澳'], + ['粤Z0000警'], + ['粤Z00000警'], + ['粤Z0000学'], + ['粤Z00000学'], + ['粤Z0000挂'], + ['粤Z00000挂'], + ['粤Z0000试'], + ['粤Z00000试'], + ['粤Z0000超'], + ['粤Z00000超'], ]; } -- cgit v1.2.3 From 79ae86031262b2c20267c9081ef78840e8375fe5 Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 26 May 2025 20:31:11 +0800 Subject: fix test cases --- src/RegistrationNumber.php | 7 +++++++ tests/RegistrationNumberTest.php | 6 ++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/RegistrationNumber.php b/src/RegistrationNumber.php index 678633d..eca7166 100644 --- a/src/RegistrationNumber.php +++ b/src/RegistrationNumber.php @@ -383,11 +383,18 @@ final readonly class RegistrationNumber private static function checkSuffix( string $region, string $authority, string $sequence, string $suffix ): bool { + // Ensure the HK or Macau suffix is only available to Guangdong-Z if (in_array($suffix, self::GUANGDONG_Z_SPECIAL_SUFFIXS, strict: true)) { return $region === self::GUANGDONG_PROVINCE && $authority === self::GUANGDONG_SPECIAL_AUTHORITY; } + // Ensure the Guangdong-Z license plate ends with either an "HK" or a "Macau" suffix + if ($region === self::GUANGDONG_PROVINCE + && $authority === self::GUANGDONG_SPECIAL_AUTHORITY) { + return in_array($suffix, self::GUANGDONG_Z_SPECIAL_SUFFIXS, strict: true); + } + if ($suffix !== '' && ! in_array($suffix, self::AVAILLABLE_SUFFIXS, strict: true)) { $len = mb_strlen($sequence); diff --git a/tests/RegistrationNumberTest.php b/tests/RegistrationNumberTest.php index 6516eb3..96af23b 100644 --- a/tests/RegistrationNumberTest.php +++ b/tests/RegistrationNumberTest.php @@ -290,7 +290,8 @@ final class RegistrationNumberTest extends TestCase ['粤O12345'], // Authority code "Z" (the 2nd character) is for internal in Guangdong province - ['粤Z12345'], + ['粤Z1234港'], + ['粤Z12345港'], // Authority code "W" (the 2nd character) is for internal in Shandong province ['鲁W12345'], @@ -309,9 +310,6 @@ final class RegistrationNumberTest extends TestCase // Authority code "O" (the 2nd character) is for internal ['粤OD12345'], - // Authority code "Z" (the 2nd character) is for internal in Guangdong province - ['粤ZD12345'], - // Authority code "W" (the 2nd character) is for internal in Shandong province ['鲁WD12345'], ]; -- cgit v1.2.3 From ce8d02afeebbaeae1216ba86c89bec373c17d68b Mon Sep 17 00:00:00 2001 From: Li Zhineng Date: Mon, 26 May 2025 21:02:54 +0800 Subject: seq must be 4-5 char long if license plate has a suffix --- src/RegistrationNumber.php | 17 ++++++++++------- tests/RegistrationNumberTest.php | 7 +++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/RegistrationNumber.php b/src/RegistrationNumber.php index eca7166..1b5e936 100644 --- a/src/RegistrationNumber.php +++ b/src/RegistrationNumber.php @@ -385,17 +385,20 @@ final readonly class RegistrationNumber ): bool { // Ensure the HK or Macau suffix is only available to Guangdong-Z if (in_array($suffix, self::GUANGDONG_Z_SPECIAL_SUFFIXS, strict: true)) { - return $region === self::GUANGDONG_PROVINCE - && $authority === self::GUANGDONG_SPECIAL_AUTHORITY; - } - + if (! ($region === self::GUANGDONG_PROVINCE + && $authority === self::GUANGDONG_SPECIAL_AUTHORITY)) { + return false; + } // Ensure the Guangdong-Z license plate ends with either an "HK" or a "Macau" suffix - if ($region === self::GUANGDONG_PROVINCE + } else if ($region === self::GUANGDONG_PROVINCE && $authority === self::GUANGDONG_SPECIAL_AUTHORITY) { - return in_array($suffix, self::GUANGDONG_Z_SPECIAL_SUFFIXS, strict: true); + if (! in_array($suffix, self::GUANGDONG_Z_SPECIAL_SUFFIXS, strict: true)) { + return false; + } } - if ($suffix !== '' && ! in_array($suffix, self::AVAILLABLE_SUFFIXS, strict: true)) { + // If the license plate has a suffix, the sequence must be 4 or 5 characters long + if ($suffix !== '' && in_array($suffix, self::AVAILLABLE_SUFFIXS, strict: true)) { $len = mb_strlen($sequence); return $len >= 4 && $len <= 5; diff --git a/tests/RegistrationNumberTest.php b/tests/RegistrationNumberTest.php index 96af23b..eadac54 100644 --- a/tests/RegistrationNumberTest.php +++ b/tests/RegistrationNumberTest.php @@ -443,6 +443,13 @@ final class RegistrationNumberTest extends TestCase ['粤Z00000试'], ['粤Z0000超'], ['粤Z00000超'], + ['粤ED12345警'], + ['粤ED12345学'], + ['粤ED12345挂'], + ['粤ZD12345港'], + ['粤ZD12345澳'], + ['粤ED12345试'], + ['粤ED12345超'], ]; } -- cgit v1.2.3