diff options
| author | Li Zhineng <[email protected]> | 2025-05-26 21:02:54 +0800 |
|---|---|---|
| committer | Li Zhineng <[email protected]> | 2025-05-26 21:02:54 +0800 |
| commit | ce8d02afeebbaeae1216ba86c89bec373c17d68b (patch) | |
| tree | 7d3464906ea8239be99e4f691614ad5a2d92b02d | |
| parent | 79ae86031262b2c20267c9081ef78840e8375fe5 (diff) | |
| download | vehicle-license-china-ce8d02afeebbaeae1216ba86c89bec373c17d68b.tar.gz vehicle-license-china-ce8d02afeebbaeae1216ba86c89bec373c17d68b.zip | |
seq must be 4-5 char long if license plate has a suffix
| -rw-r--r-- | src/RegistrationNumber.php | 17 | ||||
| -rw-r--r-- | 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超'], ]; } |
