summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/RegistrationNumber.php38
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);
+ }
}