Skip to content

Commit 9b1a1bd

Browse files
authored
Merge pull request #6 from jeddtony/master
Add validation for Nigerian states
2 parents 46ac937 + 2effc85 commit 9b1a1bd

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

src/Base.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ function __construct(string $country = null)
1616
$v = Validator::make([
1717
"country" => $country,
1818
], [
19-
"country" => "nullable|string|in:US,CA,MX,BR",
19+
20+
"country" => "nullable|string|in:US,CA,MX,BR,NG",
2021
]);
2122

2223
if ($v->fails()) {
@@ -177,6 +178,45 @@ protected function isAbbr($value, string $country = null): bool
177178
["abbr" => 'SE', "name" => 'Sergipe'],
178179
["abbr" => 'TO', "name" => 'Tocantins'],
179180
],
181+
"NG" => [
182+
["abbr" => "AB", "name" => "Abia"],
183+
["abbr" => "AD", "name" => "Adamawa"],
184+
["abbr" => "AK", "name" => "Akwa Ibom"],
185+
["abbr" => "AN", "name" => "Anambra"],
186+
["abbr" => "BA", "name" => "Bauchi"],
187+
["abbr" => "BY", "name" => "Bayelsa"],
188+
["abbr" => "BE", "name" => "Benue"],
189+
["abbr" => "BO", "name" => "Borno"],
190+
["abbr" => "CR", "name" => "Cross River"],
191+
["abbr" => "DE", "name" => "Delta"],
192+
["abbr" => "EB", "name" => "Ebonyi"],
193+
["abbr" => "ED", "name" => "Edo"],
194+
["abbr" => "EK", "name" => "Ekiti"],
195+
["abbr" => "EN", "name" => "Enugu"],
196+
["abbr" => "FC", "name" => "Federal Capital Territory"],
197+
["abbr" => "GO", "name" => "Gombe"],
198+
["abbr" => "IM", "name" => "Imo"],
199+
["abbr" => "JI", "name" => "Jigawa"],
200+
["abbr" => "KD", "name" => "Kaduna"],
201+
["abbr" => "KN", "name" => "Kano"],
202+
["abbr" => "KT", "name" => "Katsina"],
203+
["abbr" => "KE", "name" => "Kebbi"],
204+
["abbr" => "KO", "name" => "Kogi"],
205+
["abbr" => "LA", "name" => "Lagos"],
206+
["abbr" => "NA", "name" => "Nasarawa"],
207+
["abbr" => "NI", "name" => "Niger"],
208+
["abbr" => "OG", "name" => "Ogun"],
209+
["abbr" => "ON", "name" => "Ondo"],
210+
["abbr" => "OS", "name" => "Osun"],
211+
["abbr" => "OY", "name" => "Oyo"],
212+
["abbr" => "PL", "name" => "Plateau"],
213+
["abbr" => "RI", "name" => "Rivers"],
214+
["abbr" => "SO", "name" => "Sokoto"],
215+
["abbr" => "TA", "name" => "Taraba"],
216+
["abbr" => "YO", "name" => "Yobe"],
217+
["abbr" => "ZA", "name" => "Zamfara"],
218+
219+
]
180220
];
181221

182222
protected function getSubject(string $country = null): string
@@ -185,7 +225,8 @@ protected function getSubject(string $country = null): string
185225
{
186226
case "US":
187227
case "MX":
188-
case "BR":
228+
case "BR":
229+
case "NG":
189230
return "State";
190231
case "CA":
191232
return "Province";

tests/ValidatorTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ class ValidatorTest extends TestCase
2020
'mexico' => ['AGU', 'BCN', 'BCS', 'CAM', 'CHP', 'CHH', 'CMX', 'COA', 'COL', 'DUR', 'GUA',
2121
'GRO', 'HID', 'JAL', 'MIC', 'MOR', 'MEX', 'NAY', 'NLE', 'OAX', 'PUE', 'QUE', 'ROO',
2222
'SLP', 'SIN', 'SON', 'TAB', 'TAM', 'TLA', 'VER', 'YUC', 'ZAC'],
23-
];
23+
'nigeria' => ['AB', 'AD', 'AK', 'AN', 'BA', 'BY', 'BE', 'BO', 'CR', 'DE', 'EB', 'ED', 'EK',
24+
'EN', 'FC', 'GO', 'IM', 'JI', 'KD', 'KN', 'KT', 'KE', 'KO', 'LA', 'NA', 'NI', 'OG', 'ON',
25+
'OS', 'OY', 'PL', 'RI', 'SO', 'TA', 'YO', 'ZA'],
26+
];
2427

