RetrieveAllGpsCoordinates   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 88.24%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 4
eloc 18
c 4
b 1
f 2
dl 0
loc 56
ccs 15
cts 17
cp 0.8824
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 25 3
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar\Console;
4
5
use DavideCasiraghi\LaravelEventsCalendar\Facades\LaravelEventsCalendar;
6
use DavideCasiraghi\LaravelEventsCalendar\Models\Country;
7
use DavideCasiraghi\LaravelEventsCalendar\Models\EventVenue;
8
use Illuminate\Console\Command;
9
10
class RetrieveAllGpsCoordinates extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'retrieve-all-gps-coordinates';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'Assign to all the venues the corresponding GPS coordinates';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
30
     */
31 169
    public function __construct()
32
    {
33 169
        parent::__construct();
34 169
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return void
40
     */
41 1
    public function handle()
42
    {
43 1
        $eventVenues = EventVenue::all();
44 1
        $eventVenuesNumber = count($eventVenues);
45
46 1
        foreach ($eventVenues as $key => $eventVenue) {
47
48
            // Get GPS coordinates
49 1
            $address = Country::getCountryName($eventVenue->country_id).', '.$eventVenue->city.', '.$eventVenue->address.', '.$eventVenue->zip_code;
50 1
            $gpsCoordinates = LaravelEventsCalendar::getVenueGpsCoordinates($address);
0 ignored issues
show
Bug introduced by
The method getVenueGpsCoordinates() does not exist on DavideCasiraghi\LaravelE...s\LaravelEventsCalendar. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

50
            /** @scrutinizer ignore-call */ 
51
            $gpsCoordinates = LaravelEventsCalendar::getVenueGpsCoordinates($address);
Loading history...
51
52
            // Print info in console
53
            // if there are problems the geocode system assign this coordinates 39.78373 -100.445882
54 1
            if ($gpsCoordinates['lng'] != '-100.445882') {
55 1
                $this->info($key.' of '.$eventVenuesNumber.' - '.$address);
56 1
                $this->info($gpsCoordinates['lat'].' '.$gpsCoordinates['lng']);
57
            } else {
58
                $this->error($key.' of '.$eventVenuesNumber.' - '.$address);
59
                $this->error($gpsCoordinates['lat'].' '.$gpsCoordinates['lng']);
60
            }
61
62
            // Save the data
63 1
            $eventVenue->lat = $gpsCoordinates['lat'];
64 1
            $eventVenue->lng = $gpsCoordinates['lng'];
65 1
            $eventVenue->save();
66
        }
67 1
    }
68
}
69