FeedInTimezone   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 1
A saveUtcData() 0 19 3
A fetchTimezones() 0 9 2
1
<?php
2
3
/**
4
 * Author: Emmanuel Paul Mnzava
5
 * Twitter: @epmnzava
6
 * Github:https://github.com/dbrax/eticket
7
 * Email: [email protected]
8
 * 
9
 */
10
11
namespace Epmnzava\Eticket\Console;
12
13
use Epmnzava\BillMe\Models\Timezone;
14
use Epmnzava\Eticket\Actions\GetTimezone;
15
use Illuminate\Console\Command;
16
use Illuminate\Support\Facades\File;
17
use Illuminate\Support\Facades\Http;
18
use GuzzleHttp\Exception\GuzzleException;
19
use GuzzleHttp\Client;
20
use GuzzleHttp\Psr7\Request;
21
22
class FeedInTimezone extends Command
23
{
24
    protected $signature = 'eticket:feedtimezone';
25
26
    protected $description = 'feed in timezone ';
27
28
    public function handle()
29
    {
30
        $this->info('Begining to feed in timezone');
31
32
        $timezones = $this->fetchTimezones();
33
34
        $this->saveUtcData($timezones);
35
36
37
38
        $this->info('End setting ticket timezone feedin');
39
    }
40
41
    public function saveUtcData($timezones)
42
    {
43
44
        foreach($timezones as $timezone){
45
        $client=new Client();
46
        $response = json_decode($client->request('GET', 'https://timezoneapi.io/api/timezone/?'.$timezone.'&token='.config('eticket.timezone_token')));
47
     
48
        if($response->meta->code==200){
49
50
            $utc=new Timezone;
51
            $utc->timezone=$timezone;
52
            $utc->gmt=$response->data->datetime->offset_gmt;
53
            $utc->save();
54
        }
55
56
57
58
        }
59
    }
60
61
    public function fetchTimezones()
62
    {
63
64
        $client=new Client();
65
        $response = $client->request('GET', 'http://worldtimeapi.org/api/timezone');
66
        
67
        if($response->getStatusCode()==200)
68
        return json_decode($response->getBody());
69
    }
70
}
71