2528
protected $names = [
2629
'usa' => ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 'Colorado', 'Connecticut', 'District Of Columbia', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming', 'American Samoa', 'Federated States Of Micronesia', 'Guam', 'Marshall Islands', 'Northern Mariana Islands', 'Pala', 'Puerto Rico', 'Virgin Islands'],
2730
'canada' => [ 'Alberta', 'British Columbia', 'Manitoba', 'New Brunswick', 'Newfoundland And Labrador', 'Nova Scotia', 'Northwest Territories', 'Nunavut', 'Ontario', 'Prince Edward Island', 'Quebec', 'Saskatchewan', 'Yukon'],
2831
'mexico' => [ 'Aguascalientes', 'Baja California', 'Baja California Sur', 'Campeche', 'Chiapas', 'Chihuahua', 'Coahuila', 'Colima', 'Mexico City', 'Durango', 'Guanajuato', 'Guerrero', 'Hidalgo', 'Jalisco', 'México', 'Michoacán', 'Morelos', 'Nayarit', 'Nuevo León', 'Oaxaca', 'Puebla', 'Querétaro', 'Quintana Roo', 'San Luis Potosí', 'Sinaloa', 'Sonora', 'Tabasco', 'Tamaulipas', 'Tlaxcala', 'Veracruz', 'Yucatán', 'Zacatecas'],
32+
'nigeria' => ['Abia', 'Adamawa', 'Akwa Ibom', 'Anambra', 'Bauchi', 'Bayelsa', 'Benue', 'Borno', 'Cross River', 'Delta', 'Ebonyi', 'Edo', 'Ekiti', 'Enugu', 'Federal Capital Territory', 'Gombe', 'Imo', 'Jigawa', 'Kaduna', 'Kano', 'Katsina', 'Kebbi', 'Kogi', 'Lagos', 'Nasarawa', 'Niger', 'Ogun', 'Ondo', 'Osun', 'Oyo', 'Plateau', 'Rivers', 'Sokoto', 'Taraba', 'Yobe', 'Zamfara']
2933
];
3034

3135
protected function validate($value, Rule $rule)
@@ -86,6 +90,18 @@ public function testValidatorMexico()
8690
$this->assertEquals(false, $this->validate('utah', new Full("MX")));
8791
}
8892

93+
public function testValidatorNigeria()
94+
{
95+
$this->assertEquals(true, $this->validateAbbrs('nigeria', new Abbr("NG")));
96+
$this->assertEquals(true, $this->validate('la', new Abbr("NG")));
97+
$this->assertEquals(true, $this->validate('Lagos', new Full("NG")));
98+
$this->assertEquals(true, $this->validate('lagos', new Full("NG")));
99+
100+
$this->assertEquals(false, $this->validateAbbrs('usa', new Abbr("NG")));
101+
$this->assertEquals(false, $this->validate('ut', new Abbr("NG")));
102+
$this->assertEquals(false, $this->validate('Utah', new Full("NG")));
103+
$this->assertEquals(false, $this->validate('utah', new Full("NG")));
104+
}
89105
protected function validateAbbrs($country, $rule)
90106
{
91107
$x = true;

0 commit comments

Comments
 (0)