Conditions | 7 |
Paths | 13 |
Total Lines | 57 |
Code Lines | 39 |
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 |
||
65 | public function handle() |
||
66 | { |
||
67 | if ($this->option('all')) { |
||
68 | $servers = Server::with('node')->get(); |
||
69 | } elseif ($this->option('node')) { |
||
70 | $servers = Server::with('node')->where('node_id', $this->option('node'))->get(); |
||
71 | } elseif ($this->option('server')) { |
||
72 | $servers = Server::with('node')->where('id', $this->option('server'))->get(); |
||
73 | } else { |
||
74 | $this->error('You must pass a flag to determine which server(s) to rebuild.'); |
||
75 | return; |
||
76 | } |
||
77 | |||
78 | $this->line('Beginning processing, do not exit this script.'); |
||
79 | $bar = $this->output->createProgressBar(count($servers)); |
||
80 | $results = collect([]); |
||
81 | foreach($servers as $server) { |
||
82 | try { |
||
83 | $server->node->guzzleClient([ |
||
84 | 'X-Access-Server' => $server->uuid, |
||
85 | 'X-Access-Token' => $server->node->daemonSecret, |
||
86 | ])->request('POST', '/server/rebuild'); |
||
87 | |||
88 | $results = $results->merge([ |
||
89 | $server->uuid => [ |
||
90 | 'status' => 'info', |
||
91 | 'messages' => [ |
||
92 | '[✓] Processed rebuild request for ' . $server->uuid, |
||
93 | ], |
||
94 | ], |
||
95 | ]); |
||
96 | } catch (\Exception $ex) { |
||
97 | $results = $results->merge([ |
||
98 | $server->uuid => [ |
||
99 | 'status' => 'error', |
||
100 | 'messages' => [ |
||
101 | '[✗] Failed to process rebuild request for ' . $server->uuid, |
||
102 | $ex->getMessage(), |
||
103 | ], |
||
104 | ], |
||
105 | ]); |
||
106 | } |
||
107 | |||
108 | $bar->advance(); |
||
109 | } |
||
110 | |||
111 | $bar->finish(); |
||
112 | $console = $this; |
||
113 | |||
114 | $this->line("\n"); |
||
115 | $results->each(function ($item, $key) use ($console) { |
||
116 | foreach($item['messages'] as $line) { |
||
117 | $console->{$item['status']}($line); |
||
118 | } |
||
119 | }); |
||
120 | $this->line("\nCompleted rebuild command processing."); |
||
121 | } |
||
122 | } |
||
123 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.