From a365eddd4e7a33e07f0bf4c925287f98bd7969fb Mon Sep 17 00:00:00 2001 From: Matt Wells Date: Fri, 26 Apr 2019 11:41:51 +0100 Subject: [PATCH] Support for US License Plate Pulled the latest Serial Formats from Wikipedia for each Jurisdiction to create a rough License Plate number. I'm sure there are some extra nuances that means invalid characters are used but the formats should look right. https://en.wikipedia.org/wiki/United_States_license_plate_designs_and_serial_formats --- README.md | 7 +++++- src/Provider.php | 58 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bab6c6e..a9a0b5a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Faker Vehicle Provider -A provider for [Faker](https://github.com/fzaninotto/Faker#faker-internals-understanding-providers) to generate random vehicle makes & models as well as [UK registration plate](https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_the_United_Kingdom,_Crown_dependencies_and_overseas_territories#Current_system). +A provider for [Faker](https://github.com/fzaninotto/Faker#faker-internals-understanding-providers) to generate random vehicle makes & models as well as [UK registration plate](https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_the_United_Kingdom,_Crown_dependencies_and_overseas_territories#Current_system) and [US license plate](https://en.wikipedia.org/wiki/United_States_license_plate_designs_and_serial_formats#Current_standard-issue_passenger_plate_designs_and_serial_formats). ## Install @@ -23,5 +23,10 @@ $faker->addProvider(new \MattWells\Faker\Vehicle\Provider($faker)); echo $faker->vehicleMake; // Nissan echo $faker->vehicleModel; // C Class echo $faker->vehicleModel('BMW'); // 3 Series + +// UK Registration Plate echo $faker->vehicleRegistration; // XA13 LYE + +// US License Plate +echo $faker->vehicleLicensePlate; // 8BE V34 ``` diff --git a/src/Provider.php b/src/Provider.php index f3c04da..4c21904 100644 --- a/src/Provider.php +++ b/src/Provider.php @@ -151,6 +151,59 @@ class Provider extends Base 'U', 'V', 'W', 'X', 'Y', 'Z', ]; + protected static $licensePlateFormats = [ + '### ####', + '### ??#', + '### ???', + '####', + '#### ??', + '######', + '####??', + '###-???', + '###?', + '###??', + '###???', + '###·?##', + '##-#####', + '##-####?', + '##-?###', + '##-??##', + '##? ###', + '##? ?##', + '##??###', + '#-#####', + '#-#####?', + '#-####?', + '#-?####', + '#-??###', + '#? #####', + '#? ?####', + '#?# ###', + '#?#-#?#', + '#?#??', + '#?? ###', + '#?? ?##', + '#??####', + '#??? ##', + '#???###', + '#??•??#', + '? ######', + '?##-???', + '?? ####', + '?? #####', + '??# ####', + '??# ?#?', + '??-####', + '??? ###', + '??? ####', + '??? ?##', + '???###', + '???####', + '???-###', + '???-####', + '??•#####', + ]; + public static function vehicleMake() { return static::randomElement(array_keys(static::$makesWithModels)); @@ -192,4 +245,9 @@ public static function vehicleRegistration() return "{$local}{$age} {$sequence}"; } + + public static function vehicleLicensePlate() + { + return strtoupper(static::bothify(static::randomElement(static::$licensePlateFormats))); + } }