CurrenciesTableSeeder::run()   C
last analyzed

Complexity

Conditions 15
Paths 1

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 29
rs 5.9166
c 0
b 0
f 0
cc 15
nc 1
nop 0

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
namespace Turahe\Master\Seeds;
4
5
use Illuminate\Database\Seeder;
6
use Turahe\Master\Models\Currency;
7
8
class CurrenciesTableSeeder extends Seeder
9
{
10
    /**
11
     * Run the database seeds.
12
     *
13
     * @return void
14
     */
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,
0 ignored issues
show
Bug introduced by
true of type true is incompatible with the type integer expected by parameter $options of json_encode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

28
                'alternate_symbols' => isset($currency['alternate_symbols']) ? json_encode($currency['alternate_symbols'], /** @scrutinizer ignore-type */ true) : null,
Loading history...
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
    }
45
}
46