Total Complexity | 5 |
Total Lines | 30 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
14 | class SyncRatesCommand extends Command |
||
15 | { |
||
16 | protected $signature = 'tcmb:syncrates {date?} {endDate?}'; |
||
17 | protected $description = 'Get currency rates from the Central Bank of the Republic of Turkey'; |
||
18 | private array $rates = []; |
||
19 | |||
20 | public function handle() : void |
||
21 | { |
||
22 | $begin = new DateTime($this->argument('date') ?? date('Y-m-d')); |
||
|
|||
23 | $end = new DateTime($this->argument('endDate') ?? date('Y-m-d')); |
||
24 | |||
25 | if($begin != $end) { |
||
26 | $period = new DatePeriod($begin, DateInterval::createFromDateString('1 day'), $end); |
||
27 | foreach ($period as $dt){ |
||
28 | $this->syncRates($dt); |
||
29 | } |
||
30 | }else{ |
||
31 | $this->syncRates($begin); |
||
32 | } |
||
33 | ExchangeRate::insertOrIgnore($this->rates); |
||
34 | } |
||
35 | |||
36 | private function syncRates(DateTime $dt) : void |
||
44 | } |
||
45 | } |
||
47 |