Conditions | 10 |
Paths | 1 |
Total Lines | 28 |
Code Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
15 | public function run() |
||
16 | { |
||
17 | $file = __DIR__.'/../../resources/countries.json'; |
||
18 | $data = json_decode(file_get_contents($file), true); |
||
19 | $countries = array_map(function ($country) { |
||
20 | return [ |
||
21 | 'capital' => $country['capital'] ?? null, |
||
22 | 'citizenship' => ((isset($country['citizenship'])) ? $country['citizenship'] : null), |
||
23 | 'country_code' => $country['country-code'], |
||
24 | 'currency' => ((isset($country['currency'])) ? $country['currency'] : null), |
||
25 | 'currency_code' => ((isset($country['currency_code'])) ? $country['currency_code'] : null), |
||
26 | 'currency_sub_unit' => ((isset($country['currency_sub_unit'])) ? $country['currency_sub_unit'] : null), |
||
27 | 'full_name' => ((isset($country['full_name'])) ? $country['full_name'] : null), |
||
28 | 'iso_3166_2' => $country['iso_3166_2'], |
||
29 | 'iso_3166_3' => $country['iso_3166_3'], |
||
30 | 'name' => $country['name'], |
||
31 | 'region_code' => (isset($country['region-code'])) ? $country['region-code'] : null, //$country['region-code'], |
||
32 | 'sub_region_code' => (isset($country['sub-region-code'])) ? $country['sub-region-code'] : null, //$country['sub-region-code'], |
||
33 | 'eea' => (bool) $country['eea'], |
||
34 | 'calling_code' => $country['calling_code'], |
||
35 | 'currency_symbol' => ((isset($country['currency_symbol'])) ? $country['currency_symbol'] : null), |
||
36 | 'flag' =>((isset($country['flag'])) ? $country['flag'] : null), |
||
37 | 'created_at' => now()->toDateTimeString(), |
||
38 | 'updated_at' => now()->toDateTimeString(), |
||
39 | ]; |
||
40 | }, $data); |
||
41 | |||
42 | Country::insert($countries); |
||
43 | } |
||
45 |