@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | throw new Exception('loadJson Error: File name not set'); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - if (! file_exists($file) && ! file_exists($file = $this->dataDir("/$dir/".strtolower($file).'.json'))) { |
|
| 52 | + if (!file_exists($file) && !file_exists($file = $this->dataDir("/$dir/".strtolower($file).'.json'))) { |
|
| 53 | 53 | return coollect(); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | */ |
| 71 | 71 | public function loadJsonFiles($dir) |
| 72 | 72 | { |
| 73 | - return coollect(glob("$dir/*.json*"))->mapWithKeys(function ($file) { |
|
| 73 | + return coollect(glob("$dir/*.json*"))->mapWithKeys(function($file) { |
|
| 74 | 74 | $key = str_replace('.json', '', str_replace('.json5', '', basename($file))); |
| 75 | 75 | |
| 76 | 76 | return [$key => $this->loadJson($file)]; |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function moveFilesWildcard($from, $to) |
| 87 | 87 | { |
| 88 | - coollect(glob($this->dataDir($from)))->each(function ($from) use ($to) { |
|
| 88 | + coollect(glob($this->dataDir($from)))->each(function($from) use ($to) { |
|
| 89 | 89 | $this->mkDir($dir = $this->dataDir($to)); |
| 90 | 90 | |
| 91 | 91 | rename($from, $dir.'/'.basename($from)); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | /** |
| 65 | 65 | * Load json files from dir. |
| 66 | 66 | * |
| 67 | - * @param $dir |
|
| 67 | + * @param string $dir |
|
| 68 | 68 | * @return \PragmaRX\Coollection\Package\Coollection |
| 69 | 69 | */ |
| 70 | 70 | public function loadJsonFiles($dir) |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
| 108 | - * @param $contents |
|
| 108 | + * @param string $contents |
|
| 109 | 109 | * @return string |
| 110 | 110 | */ |
| 111 | 111 | public function sanitizeFile($contents) |
@@ -6,7 +6,7 @@ |
||
| 6 | 6 | { |
| 7 | 7 | public function defineConstants() |
| 8 | 8 | { |
| 9 | - if (! defined('__COUNTRIES_DIR__')) { |
|
| 9 | + if (!defined('__COUNTRIES_DIR__')) { |
|
| 10 | 10 | define( |
| 11 | 11 | '__COUNTRIES_DIR__', |
| 12 | 12 | realpath( |
@@ -83,7 +83,7 @@ |
||
| 83 | 83 | /** |
| 84 | 84 | * Build countries collection. |
| 85 | 85 | * |
| 86 | - * @param $dataDir |
|
| 86 | + * @param string $dataDir |
|
| 87 | 87 | * @return \PragmaRX\Coollection\Package\Coollection |
| 88 | 88 | */ |
| 89 | 89 | public function buildCountriesCoollection($dataDir) |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | $dataDir = '/countries/default/'; |
| 74 | 74 | |
| 75 | - $this->updater->setCountries($this->cache->remember('updateCountries->buildCountriesCoollection', 160, function () use ($dataDir) { |
|
| 75 | + $this->updater->setCountries($this->cache->remember('updateCountries->buildCountriesCoollection', 160, function() use ($dataDir) { |
|
| 76 | 76 | $this->helper->eraseDataDir($dataDir); |
| 77 | 77 | |
| 78 | 78 | return $this->buildCountriesCoollection($dataDir); |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $this->helper->message('Generating countries...'); |
| 106 | 106 | |
| 107 | - $countries = coollect($shapeFile)->map(function ($country) { |
|
| 107 | + $countries = coollect($shapeFile)->map(function($country) { |
|
| 108 | 108 | return $this->natural->fixNaturalOddCountries($country); |
| 109 | - })->mapWithKeys(function ($natural) use ($mledoze, $dataDir) { |
|
| 109 | + })->mapWithKeys(function($natural) use ($mledoze, $dataDir) { |
|
| 110 | 110 | list($mledoze, $countryCode) = $this->mledoze->findMledozeCountry($mledoze, $natural); |
| 111 | 111 | |
| 112 | - $natural = coollect($natural)->mapWithKeys(function ($country, $key) { |
|
| 112 | + $natural = coollect($natural)->mapWithKeys(function($country, $key) { |
|
| 113 | 113 | return [strtolower($key) => $country]; |
| 114 | 114 | }); |
| 115 | 115 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | public function clearCountryCurrencies($country) |
| 152 | 152 | { |
| 153 | - if (isset($country['currency']) && ! is_null($country['currency'])) { |
|
| 153 | + if (isset($country['currency']) && !is_null($country['currency'])) { |
|
| 154 | 154 | $country['currencies'] = $country['currency']->keys(); |
| 155 | 155 | |
| 156 | 156 | unset($country['currency']); |
@@ -2,10 +2,10 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace PragmaRX\Countries\Update; |
| 4 | 4 | |
| 5 | -use PragmaRX\Countries\Package\Support\Base; |
|
| 6 | -use PragmaRX\Countries\Package\Services\Config; |
|
| 7 | 5 | use PragmaRX\Countries\Package\Countries as CountriesService; |
| 8 | 6 | use PragmaRX\Countries\Package\Services\Cache\Service as Cache; |
| 7 | +use PragmaRX\Countries\Package\Services\Config; |
|
| 8 | +use PragmaRX\Countries\Package\Support\Base; |
|
| 9 | 9 | |
| 10 | 10 | class Countries extends Base |
| 11 | 11 | { |
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace PragmaRX\Countries\Update; |
| 4 | 4 | |
| 5 | -use PragmaRX\Countries\Package\Support\Base; |
|
| 6 | 5 | use PragmaRX\Coollection\Package\Coollection; |
| 6 | +use PragmaRX\Countries\Package\Support\Base; |
|
| 7 | 7 | |
| 8 | 8 | class Mledoze extends Base |
| 9 | 9 | { |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * Fill mledoze fields with natural earth vector data. |
| 61 | 61 | * |
| 62 | 62 | * @param $fields |
| 63 | - * @return mixed |
|
| 63 | + * @return Coollection |
|
| 64 | 64 | */ |
| 65 | 65 | public function fillMledozeFields($fields) |
| 66 | 66 | { |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @param \PragmaRX\Coollection\Package\Coollection $mledoze |
| 111 | 111 | * @param \PragmaRX\Coollection\Package\Coollection $natural |
| 112 | 112 | * @param string $suffix |
| 113 | - * @return mixed |
|
| 113 | + * @return Coollection |
|
| 114 | 114 | */ |
| 115 | 115 | public function mergeWithMledoze($mledoze, $natural, $suffix = '_nev') |
| 116 | 116 | { |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function loadMledozeCountries() |
| 45 | 45 | { |
| 46 | - $mledoze = coollect($this->helper->loadJson('countries', 'third-party/mledoze/dist'))->mapWithKeys(function ( |
|
| 46 | + $mledoze = coollect($this->helper->loadJson('countries', 'third-party/mledoze/dist'))->mapWithKeys(function( |
|
| 47 | 47 | $country |
| 48 | 48 | ) { |
| 49 | 49 | $country = $this->updater->addDataSource($country, 'mledoze'); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | { |
| 98 | 98 | list($country, $countryCode) = $this->updater->findCountryByAnyField($mledoze, $natural); |
| 99 | 99 | |
| 100 | - if (! $country->isEmpty()) { |
|
| 100 | + if (!$country->isEmpty()) { |
|
| 101 | 101 | return [coollect($this->helper->arrayKeysSnakeRecursive($country)), $countryCode]; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | $result = $this->makeFlag($result); |
| 158 | 158 | |
| 159 | - return coollect($result)->sortBy(function ($value, $key) { |
|
| 159 | + return coollect($result)->sortBy(function($value, $key) { |
|
| 160 | 160 | return $key; |
| 161 | 161 | }); |
| 162 | 162 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | /** |
| 50 | 50 | * Check if cache is enabled. |
| 51 | 51 | * |
| 52 | - * @return bool |
|
| 52 | + * @return \PragmaRX\Coollection\Package\Coollection |
|
| 53 | 53 | */ |
| 54 | 54 | protected function enabled() |
| 55 | 55 | { |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * Delete an item from the cache by its unique key. |
| 136 | 136 | * |
| 137 | 137 | * @param string $key |
| 138 | - * @return bool |
|
| 138 | + * @return boolean|null |
|
| 139 | 139 | */ |
| 140 | 140 | public function delete($key) |
| 141 | 141 | { |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | if (is_null($this->dir)) { |
| 56 | 56 | $this->dir = $this->config->cache->directory ?: sys_get_temp_dir().'/__PRAGMARX_COUNTRIES__/cache'; |
| 57 | 57 | |
| 58 | - if (! file_exists($this->dir)) { |
|
| 58 | + if (!file_exists($this->dir)) { |
|
| 59 | 59 | mkdir($this->dir, 0755, true); |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | public function getMultiple($keys, $default = null) |
| 145 | 145 | { |
| 146 | - return coollect($keys)->map(function ($key) { |
|
| 146 | + return coollect($keys)->map(function($key) { |
|
| 147 | 147 | return $this->get($key); |
| 148 | 148 | }); |
| 149 | 149 | } |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | public function setMultiple($values, $ttl = null) |
| 159 | 159 | { |
| 160 | - return coollect($values)->map(function ($value, $key) use ($ttl) { |
|
| 160 | + return coollect($values)->map(function($value, $key) use ($ttl) { |
|
| 161 | 161 | return $this->set($key, $value, $ttl); |
| 162 | 162 | }); |
| 163 | 163 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | public function deleteMultiple($keys) |
| 172 | 172 | { |
| 173 | - coollect($keys)->map(function ($key) { |
|
| 173 | + coollect($keys)->map(function($key) { |
|
| 174 | 174 | $this->forget($key); |
| 175 | 175 | }); |
| 176 | 176 | } |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | public function has($key) |
| 185 | 185 | { |
| 186 | - return ! is_null($this->get($key)); |
|
| 186 | + return !is_null($this->get($key)); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | { |
| 216 | 216 | $value = $this->get($key); |
| 217 | 217 | |
| 218 | - if (! is_null($value)) { |
|
| 218 | + if (!is_null($value)) { |
|
| 219 | 219 | return $value; |
| 220 | 220 | } |
| 221 | 221 | |
@@ -3,10 +3,10 @@ |
||
| 3 | 3 | namespace PragmaRX\Countries\Package\Services\Cache\Managers; |
| 4 | 4 | |
| 5 | 5 | use Closure; |
| 6 | -use Psr\SimpleCache\CacheInterface; |
|
| 7 | 6 | use Nette\Caching\Cache as NetteCache; |
| 8 | 7 | use Nette\Caching\Storages\FileStorage; |
| 9 | 8 | use PragmaRX\Countries\Package\Services\Config; |
| 9 | +use Psr\SimpleCache\CacheInterface; |
|
| 10 | 10 | |
| 11 | 11 | class Nette implements CacheInterface |
| 12 | 12 | { |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | /** |
| 47 | 47 | * Hydrator constructor. |
| 48 | 48 | * |
| 49 | - * @param object $config |
|
| 49 | + * @param Config $config |
|
| 50 | 50 | */ |
| 51 | 51 | public function __construct($config) |
| 52 | 52 | { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * Can hydrate? |
| 58 | 58 | * |
| 59 | 59 | * @param $element |
| 60 | - * @param $enabled |
|
| 60 | + * @param boolean $enabled |
|
| 61 | 61 | * @param $countryCode |
| 62 | 62 | * @return bool |
| 63 | 63 | */ |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @param $countries |
| 95 | 95 | * @param $elements |
| 96 | - * @return mixed |
|
| 96 | + * @return \PragmaRX\Countries\Package\Support\Collection |
|
| 97 | 97 | */ |
| 98 | 98 | private function hydrateCountries($countries, $elements = null) |
| 99 | 99 | { |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | * |
| 110 | 110 | * @param $country |
| 111 | 111 | * @param $elements |
| 112 | - * @return mixed |
|
| 112 | + * @return \PragmaRX\Countries\Package\Support\Collection |
|
| 113 | 113 | */ |
| 114 | 114 | private function hydrateCountry($country, $elements) |
| 115 | 115 | { |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Hydrate flag. |
| 286 | 286 | * |
| 287 | 287 | * @param $country |
| 288 | - * @return mixed |
|
| 288 | + * @return Coollection |
|
| 289 | 289 | */ |
| 290 | 290 | public function hydrateFlag($country) |
| 291 | 291 | { |
@@ -396,7 +396,7 @@ discard block |
||
| 396 | 396 | * Get country by country code. |
| 397 | 397 | * |
| 398 | 398 | * @param $countryCode |
| 399 | - * @return mixed |
|
| 399 | + * @return \PragmaRX\Countries\Package\Support\Collection |
|
| 400 | 400 | */ |
| 401 | 401 | public function getCountry($countryCode) |
| 402 | 402 | { |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | /** |
| 456 | 456 | * Repository setter. |
| 457 | 457 | * |
| 458 | - * @param $repository |
|
| 458 | + * @param \PragmaRX\Countries\Package\Data\Repository $repository |
|
| 459 | 459 | */ |
| 460 | 460 | public function setRepository($repository) |
| 461 | 461 | { |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | protected function canHydrate($element, $enabled, $countryCode) |
| 65 | 65 | { |
| 66 | 66 | return ($enabled || $this->config->get('hydrate.elements.'.$element)) && |
| 67 | - ! isset($this->repository->countries[$countryCode]['hydrated'][$element]); |
|
| 67 | + !isset($this->repository->countries[$countryCode]['hydrated'][$element]); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | protected function createHydrated($countryCode) |
| 74 | 74 | { |
| 75 | - if (! isset($this->repository->countries[$countryCode]['hydrated'])) { |
|
| 75 | + if (!isset($this->repository->countries[$countryCode]['hydrated'])) { |
|
| 76 | 76 | $this->repository->countries[$countryCode]['hydrated'] = []; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | protected function fixCurrencies($country) |
| 83 | 83 | { |
| 84 | - if (! isset($country['currencies']) && isset($country['currency'])) { |
|
| 84 | + if (!isset($country['currencies']) && isset($country['currency'])) { |
|
| 85 | 85 | $country['currencies'] = $country['currency']; |
| 86 | 86 | } |
| 87 | 87 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | private function hydrateCountries($countries, $elements = null) |
| 99 | 99 | { |
| 100 | 100 | return countriesCollect( |
| 101 | - $countries->map(function ($country) use ($elements) { |
|
| 101 | + $countries->map(function($country) use ($elements) { |
|
| 102 | 102 | return $this->hydrateCountry($country, $elements); |
| 103 | 103 | }) |
| 104 | 104 | ); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | protected function needsHydration($countryCode, $element, $enabled = false) |
| 194 | 194 | { |
| 195 | - if (! $this->canHydrate($element, $enabled, $countryCode)) { |
|
| 195 | + if (!$this->canHydrate($element, $enabled, $countryCode)) { |
|
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | public function hydrateBorders($country) |
| 306 | 306 | { |
| 307 | 307 | $country['borders'] = isset($country['borders']) |
| 308 | - ? $country['borders'] = countriesCollect($country['borders'])->map(function ($border) { |
|
| 308 | + ? $country['borders'] = countriesCollect($country['borders'])->map(function($border) { |
|
| 309 | 309 | return $this->repository->call('where', ['cca3', $border])->first(); |
| 310 | 310 | }) |
| 311 | 311 | : countriesCollect(); |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | { |
| 335 | 335 | $country = $this->hydrateTimezones($country); |
| 336 | 336 | |
| 337 | - $country['timezones'] = $country->timezones->map(function ($timezone) { |
|
| 337 | + $country['timezones'] = $country->timezones->map(function($timezone) { |
|
| 338 | 338 | return $timezone->overwrite(['times' => $this->repository->findTimezoneTime($timezone['zone_id'])]); |
| 339 | 339 | }); |
| 340 | 340 | |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | $country = $this->fixCurrencies($country); |
| 355 | 355 | |
| 356 | 356 | if (isset($country['currencies'])) { |
| 357 | - $currencies = countriesCollect($country['currencies'])->mapWithKeys(function ($code) { |
|
| 357 | + $currencies = countriesCollect($country['currencies'])->mapWithKeys(function($code) { |
|
| 358 | 358 | if ($this->isCurrenciesArray($code)) { |
| 359 | 359 | return [ |
| 360 | 360 | $code['ISO4217Code'] => $code, |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | */ |
| 412 | 412 | public function addCountry($countryCode, $country) |
| 413 | 413 | { |
| 414 | - if (! isset($this->repository->countries[$countryCode])) { |
|
| 414 | + if (!isset($this->repository->countries[$countryCode])) { |
|
| 415 | 415 | $this->repository->countries[$countryCode] = $country; |
| 416 | 416 | } |
| 417 | 417 | } |
@@ -438,14 +438,14 @@ discard block |
||
| 438 | 438 | */ |
| 439 | 439 | protected function checkHydrationElements($elements) |
| 440 | 440 | { |
| 441 | - $elements = countriesCollect($elements)->mapWithKeys(function ($value, $key) { |
|
| 441 | + $elements = countriesCollect($elements)->mapWithKeys(function($value, $key) { |
|
| 442 | 442 | if (is_numeric($key)) { |
| 443 | 443 | $key = $value; |
| 444 | 444 | $value = true; |
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | return [$key => $value]; |
| 448 | - })->filter(function ($element) { |
|
| 448 | + })->filter(function($element) { |
|
| 449 | 449 | return $element; |
| 450 | 450 | }); |
| 451 | 451 | |
@@ -3,12 +3,12 @@ |
||
| 3 | 3 | namespace PragmaRX\Countries\Update; |
| 4 | 4 | |
| 5 | 5 | use Exception; |
| 6 | -use ReflectionClass; |
|
| 7 | -use ShapeFile\ShapeFile; |
|
| 8 | -use RecursiveIteratorIterator; |
|
| 9 | -use RecursiveDirectoryIterator; |
|
| 10 | 6 | use PragmaRX\Countries\Package\Services\Command; |
| 11 | 7 | use PragmaRX\Countries\Package\Services\Helper as ServiceHelper; |
| 8 | +use RecursiveDirectoryIterator; |
|
| 9 | +use RecursiveIteratorIterator; |
|
| 10 | +use ReflectionClass; |
|
| 11 | +use ShapeFile\ShapeFile; |
|
| 12 | 12 | |
| 13 | 13 | class Helper |
| 14 | 14 | { |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | public function download($url, $directory) |
| 160 | 160 | { |
| 161 | - coollect((array) $url)->each(function ($url) use ($directory) { |
|
| 161 | + coollect((array) $url)->each(function($url) use ($directory) { |
|
| 162 | 162 | $filename = basename($url); |
| 163 | 163 | |
| 164 | 164 | $destination = $this->toDir("{$directory}/{$filename}"); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | |
| 216 | 216 | $fw = $this->fopenOrFail($destination, 'w'); |
| 217 | 217 | |
| 218 | - while (! feof($fr)) { |
|
| 218 | + while (!feof($fr)) { |
|
| 219 | 219 | fwrite($fw, fread($fr, 4096)); |
| 220 | 220 | flush(); |
| 221 | 221 | } |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $ch = curl_init(); |
| 237 | 237 | curl_setopt($ch, CURLOPT_URL, $url); |
| 238 | 238 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 239 | - curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function ($resource, $total, $downloaded) use (&$nextStep) { |
|
| 239 | + curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($resource, $total, $downloaded) use (&$nextStep) { |
|
| 240 | 240 | if ($downloaded > $nextStep) { |
| 241 | 241 | echo '.'; |
| 242 | 242 | $nextStep += 8192; |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | protected function renameMasterToPackage($file, $subPath, $path, $exclude) |
| 262 | 262 | { |
| 263 | 263 | if (ends_with($file, 'master.zip')) { |
| 264 | - $dir = coollect(scandir($path))->filter(function ($file) use ($exclude) { |
|
| 264 | + $dir = coollect(scandir($path))->filter(function($file) use ($exclude) { |
|
| 265 | 265 | return $file !== '.' && $file !== '..' && $file !== $exclude; |
| 266 | 266 | })->first(); |
| 267 | 267 | |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | { |
| 278 | 278 | $path = dirname($file); |
| 279 | 279 | |
| 280 | - if (! ends_with($file, '.zip') || file_exists($subPath = "$path/$subPath")) { |
|
| 280 | + if (!ends_with($file, '.zip') || file_exists($subPath = "$path/$subPath")) { |
|
| 281 | 281 | return; |
| 282 | 282 | } |
| 283 | 283 | |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | */ |
| 297 | 297 | public function delTree($dir) |
| 298 | 298 | { |
| 299 | - if (! file_exists($dir)) { |
|
| 299 | + if (!file_exists($dir)) { |
|
| 300 | 300 | return false; |
| 301 | 301 | } |
| 302 | 302 | |
@@ -333,9 +333,9 @@ discard block |
||
| 333 | 333 | |
| 334 | 334 | unset($shapeRecords); |
| 335 | 335 | |
| 336 | - return coollect($result)->mapWithKeys(function ($fields, $key1) { |
|
| 336 | + return coollect($result)->mapWithKeys(function($fields, $key1) { |
|
| 337 | 337 | return [ |
| 338 | - strtolower($key1) => coollect($fields)->mapWithKeys(function ($value, $key2) { |
|
| 338 | + strtolower($key1) => coollect($fields)->mapWithKeys(function($value, $key2) { |
|
| 339 | 339 | return [strtolower($key2) => $value]; |
| 340 | 340 | }), |
| 341 | 341 | ]; |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | |
| 355 | 355 | $array = arrayable($array) ? $array->toArray() : $array; |
| 356 | 356 | |
| 357 | - array_walk($array, function ($value, $key) use (&$result) { |
|
| 357 | + array_walk($array, function($value, $key) use (&$result) { |
|
| 358 | 358 | $result[snake_case($key)] = arrayable($value) || is_array($value) |
| 359 | 359 | ? $this->arrayKeysSnakeRecursive($value) |
| 360 | 360 | : $value; |
@@ -382,7 +382,7 @@ discard block |
||
| 382 | 382 | */ |
| 383 | 383 | public function fixUtf8($string) |
| 384 | 384 | { |
| 385 | - return preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function ($match) { |
|
| 385 | + return preg_replace_callback('/\\\\u([0-9a-fA-F]{4})/', function($match) { |
|
| 386 | 386 | return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE'); |
| 387 | 387 | }, $string); |
| 388 | 388 | } |
@@ -418,9 +418,9 @@ discard block |
||
| 418 | 418 | */ |
| 419 | 419 | public function downloadDataFiles() |
| 420 | 420 | { |
| 421 | - $this->config->get('downloadable')->each(function ($urls, $path) { |
|
| 422 | - if (! file_exists($destination = $this->dataDir("third-party/$path"))) { |
|
| 423 | - coollect($urls)->each(function ($url) use ($path, $destination) { |
|
| 421 | + $this->config->get('downloadable')->each(function($urls, $path) { |
|
| 422 | + if (!file_exists($destination = $this->dataDir("third-party/$path"))) { |
|
| 423 | + coollect($urls)->each(function($url) use ($path, $destination) { |
|
| 424 | 424 | $this->download($url, $destination); |
| 425 | 425 | |
| 426 | 426 | $file = basename($url); |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | */ |
| 489 | 489 | public function loadJsonFiles($dir) |
| 490 | 490 | { |
| 491 | - return coollect(glob("$dir/*.json*"))->mapWithKeys(function ($file) { |
|
| 491 | + return coollect(glob("$dir/*.json*"))->mapWithKeys(function($file) { |
|
| 492 | 492 | $key = str_replace('.json', '', str_replace('.json5', '', basename($file))); |
| 493 | 493 | |
| 494 | 494 | return [$key => $this->loadJson($file)]; |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | */ |
| 522 | 522 | public function moveDataFiles() |
| 523 | 523 | { |
| 524 | - $this->config->get('moveable')->each(function ($to, $from) { |
|
| 524 | + $this->config->get('moveable')->each(function($to, $from) { |
|
| 525 | 525 | $this->moveDataFile($from, $to); |
| 526 | 526 | }); |
| 527 | 527 | } |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | */ |
| 551 | 551 | public function message($message, $type = 'line') |
| 552 | 552 | { |
| 553 | - if (! is_null($this->command)) { |
|
| 553 | + if (!is_null($this->command)) { |
|
| 554 | 554 | $this->command->{$type}($message); |
| 555 | 555 | } |
| 556 | 556 | } |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | $this->abort('loadCsv Error: File name not set'); |
| 581 | 581 | } |
| 582 | 582 | |
| 583 | - if (! file_exists($file)) { |
|
| 583 | + if (!file_exists($file)) { |
|
| 584 | 584 | $file = $this->dataDir($this->addSuffix('.csv', "/$dir/".strtolower($file))); |
| 585 | 585 | } |
| 586 | 586 | |
@@ -596,7 +596,7 @@ discard block |
||
| 596 | 596 | */ |
| 597 | 597 | public function makeJsonFileName($key, $dir = '') |
| 598 | 598 | { |
| 599 | - if (! ends_with($dir, (DIRECTORY_SEPARATOR))) { |
|
| 599 | + if (!ends_with($dir, (DIRECTORY_SEPARATOR))) { |
|
| 600 | 600 | $dir .= DIRECTORY_SEPARATOR; |
| 601 | 601 | } |
| 602 | 602 | |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | { |
| 678 | 678 | $this->progress('--- Delete temporary files'); |
| 679 | 679 | |
| 680 | - $this->config->get('deletable')->each(function ($directory) { |
|
| 680 | + $this->config->get('deletable')->each(function($directory) { |
|
| 681 | 681 | if (file_exists($directory = $this->dataDir($directory))) { |
| 682 | 682 | $this->deleteDirectory($directory); |
| 683 | 683 | } |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | /** |
| 70 | 70 | * Add suffix to string. |
| 71 | 71 | * |
| 72 | - * @param $suffix |
|
| 73 | - * @param $string |
|
| 74 | - * @return mixed |
|
| 72 | + * @param string string |
|
| 73 | + * @param string $string |
|
| 74 | + * @return string |
|
| 75 | 75 | */ |
| 76 | 76 | protected function addSuffix($suffix, $string) |
| 77 | 77 | { |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | /** |
| 99 | 99 | * Delete a whole directory. |
| 100 | 100 | * |
| 101 | - * @param $dir |
|
| 101 | + * @param string $dir |
|
| 102 | 102 | */ |
| 103 | 103 | protected function deleteDirectory($dir) |
| 104 | 104 | { |
@@ -116,6 +116,11 @@ discard block |
||
| 116 | 116 | rmdir($dir); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | + /** |
|
| 120 | + * @param string $string |
|
| 121 | + * |
|
| 122 | + * @return resource |
|
| 123 | + */ |
|
| 119 | 124 | protected function fopenOrFail($url, $string) |
| 120 | 125 | { |
| 121 | 126 | if (($handle = @fopen($url, $string)) === false) { |
@@ -184,7 +189,7 @@ discard block |
||
| 184 | 189 | |
| 185 | 190 | /** |
| 186 | 191 | * @param $url |
| 187 | - * @param $destination |
|
| 192 | + * @param string $destination |
|
| 188 | 193 | */ |
| 189 | 194 | public function downloadFile($url, $destination) |
| 190 | 195 | { |
@@ -255,8 +260,8 @@ discard block |
||
| 255 | 260 | /** |
| 256 | 261 | * @param $file |
| 257 | 262 | * @param $subPath |
| 258 | - * @param $path |
|
| 259 | - * @param $exclude |
|
| 263 | + * @param string $path |
|
| 264 | + * @param string $exclude |
|
| 260 | 265 | */ |
| 261 | 266 | protected function renameMasterToPackage($file, $subPath, $path, $exclude) |
| 262 | 267 | { |
@@ -310,7 +315,7 @@ discard block |
||
| 310 | 315 | /** |
| 311 | 316 | * Load a shapeFile. |
| 312 | 317 | * |
| 313 | - * @param $dir |
|
| 318 | + * @param string $dir |
|
| 314 | 319 | * @return \PragmaRX\Coollection\Package\Coollection |
| 315 | 320 | */ |
| 316 | 321 | public function shapeFile($dir) |
@@ -391,7 +396,7 @@ discard block |
||
| 391 | 396 | * Unzip a file. |
| 392 | 397 | * |
| 393 | 398 | * @param $file |
| 394 | - * @param $path |
|
| 399 | + * @param string $path |
|
| 395 | 400 | */ |
| 396 | 401 | public function unzip($file, $path) |
| 397 | 402 | { |
@@ -483,7 +488,7 @@ discard block |
||
| 483 | 488 | /** |
| 484 | 489 | * Load json files from dir. |
| 485 | 490 | * |
| 486 | - * @param $dir |
|
| 491 | + * @param string $dir |
|
| 487 | 492 | * @return \PragmaRX\Coollection\Package\Coollection |
| 488 | 493 | */ |
| 489 | 494 | public function loadJsonFiles($dir) |
@@ -569,7 +574,7 @@ discard block |
||
| 569 | 574 | /** |
| 570 | 575 | * Loads a json file. |
| 571 | 576 | * |
| 572 | - * @param $file |
|
| 577 | + * @param string $file |
|
| 573 | 578 | * @param string $dir |
| 574 | 579 | * @return \PragmaRX\Coollection\Package\Coollection |
| 575 | 580 | * @throws \Exception |
@@ -606,7 +611,7 @@ discard block |
||
| 606 | 611 | /** |
| 607 | 612 | * Put contents into a file. |
| 608 | 613 | * |
| 609 | - * @param $file |
|
| 614 | + * @param string $file |
|
| 610 | 615 | * @param $contents |
| 611 | 616 | */ |
| 612 | 617 | public function putFile($file, $contents) |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | /** |
| 52 | 52 | * Fill mledoze fields with natural earth vector data. |
| 53 | 53 | * |
| 54 | - * @param $fields |
|
| 54 | + * @param Coollection $fields |
|
| 55 | 55 | * @return mixed |
| 56 | 56 | */ |
| 57 | 57 | public function fillMledozeFields($fields) |
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace PragmaRX\Countries\Update; |
| 4 | 4 | |
| 5 | -use PragmaRX\Countries\Package\Support\Base; |
|
| 6 | 5 | use PragmaRX\Coollection\Package\Coollection; |
| 6 | +use PragmaRX\Countries\Package\Support\Base; |
|
| 7 | 7 | |
| 8 | 8 | class Nationality extends Base |
| 9 | 9 | { |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | public function load() |
| 37 | 37 | { |
| 38 | - $mledoze = coollect($this->helper->loadJson('countries', 'third-party/mledoze/dist'))->mapWithKeys(function ( |
|
| 38 | + $mledoze = coollect($this->helper->loadJson('countries', 'third-party/mledoze/dist'))->mapWithKeys(function( |
|
| 39 | 39 | $country |
| 40 | 40 | ) { |
| 41 | 41 | $country = $this->updater->addDataSource($country, 'mledoze'); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | { |
| 90 | 90 | list($country, $countryCode) = $this->updater->findCountryByAnyField($mledoze, $natural); |
| 91 | 91 | |
| 92 | - if (! $country->isEmpty()) { |
|
| 92 | + if (!$country->isEmpty()) { |
|
| 93 | 93 | return [coollect($this->helper->arrayKeysSnakeRecursive($country)), $countryCode]; |
| 94 | 94 | } |
| 95 | 95 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $result[$key] = $mledozeValue; // Natural Earth Vector |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - return coollect($result)->sortBy(function ($value, $key) { |
|
| 140 | + return coollect($result)->sortBy(function($value, $key) { |
|
| 141 | 141 | return $key; |
| 142 | 142 | }); |
| 143 | 143 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | 94 | * Updater constructor. |
| 95 | - * @param object $config |
|
| 95 | + * @param ConfigService $config |
|
| 96 | 96 | * @param Helper $helper |
| 97 | 97 | */ |
| 98 | 98 | public function __construct($config, Helper $helper) |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
| 134 | - * @return mixed |
|
| 134 | + * @return Command |
|
| 135 | 135 | */ |
| 136 | 136 | public function getCommand() |
| 137 | 137 | { |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
| 222 | - * @param $result |
|
| 223 | - * @param $type |
|
| 222 | + * @param Coollection $result |
|
| 223 | + * @param string $type |
|
| 224 | 224 | * @return \PragmaRX\Coollection\Package\Coollection |
| 225 | 225 | */ |
| 226 | 226 | public function addRecordType($result, $type) |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | * @param \PragmaRX\Coollection\Package\Coollection $on |
| 260 | 260 | * @param \PragmaRX\Coollection\Package\Coollection $by |
| 261 | 261 | * @param $fields |
| 262 | - * @param $codeField |
|
| 262 | + * @param string $codeField |
|
| 263 | 263 | * @return array |
| 264 | 264 | */ |
| 265 | 265 | public function findByFields($on, $by, $fields, $codeField) |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | /** |
| 342 | 342 | * @param $result |
| 343 | 343 | * @param $dir |
| 344 | - * @param $normalizerClosure |
|
| 344 | + * @param Closure $normalizerClosure |
|
| 345 | 345 | * @return array |
| 346 | 346 | */ |
| 347 | 347 | public function normalizeData($result, $dir, $normalizerClosure) |
@@ -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 | |
@@ -3,12 +3,12 @@ |
||
| 3 | 3 | namespace PragmaRX\Countries\Update; |
| 4 | 4 | |
| 5 | 5 | use Closure; |
| 6 | -use PragmaRX\Countries\Package\Support\Base; |
|
| 7 | 6 | use PragmaRX\Coollection\Package\Coollection; |
| 8 | 7 | use PragmaRX\Countries\Package\Contracts\Config; |
| 9 | -use PragmaRX\Countries\Package\Services\Command; |
|
| 10 | 8 | use PragmaRX\Countries\Package\Services\Cache\Service as Cache; |
| 9 | +use PragmaRX\Countries\Package\Services\Command; |
|
| 11 | 10 | use PragmaRX\Countries\Package\Services\Config as ConfigService; |
| 11 | +use PragmaRX\Countries\Package\Support\Base; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * @codeCoverageIgnore |