| Conditions | 15 |
| Paths | 1 |
| Total Lines | 29 |
| Code Lines | 22 |
| 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 | //Get all of the currencies |
||
| 18 | $file = __DIR__.'/../../resources/currencies.json'; |
||
| 19 | |||
| 20 | $data = json_decode(file_get_contents($file), true); |
||
| 21 | $currencies = array_map(function ($currency) { |
||
| 22 | return [ |
||
| 23 | 'priority' => isset($currency['priority']) ? $currency['priority'] : 100, |
||
| 24 | 'iso_code' => isset($currency['iso_code']) ? $currency['iso_code'] : null, |
||
| 25 | 'name' => isset($currency['name']) ? $currency['name'] : null, |
||
| 26 | 'symbol' => isset($currency['symbol']) ? $currency['symbol'] : null, |
||
| 27 | 'disambiguate_symbol' => isset($currency['disambiguate_symbol']) ? $currency['disambiguate_symbol'] : null, |
||
| 28 | 'alternate_symbols' => isset($currency['alternate_symbols']) ? json_encode($currency['alternate_symbols'], true) : null, |
||
|
|
|||
| 29 | 'subunit' => isset($currency['subunit']) ? $currency['subunit'] : null, |
||
| 30 | 'subunit_to_unit' => isset($currency['subunit_to_unit']) ? $currency['subunit_to_unit'] : 100, |
||
| 31 | 'symbol_first' => isset($currency['symbol_first']) ? $currency['symbol_first'] : 1, |
||
| 32 | 'html_entity' => isset($currency['html_entity']) ? $currency['html_entity'] : null, |
||
| 33 | 'decimal_mark' => isset($currency['decimal_mark']) ? $currency['decimal_mark'] : '.', |
||
| 34 | 'thousands_separator' => isset($currency['thousands_separator']) ? $currency['thousands_separator'] : ',', |
||
| 35 | 'iso_numeric' => isset($currency['iso_numeric']) ? $currency['iso_numeric'] : null, |
||
| 36 | 'smallest_denomination' => isset($currency['smallest_denomination']) ? $currency['smallest_denomination'] : 1, |
||
| 37 | 'created_at' => now()->toDateTimeString(), |
||
| 38 | 'updated_at' => now()->toDateTimeString(), |
||
| 39 | |||
| 40 | ]; |
||
| 41 | }, $data); |
||
| 42 | |||
| 43 | Currency::insert($currencies); |
||
| 44 | } |
||
| 46 |