diff options
| author | Li Zhineng <[email protected]> | 2025-05-12 19:27:10 +0800 |
|---|---|---|
| committer | Li Zhineng <[email protected]> | 2025-05-12 19:27:10 +0800 |
| commit | db83565c54a2b97ad9cf3e83314775193876be43 (patch) | |
| tree | deb5793a20bb14a463c91efc1e4928fcb22f2928 /src/RegistrationNumber.php | |
| parent | 12ebfe678ed2554fb5902c60d99a53414bec0ad1 (diff) | |
| download | vehicle-license-china-db83565c54a2b97ad9cf3e83314775193876be43.tar.gz vehicle-license-china-db83565c54a2b97ad9cf3e83314775193876be43.zip | |
determine if clean energy
Diffstat (limited to 'src/RegistrationNumber.php')
| -rw-r--r-- | src/RegistrationNumber.php | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/RegistrationNumber.php b/src/RegistrationNumber.php index 6e729e3..3f6edcc 100644 --- a/src/RegistrationNumber.php +++ b/src/RegistrationNumber.php @@ -134,10 +134,23 @@ final readonly class RegistrationNumber 'F', 'G', 'H', 'J', 'K', ]; + /** + * @var string[] + */ + private const array BATTERY_ELECTRIC_LETTERS = [ + 'D', 'A', 'B', 'C', 'E', + ]; + + public string $region; + + public string $authority; + + public string $sequence; + private function __construct( public string $registrationNumber ) { - // + $this->parse($registrationNumber); } public static function make(string $registrationNumber): static @@ -250,4 +263,27 @@ final readonly class RegistrationNumber 'The registration number "%s" is invalid.', $registrationNumber )); } + + private function parse(string $registrationNumber): void + { + $this->region = mb_substr($registrationNumber, 0, 1); + $this->authority = mb_substr($registrationNumber, 1, 1); + $this->sequence = mb_substr($registrationNumber, 2); + } + + public function isCleanEnergy(): bool + { + return strlen($this->sequence) === 6; + } + + public function isBatteryElectric(): bool + { + if (! $this->isCleanEnergy()) { + return false; + } + + $code = mb_substr($this->sequence, 0, 1); + + return in_array($code, self::BATTERY_ELECTRIC_LETTERS); + } } |
