Skip to content

Commit

Permalink
Support for US License Plate
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mattwells committed Apr 26, 2019
1 parent 2ec870a commit a365edd
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
```
58 changes: 58 additions & 0 deletions src/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -192,4 +245,9 @@ public static function vehicleRegistration()

return "{$local}{$age} {$sequence}";
}

public static function vehicleLicensePlate()
{
return strtoupper(static::bothify(static::randomElement(static::$licensePlateFormats)));
}
}

0 comments on commit a365edd

Please sign in to comment.