Conditions | 3 |
Paths | 1 |
Total Lines | 69 |
Code Lines | 56 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
43 | public function handle() |
||
44 | { |
||
45 | $count = Province::count(); |
||
46 | $this->info("Processing {$count} Province"); |
||
47 | $bar = $this->output->createProgressBar($count); |
||
|
|||
48 | $bar->start(); |
||
49 | Province::cursor()->each(function ($item) use ($bar) { |
||
50 | $meta = $item->meta; |
||
51 | $geocoding = \Geocoder::getCoordinatesForAddress($item->address); |
||
52 | $meta['lat'] = $geocoding['lat'] ?? null; |
||
53 | $meta['long'] = $geocoding['lng'] ?? null; |
||
54 | $item->meta = $meta; |
||
55 | $item->save(); |
||
56 | $bar->advance(); |
||
57 | }); |
||
58 | |||
59 | $this->line(''); |
||
60 | |||
61 | $count = City::count(); |
||
62 | $this->info("Processing {$count} City"); |
||
63 | $bar = $this->output->createProgressBar($count); |
||
64 | $bar->start(); |
||
65 | City::with('provinsi')->cursor()->each(function ($item) use ($bar) { |
||
66 | $meta = $item->meta; |
||
67 | $geocoding = \Geocoder::getCoordinatesForAddress($item->address); |
||
68 | $meta['lat'] = $geocoding['lat'] ?? null; |
||
69 | $meta['long'] = $geocoding['lng'] ?? null; |
||
70 | $item->meta = $meta; |
||
71 | $item->save(); |
||
72 | $bar->advance(); |
||
73 | }); |
||
74 | |||
75 | $this->line(''); |
||
76 | |||
77 | $count = District::count(); |
||
78 | $this->info("Processing {$count} District"); |
||
79 | $bar = $this->output->createProgressBar($count); |
||
80 | $bar->start(); |
||
81 | District::with('kabupaten.provinsi')->cursor()->each(function ($item) use ($bar) { |
||
82 | $meta = $item->meta; |
||
83 | $geocoding = \Geocoder::getCoordinatesForAddress($item->address); |
||
84 | $meta['lat'] = $geocoding['lat'] ?? null; |
||
85 | $meta['long'] = $geocoding['lng'] ?? null; |
||
86 | $item->meta = $meta; |
||
87 | $item->save(); |
||
88 | $bar->advance(); |
||
89 | }); |
||
90 | |||
91 | $this->line(''); |
||
92 | |||
93 | $count = Village::whereNull('meta')->count(); |
||
94 | $this->info("Processing {$count} Village"); |
||
95 | $bar = $this->output->createProgressBar($count); |
||
96 | $bar->start(); |
||
97 | Village::whereNull('meta')->cursor()->each(function ($item) use ($bar) { |
||
98 | $meta = $item->meta; |
||
99 | if (!$meta) { |
||
100 | try { |
||
101 | $geocoding = \Geocoder::getCoordinatesForAddress($item->address); |
||
102 | $meta['lat'] = $geocoding['lat'] ?? null; |
||
103 | $meta['long'] = $geocoding['lng'] ?? null; |
||
104 | $item->meta = $meta; |
||
105 | $item->save(); |
||
106 | } catch (ServerException $e) { |
||
107 | $this->error($e->getMessage()); |
||
108 | sleep(1); |
||
109 | } |
||
110 | } |
||
111 | $bar->advance(); |
||
112 | }); |
||
115 |