Conditions | 5 |
Paths | 9 |
Total Lines | 65 |
Code Lines | 50 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
41 | public function handle() |
||
42 | { |
||
43 | $url = sprintf(self::URL, time() - mt_rand(1, 30), $this->current_page); |
||
44 | |||
45 | $response = Http::get($url); |
||
46 | |||
47 | if ($response->failed()) { |
||
48 | if (++$this->retry > self::MAX_RETRY) { |
||
49 | return; |
||
50 | } |
||
51 | |||
52 | dispatch(new SyncWithGeneanum($this->current_page, $this->retry)); |
||
53 | } |
||
54 | |||
55 | $result = $response->json(); |
||
56 | |||
57 | $has_more_result = $result['total'] > $result['page']; |
||
58 | if ($has_more_result) { |
||
59 | dispatch(new SyncWithGeneanum(++$this->current_page)) |
||
60 | ->delay(now()->addSeconds(mt_rand(10, 60))); |
||
61 | } |
||
62 | |||
63 | $rows = $result['rows']; |
||
64 | |||
65 | foreach ($rows as $row) { |
||
66 | $remote_id = $row['id']; |
||
67 | [ |
||
68 | $date, |
||
69 | $name, |
||
70 | $first_name, |
||
71 | $sex, |
||
72 | $father_first_name, |
||
73 | $father_is_dead, |
||
74 | $mother_name, |
||
75 | $mother_first_name, |
||
76 | $mother_is_dead, |
||
77 | $observation1, |
||
78 | $observation2, |
||
79 | $observation3, |
||
80 | $observation4, |
||
81 | $officer, |
||
82 | $parish, |
||
83 | $source, |
||
84 | $update, |
||
85 | ] = $row['cell']; |
||
86 | |||
87 | Geneanum::updateOrCreate(['remote_id' => $remote_id], |
||
88 | [ |
||
89 | 'date' => $date, |
||
90 | 'name' => $name, |
||
91 | 'first_name' => $first_name, |
||
92 | 'sex' => $sex, |
||
93 | 'father_first_name' => $father_first_name, |
||
94 | 'father_is_dead' => $father_is_dead, |
||
95 | 'mother_name' => $mother_name, |
||
96 | 'mother_first_name' => $mother_first_name, |
||
97 | 'mother_is_dead' => $mother_is_dead, |
||
98 | 'observation1' => $observation1, |
||
99 | 'observation2' => $observation2, |
||
100 | 'observation3' => $observation3, |
||
101 | 'observation4' => $observation4, |
||
102 | 'officer' => $officer, |
||
103 | 'parish' => $parish, |
||
104 | 'source' => $source, |
||
105 | 'update' => $update, |
||
106 | ]); |
||
111 |