@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | use PragmaRX\Countries\Package\Support\Collection; |
| 4 | 4 | |
| 5 | -if (! function_exists('array_sort_by_keys_recursive')) { |
|
| 5 | +if (!function_exists('array_sort_by_keys_recursive')) { |
|
| 6 | 6 | /** |
| 7 | 7 | * Recursively sort array by keys. |
| 8 | 8 | * |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | -if (! function_exists('countriesCollect')) { |
|
| 24 | +if (!function_exists('countriesCollect')) { |
|
| 25 | 25 | /** |
| 26 | 26 | * Check if array is multidimensional. |
| 27 | 27 | * |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | |
| 37 | -if (! function_exists('arrayable')) { |
|
| 37 | +if (!function_exists('arrayable')) { |
|
| 38 | 38 | /** |
| 39 | 39 | * Recursively change all array keys case. |
| 40 | 40 | * |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | 'latlng' => 'geo', |
| 62 | 62 | ]; |
| 63 | 63 | |
| 64 | - coollect($mergeable)->each(function ($to, $key) use (&$natural) { |
|
| 64 | + coollect($mergeable)->each(function($to, $key) use (&$natural) { |
|
| 65 | 65 | if (isset($natural[$key])) { |
| 66 | 66 | $natural->overwrite([$to => [$key => $natural[$key]]]); |
| 67 | 67 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function findRinvexState($country, $needle) |
| 115 | 115 | { |
| 116 | - $states = $this->findRinvex($country, 'divisions')->map(function ($state, $postal) { |
|
| 116 | + $states = $this->findRinvex($country, 'divisions')->map(function($state, $postal) { |
|
| 117 | 117 | $state['postal'] = $postal; |
| 118 | 118 | |
| 119 | 119 | $state['name'] = $this->helper->fixUtf8($state['name']); |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | return $states; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - $state = $states->filter(function ($rinvexState) use ($needle) { |
|
| 128 | + $state = $states->filter(function($rinvexState) use ($needle) { |
|
| 129 | 129 | return $rinvexState->postal == $needle->postal || |
| 130 | 130 | $rinvexState->name == $needle['name'] || |
| 131 | 131 | utf8_encode($rinvexState->name) == $needle['name'] || |
| 132 | 132 | $rinvexState->alt_names->contains($needle['name']) || |
| 133 | - $rinvexState->alt_names->contains(function ($name) use ($needle) { |
|
| 133 | + $rinvexState->alt_names->contains(function($name) use ($needle) { |
|
| 134 | 134 | return $needle->alt_names->contains($name); |
| 135 | 135 | }); |
| 136 | 136 | })->first(); |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | continue; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - if ($rinvexValue !== $naturalValue && ! $defaultToRinvex->contains($key)) { |
|
| 207 | + if ($rinvexValue !== $naturalValue && !$defaultToRinvex->contains($key)) { |
|
| 208 | 208 | $result[$key.$suffix] = $rinvexValue; // Natural Earth Vector |
| 209 | 209 | } |
| 210 | 210 | |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | : $naturalValue; // Natural Earth Vector |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - return coollect($result)->sortBy(function ($value, $key) { |
|
| 216 | + return coollect($result)->sortBy(function($value, $key) { |
|
| 217 | 217 | return $key; |
| 218 | 218 | }); |
| 219 | 219 | } |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public function mergeCountryStatesWithRinvex($states) |
| 228 | 228 | { |
| 229 | - return coollect($states)->map(function ($state) { |
|
| 229 | + return coollect($states)->map(function($state) { |
|
| 230 | 230 | return $this->mergeStateWithRinvex($state); |
| 231 | 231 | }); |
| 232 | 232 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | $this->helper->message('Processing cities...'); |
| 45 | 45 | |
| 46 | - $normalizerClosure = function ($item) { |
|
| 46 | + $normalizerClosure = function($item) { |
|
| 47 | 47 | $item = $this->updater->addDataSource($item, 'natural'); |
| 48 | 48 | |
| 49 | 49 | $item = $this->updater->addRecordType($item, 'city'); |
@@ -51,11 +51,11 @@ discard block |
||
| 51 | 51 | return $this->updater->normalizeStateOrCityData($item); |
| 52 | 52 | }; |
| 53 | 53 | |
| 54 | - $codeGeneratorClosure = function ($item) { |
|
| 54 | + $codeGeneratorClosure = function($item) { |
|
| 55 | 55 | return $this->helper->caseForKey($item['nameascii']); |
| 56 | 56 | }; |
| 57 | 57 | |
| 58 | - $mergerClosure = function ($item) { |
|
| 58 | + $mergerClosure = function($item) { |
|
| 59 | 59 | return $item; |
| 60 | 60 | }; |
| 61 | 61 | |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | throw new Exception("No currencies found in {$directory}"); |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - $currencies = $currencies->mapWithKeys(function ($currency) { |
|
| 50 | + $currencies = $currencies->mapWithKeys(function($currency) { |
|
| 51 | 51 | return $currency; |
| 52 | 52 | }); |
| 53 | 53 | |
| 54 | 54 | $this->helper->message('Processing currencies...'); |
| 55 | 55 | |
| 56 | - $normalizerClosure = function ($item) { |
|
| 56 | + $normalizerClosure = function($item) { |
|
| 57 | 57 | $item = $this->updater->addDataSource($item, 'world-currencies'); |
| 58 | 58 | |
| 59 | 59 | $item = $this->updater->addRecordType($item, 'currency'); |
@@ -61,10 +61,10 @@ discard block |
||
| 61 | 61 | return [$item]; |
| 62 | 62 | }; |
| 63 | 63 | |
| 64 | - $getCodeClosure = function () { |
|
| 64 | + $getCodeClosure = function() { |
|
| 65 | 65 | }; |
| 66 | 66 | |
| 67 | - $generateTaxData = function ($tax) { |
|
| 67 | + $generateTaxData = function($tax) { |
|
| 68 | 68 | return $tax; |
| 69 | 69 | }; |
| 70 | 70 | |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | $taxes = $this->helper->loadJsonFiles($this->helper->dataDir('third-party/commerceguys/taxes/types')); |
| 40 | 40 | |
| 41 | - $taxes = $taxes->mapWithKeys(function ($vat, $key) { |
|
| 41 | + $taxes = $taxes->mapWithKeys(function($vat, $key) { |
|
| 42 | 42 | $parts = coollect(explode('_', $key)); |
| 43 | 43 | $cca2 = $parts->first(); |
| 44 | 44 | $type = $parts->last(); |
@@ -69,15 +69,15 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | $this->helper->message('Processing taxes...'); |
| 71 | 71 | |
| 72 | - $normalizerClosure = function ($item) { |
|
| 72 | + $normalizerClosure = function($item) { |
|
| 73 | 73 | return $item; |
| 74 | 74 | }; |
| 75 | 75 | |
| 76 | - $getCodeClosure = function ($item) { |
|
| 76 | + $getCodeClosure = function($item) { |
|
| 77 | 77 | return $item['tax_type']; |
| 78 | 78 | }; |
| 79 | 79 | |
| 80 | - $generateTaxData = function ($tax) { |
|
| 80 | + $generateTaxData = function($tax) { |
|
| 81 | 81 | return $this->normalizeTax($tax); |
| 82 | 82 | }; |
| 83 | 83 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $countries = $this->cache->remember( |
| 51 | 51 | 'updateTimezone.countries', |
| 52 | 52 | 160, |
| 53 | - function () { |
|
| 53 | + function() { |
|
| 54 | 54 | return $this->helper->loadCsv($this->helper->dataDir('third-party/timezonedb/country.csv')); |
| 55 | 55 | } |
| 56 | 56 | ); |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | $zones = $this->cache->remember( |
| 61 | 61 | 'updateTimezone.zones', |
| 62 | 62 | 160, |
| 63 | - function () { |
|
| 64 | - return $this->helper->loadCsv($this->helper->dataDir('third-party/timezonedb/zone.csv'))->mapWithKeys(function ($value) { |
|
| 63 | + function() { |
|
| 64 | + return $this->helper->loadCsv($this->helper->dataDir('third-party/timezonedb/zone.csv'))->mapWithKeys(function($value) { |
|
| 65 | 65 | return [ |
| 66 | 66 | $value[0] => [ |
| 67 | 67 | 'zone_id' => $value[0], |
@@ -78,8 +78,8 @@ discard block |
||
| 78 | 78 | $timezones = $this->cache->remember( |
| 79 | 79 | 'updateTimezone.timezones', |
| 80 | 80 | 160, |
| 81 | - function () { |
|
| 82 | - return $this->helper->loadCsv($this->helper->dataDir('third-party/timezonedb/timezone.csv'))->map(function ($timezone) { |
|
| 81 | + function() { |
|
| 82 | + return $this->helper->loadCsv($this->helper->dataDir('third-party/timezonedb/timezone.csv'))->map(function($timezone) { |
|
| 83 | 83 | return [ |
| 84 | 84 | 'zone_id' => $timezone[0], |
| 85 | 85 | 'abbreviation' => $timezone[1], |
@@ -96,9 +96,9 @@ discard block |
||
| 96 | 96 | $abbreviations = $this->cache->remember( |
| 97 | 97 | 'updateTimezone.abbreviations', |
| 98 | 98 | 160, |
| 99 | - function () use ($timezones) { |
|
| 100 | - return $timezones->groupBy('zone_id')->map(function (Coollection $timezones) { |
|
| 101 | - return $timezones->map(function ($timezone) { |
|
| 99 | + function() use ($timezones) { |
|
| 100 | + return $timezones->groupBy('zone_id')->map(function(Coollection $timezones) { |
|
| 101 | + return $timezones->map(function($timezone) { |
|
| 102 | 102 | return $timezone['abbreviation']; |
| 103 | 103 | })->unique()->sort()->values(); |
| 104 | 104 | }); |
@@ -107,13 +107,13 @@ discard block |
||
| 107 | 107 | |
| 108 | 108 | $this->helper->progress('Updating countries timezones...'); |
| 109 | 109 | |
| 110 | - $countries = $countries->mapWithKeys(function ($item) { |
|
| 110 | + $countries = $countries->mapWithKeys(function($item) { |
|
| 111 | 111 | return [$item[0] => [ |
| 112 | 112 | 'cca2' => $item[0], |
| 113 | 113 | 'name' => $item[1], |
| 114 | 114 | ]]; |
| 115 | 115 | }) |
| 116 | - ->mapWithKeys(function ($item, $cca2) { |
|
| 116 | + ->mapWithKeys(function($item, $cca2) { |
|
| 117 | 117 | $fields = [ |
| 118 | 118 | ['cca2', 'cca2'], |
| 119 | 119 | ['name.common', 'name'], |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | 'name' => $item['name'], |
| 134 | 134 | ], |
| 135 | 135 | ]; |
| 136 | - })->map(function ($country) use ($zones, $abbreviations) { |
|
| 137 | - $country['timezones'] = $zones->where('country_code', $country['cca2'])->mapWithKeys(function ($zone) use ($abbreviations, $country) { |
|
| 136 | + })->map(function($country) use ($zones, $abbreviations) { |
|
| 137 | + $country['timezones'] = $zones->where('country_code', $country['cca2'])->mapWithKeys(function($zone) use ($abbreviations, $country) { |
|
| 138 | 138 | $zone['abbreviations'] = $abbreviations[$zone['zone_id']]; |
| 139 | 139 | |
| 140 | 140 | $zone['cca3'] = isset($country['cca3']) ? $country['cca3'] : null; |
@@ -153,14 +153,14 @@ discard block |
||
| 153 | 153 | |
| 154 | 154 | $this->helper->message('Generating timezone files...'); |
| 155 | 155 | |
| 156 | - $getCountryCodeClosure = function () { |
|
| 156 | + $getCountryCodeClosure = function() { |
|
| 157 | 157 | }; |
| 158 | 158 | |
| 159 | - $normalizeCountryClosure = function ($country) { |
|
| 159 | + $normalizeCountryClosure = function($country) { |
|
| 160 | 160 | return [$country['timezones']]; |
| 161 | 161 | }; |
| 162 | 162 | |
| 163 | - $dummyClosure = function ($country) { |
|
| 163 | + $dummyClosure = function($country) { |
|
| 164 | 164 | return $country; |
| 165 | 165 | }; |
| 166 | 166 | |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | $record = $record->toArray(); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - if (! isset($record[$field = 'data_sources'])) { |
|
| 212 | + if (!isset($record[$field = 'data_sources'])) { |
|
| 213 | 213 | $record['data_sources'] = []; |
| 214 | 214 | } |
| 215 | 215 | |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | foreach ($fields as $field) { |
| 268 | 268 | $found = $on->where($field[0], $by[$field[1]])->first(); |
| 269 | 269 | |
| 270 | - if (isset($by[$field[1]]) && ! is_null($found) && $found->count() > 0) { |
|
| 270 | + if (isset($by[$field[1]]) && !is_null($found) && $found->count() > 0) { |
|
| 271 | 271 | return [coollect($found), $found->{$codeField}]; |
| 272 | 272 | } |
| 273 | 273 | } |
@@ -285,19 +285,19 @@ discard block |
||
| 285 | 285 | */ |
| 286 | 286 | public function generateAllJsonFiles($dir, $makeGroupKeyClosure, $records, $groupKey) |
| 287 | 287 | { |
| 288 | - if (! empty($groupKey)) { |
|
| 288 | + if (!empty($groupKey)) { |
|
| 289 | 289 | $records = $records->groupBy($groupKey); |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - $records->each(function (Coollection $record, $key) use ($dir, $makeGroupKeyClosure) { |
|
| 292 | + $records->each(function(Coollection $record, $key) use ($dir, $makeGroupKeyClosure) { |
|
| 293 | 293 | $this->helper->mkdir(dirname($file = $this->helper->makeJsonFileName($key, $dir))); |
| 294 | 294 | |
| 295 | - $record = $record->mapWithKeys(function ($record, $key) use ($makeGroupKeyClosure) { |
|
| 295 | + $record = $record->mapWithKeys(function($record, $key) use ($makeGroupKeyClosure) { |
|
| 296 | 296 | $key = is_null($makeGroupKeyClosure) |
| 297 | 297 | ? $key |
| 298 | 298 | : $makeGroupKeyClosure($record, $key); |
| 299 | 299 | |
| 300 | - $record = coollect($record)->sortBy(function ($value, $key) { |
|
| 300 | + $record = coollect($record)->sortBy(function($value, $key) { |
|
| 301 | 301 | return $key; |
| 302 | 302 | }); |
| 303 | 303 | |
@@ -351,13 +351,13 @@ discard block |
||
| 351 | 351 | return $this->cache->remember( |
| 352 | 352 | 'normalizeData'.$dir, |
| 353 | 353 | 160, |
| 354 | - function () use ($dir, $result, $normalizerClosure, &$counter) { |
|
| 355 | - return coollect($result)->map(function ($item, $key) use ($normalizerClosure, &$counter) { |
|
| 354 | + function() use ($dir, $result, $normalizerClosure, &$counter) { |
|
| 355 | + return coollect($result)->map(function($item, $key) use ($normalizerClosure, &$counter) { |
|
| 356 | 356 | if ($counter++ % 1000 === 0) { |
| 357 | 357 | $this->helper->message("Normalized: {$counter}"); |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - return $normalizerClosure(coollect($item)->mapWithKeys(function ($value, $key) { |
|
| 360 | + return $normalizerClosure(coollect($item)->mapWithKeys(function($value, $key) { |
|
| 361 | 361 | return [strtolower($key) => $value]; |
| 362 | 362 | }), $key); |
| 363 | 363 | }); |
@@ -386,7 +386,7 @@ discard block |
||
| 386 | 386 | $countryCode = $this->helper->caseForKey($item['name']); |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - $item['iso_a3'] = ! isset($item['iso_a3']) |
|
| 389 | + $item['iso_a3'] = !isset($item['iso_a3']) |
|
| 390 | 390 | ? $countryCode |
| 391 | 391 | : $item['iso_a3']; |
| 392 | 392 | |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | $this->helper->message('Processing states...'); |
| 50 | 50 | |
| 51 | - $normalizerClosure = function ($item) { |
|
| 51 | + $normalizerClosure = function($item) { |
|
| 52 | 52 | $item = $this->updater->addDataSource($item, 'natural'); |
| 53 | 53 | |
| 54 | 54 | $item = $this->updater->addRecordType($item, 'state'); |
@@ -56,13 +56,13 @@ discard block |
||
| 56 | 56 | return $this->updater->normalizeStateOrCityData($item); |
| 57 | 57 | }; |
| 58 | 58 | |
| 59 | - $getCodeClosure = function ($item) { |
|
| 59 | + $getCodeClosure = function($item) { |
|
| 60 | 60 | return $this->makeStatePostalCode($item); |
| 61 | 61 | }; |
| 62 | 62 | |
| 63 | 63 | $counter = 0; |
| 64 | 64 | |
| 65 | - $mergerClosure = function ($states) use (&$counter) { |
|
| 65 | + $mergerClosure = function($states) use (&$counter) { |
|
| 66 | 66 | if ($counter++ % 100 === 0) { |
| 67 | 67 | $this->helper->message("Processed: $counter"); |
| 68 | 68 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - if (! empty(trim($item->postal))) { |
|
| 96 | + if (!empty(trim($item->postal))) { |
|
| 97 | 97 | $item->postal; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | private function arrayFinder(string $propertyName, $find, Closure $finderClosure) |
| 110 | 110 | { |
| 111 | - return $this->filter(function ($data) use ($find, $propertyName, $finderClosure) { |
|
| 111 | + return $this->filter(function($data) use ($find, $propertyName, $finderClosure) { |
|
| 112 | 112 | try { |
| 113 | 113 | $attributeValue = $data->{$propertyName}; |
| 114 | 114 | } catch (\Exception $e) { |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | */ |
| 131 | 131 | private function _whereKey(string $arrayName, $value) |
| 132 | 132 | { |
| 133 | - $finderClosure = function ($value, $attributeValue) { |
|
| 133 | + $finderClosure = function($value, $attributeValue) { |
|
| 134 | 134 | return Arr::has($attributeValue, $value); |
| 135 | 135 | }; |
| 136 | 136 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | private function _whereAttribute(string $arrayName, $value) |
| 150 | 150 | { |
| 151 | - $finderClosure = function ($value, $attributeValue) { |
|
| 151 | + $finderClosure = function($value, $attributeValue) { |
|
| 152 | 152 | return \in_array($value, $attributeValue->toArray()); |
| 153 | 153 | }; |
| 154 | 154 | |