@@ -12,8 +12,7 @@ discard block |
||
12 | 12 | * |
13 | 13 | * @author Joe Huss <[email protected]> |
14 | 14 | */ |
15 | -class Validator |
|
16 | -{ |
|
15 | +class Validator { |
|
17 | 16 | protected $zip_names = array( |
18 | 17 | 'BR' => array('name' => 'CEP', 'acronym_text' => 'Código de endereçamento postal (Postal Addressing Code)'), |
19 | 18 | 'CA' => array('name' => 'Postal Code', 'acronym_text' => ''), |
@@ -285,54 +284,44 @@ discard block |
||
285 | 284 | 'ZW' => array(), // Zimbabwe, Notes: System is being planned. |
286 | 285 | ); |
287 | 286 | |
288 | - public function isValid($countryCode, $postalCode, $ignoreSpaces = false) |
|
289 | - { |
|
287 | + public function isValid($countryCode, $postalCode, $ignoreSpaces = false) { |
|
290 | 288 | //$postalCode = str_replace('-', '', $postalCode); |
291 | - if (!isset($this->formats[$countryCode])) |
|
292 | - { |
|
289 | + if (!isset($this->formats[$countryCode])) { |
|
293 | 290 | throw new ValidationException(sprintf('Invalid country code: "%s"', $countryCode)); |
294 | 291 | } |
295 | 292 | |
296 | - foreach ($this->formats[$countryCode] as $format) |
|
297 | - { |
|
293 | + foreach ($this->formats[$countryCode] as $format) { |
|
298 | 294 | #echo $postalCode . ' - ' . $this->getFormatPattern($format)."\n"; |
299 | - if (preg_match($this->getFormatPattern($format, $ignoreSpaces), $postalCode)) |
|
300 | - { |
|
295 | + if (preg_match($this->getFormatPattern($format, $ignoreSpaces), $postalCode)) { |
|
301 | 296 | return true; |
302 | 297 | } |
303 | 298 | } |
304 | 299 | |
305 | - if (!count($this->formats[$countryCode])) |
|
306 | - { |
|
300 | + if (!count($this->formats[$countryCode])) { |
|
307 | 301 | return true; |
308 | 302 | } |
309 | 303 | |
310 | 304 | return false; |
311 | 305 | } |
312 | 306 | |
313 | - public function getFormats($countryCode) |
|
314 | - { |
|
315 | - if (!isset($this->formats[$countryCode])) |
|
316 | - { |
|
307 | + public function getFormats($countryCode) { |
|
308 | + if (!isset($this->formats[$countryCode])) { |
|
317 | 309 | throw new ValidationException(sprintf('Invalid country code: "%s"', $countryCode)); |
318 | 310 | } |
319 | 311 | |
320 | 312 | return $this->formats[$countryCode]; |
321 | 313 | } |
322 | 314 | |
323 | - public function hasCountry($countryCode) |
|
324 | - { |
|
315 | + public function hasCountry($countryCode) { |
|
325 | 316 | return (isset($this->formats[$countryCode])); |
326 | 317 | } |
327 | 318 | |
328 | - protected function getFormatPattern($format, $ignoreSpaces = false) |
|
329 | - { |
|
319 | + protected function getFormatPattern($format, $ignoreSpaces = false) { |
|
330 | 320 | //$format = str_replace('-', '', $format); |
331 | 321 | $pattern = str_replace('#', '\d', $format); |
332 | 322 | $pattern = str_replace('@', '[a-zA-Z]', $pattern); |
333 | 323 | |
334 | - if ($ignoreSpaces) |
|
335 | - { |
|
324 | + if ($ignoreSpaces) { |
|
336 | 325 | $pattern = str_replace(' ', ' ?', $pattern); |
337 | 326 | } |
338 | 327 |
@@ -336,7 +336,7 @@ |
||
336 | 336 | $pattern = str_replace(' ', ' ?', $pattern); |
337 | 337 | } |
338 | 338 | |
339 | - return '/^' . $pattern . '$/'; |
|
339 | + return '/^'.$pattern.'$/'; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | public function getZipName($countryCode) { |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | 'US' => ['name' => 'ZIP code', 'acronym_text' => 'Zone Improvement Plan'], |
22 | 22 | ]; |
23 | 23 | |
24 | -require(__DIR__ . '/../../../include/functions.inc.php'); |
|
24 | +require(__DIR__.'/../../../include/functions.inc.php'); |
|
25 | 25 | function_requirements('getcurlpage'); |
26 | 26 | $page = getcurlpage('https://en.wikipedia.org/wiki/Special:Export/List_of_postal_codes'); |
27 | 27 | $page = str_replace("\n\n", "\n", $page); |
@@ -45,13 +45,13 @@ discard block |
||
45 | 45 | $area = explode(',', $area); |
46 | 46 | foreach ($area as $each_area) |
47 | 47 | if (trim($each_area) != '' && trim($each_area) != '- no codes -') |
48 | - $codes[] = "'" . trim($each_area) . "'"; |
|
48 | + $codes[] = "'".trim($each_area)."'"; |
|
49 | 49 | $street = explode(',', $street); |
50 | 50 | foreach ($street as $each_street) |
51 | 51 | if (trim($each_street) != '') |
52 | - $codes[] = "'" . trim($each_street) . "'"; |
|
52 | + $codes[] = "'".trim($each_street)."'"; |
|
53 | 53 | $found[] = $iso; |
54 | - echo " '$iso' => [" . str_replace(['N', 'A'], ['#', '@'], implode(", ", $codes)) . "]," . (sizeof($codes) == 0 ? ' ' : '') . " // $country" . (trim($notes) != '' ? ', Notes: ' . $notes : '') . "\n"; |
|
54 | + echo " '$iso' => [".str_replace(['N', 'A'], ['#', '@'], implode(", ", $codes))."],".(sizeof($codes) == 0 ? ' ' : '')." // $country".(trim($notes) != '' ? ', Notes: '.$notes : '')."\n"; |
|
55 | 55 | } |
56 | 56 | } |
57 | 57 | $db = $GLOBALS['tf']->db; |
@@ -75,12 +75,12 @@ discard block |
||
75 | 75 | $area = explode(',', $area); |
76 | 76 | foreach ($area as $each_area) |
77 | 77 | if (trim($each_area) != '' && trim($each_area) != '- no codes -') |
78 | - $codes[] = "'" . trim($each_area) . "'"; |
|
78 | + $codes[] = "'".trim($each_area)."'"; |
|
79 | 79 | $street = explode(',', $street); |
80 | 80 | foreach ($street as $each_street) |
81 | 81 | if (trim($each_street) != '') |
82 | - $codes[] = "'" . trim($each_street) . "'"; |
|
83 | - echo " '$iso' => [" . implode(", ", $codes) . "] // $country" . (trim($notes) != '' ? ', Notes: ' . $notes : '') . "\n"; |
|
82 | + $codes[] = "'".trim($each_street)."'"; |
|
83 | + echo " '$iso' => [".implode(", ", $codes)."] // $country".(trim($notes) != '' ? ', Notes: '.$notes : '')."\n"; |
|
84 | 84 | } |
85 | 85 | //$page = getcurlpage('https://en.wikipedia.org/wiki/List_of_postal_codes'); |
86 | 86 | //function_requirements('xml2array'); |