Passed
Push — master ( c14754...f81f92 )
by Davide
47:05 queued 11s
created

RetrieveAllGpsCoordinates::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 19
ccs 0
cts 11
cp 0
rs 9.9332
cc 2
nc 2
nop 0
crap 6
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 152
    public function __construct()
32
    {
33 152
        parent::__construct();
34 152
    }
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;
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 on screen
54
            $this->info($key." of ".$eventVenuesNumber." - ".$address);
55
            $this->info($gpsCoordinates['lat']." ".$gpsCoordinates['lng']);
56
            
57
            // Save the data
58
            $eventVenue->lat = $gpsCoordinates['lat'];
59
            $eventVenue->lng = $gpsCoordinates['lng'];
60
            $eventVenue->save();
61
        }
62
    }
63
}
64