Passed
Pull Request — master (#158)
by Davide
142:57 queued 103:47
created

RetrieveAllGpsCoordinates   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 17.65%

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 4
eloc 18
c 4
b 1
f 2
dl 0
loc 57
ccs 3
cts 17
cp 0.1765
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 159
    public function __construct()
32
    {
33 159
        parent::__construct();
34 159
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @param
40
     * @return mixed
41
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment @return at position 0 could not be parsed: Unknown type name '@return' at position 0 in @return.
Loading history...
42
    public function handle()
43
    {
44
        $eventVenues = EventVenue::all();
45
        $eventVenuesNumber = count($eventVenues);
46
47
        foreach ($eventVenues as $key => $eventVenue) {
48
49
            // Get GPS coordinates
50
            $address = Country::getCountryName($eventVenue->country_id).', '.$eventVenue->city.', '.$eventVenue->address.', '.$eventVenue->zip_code;
51
            $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

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