diff options
| author | Li Zhineng <[email protected]> | 2025-05-26 21:51:52 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-05-26 21:51:52 +0800 |
| commit | 186e50439b0f72205e04858aeff9b3cde1cf281b (patch) | |
| tree | 7d3464906ea8239be99e4f691614ad5a2d92b02d /src/RegistrationNumber.php | |
| parent | 548c049fa58edb27a0229a9bd1f44b6dd0e65a42 (diff) | |
| parent | ce8d02afeebbaeae1216ba86c89bec373c17d68b (diff) | |
| download | vehicle-license-china-186e50439b0f72205e04858aeff9b3cde1cf281b.tar.gz vehicle-license-china-186e50439b0f72205e04858aeff9b3cde1cf281b.zip | |
Merge pull request #1 from lizhineng/fix-yue-z
Guangdong-Z only supports the Macau and Hong Kong suffixes
Diffstat (limited to 'src/RegistrationNumber.php')
| -rw-r--r-- | src/RegistrationNumber.php | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/RegistrationNumber.php b/src/RegistrationNumber.php index 678633d..1b5e936 100644 --- a/src/RegistrationNumber.php +++ b/src/RegistrationNumber.php @@ -383,12 +383,22 @@ 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; + 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 + } else if ($region === self::GUANGDONG_PROVINCE + && $authority === self::GUANGDONG_SPECIAL_AUTHORITY) { + 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; |
