Conditions | 10 |
Paths | 384 |
Total Lines | 74 |
Code Lines | 47 |
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 |
||
135 | protected function createServer(Provider $provider) |
||
136 | { |
||
137 | if ($provider->provider() !== 'custom') { |
||
138 | $size = $this->choice('Choose server size', array_keys($provider->sizes())); |
||
139 | $provider->withMemoryOf($size); |
||
140 | |||
141 | $regions = $provider->regions(); |
||
142 | |||
143 | $region = $this->choice('Choose server region', $regions); |
||
144 | |||
145 | if ($provider->provider() === 'linode') { |
||
146 | $flippedRegions = array_flip($regions); |
||
147 | $region = $flippedRegions[$region]; |
||
148 | } |
||
149 | |||
150 | $provider->at($region); |
||
151 | } |
||
152 | |||
153 | $phpVersion = $this->choice('Choose PHP version', $provider->phpVersions()); |
||
154 | $provider->runningPhp($phpVersion); |
||
155 | |||
156 | $databaseName = 'forge'; |
||
157 | |||
158 | if ($this->confirm('Do you want to set new database name?')) { |
||
159 | $databaseName = $this->ask('Choose database name'); |
||
160 | } else { |
||
161 | $this->comment('OK, using default database name ("forge").'); |
||
162 | } |
||
163 | |||
164 | if ($this->confirm('Do you want to install MariaDb instead of MySQL?')) { |
||
165 | $provider->withMariaDb($databaseName); |
||
166 | $this->comment('OK, MariaDb server will be installed'); |
||
167 | } else { |
||
168 | $provider->withMysql($databaseName); |
||
169 | $this->comment('OK, MySQL server will be installed.'); |
||
170 | } |
||
171 | |||
172 | if ($this->confirm('Do you want to provision this server as load balancer?', false)) { |
||
173 | $provider->asLoadBalancer(); |
||
174 | $this->comment('OK, server will be provisioned as load balancer.'); |
||
175 | } |
||
176 | |||
177 | if ($provider->provider() === 'custom') { |
||
178 | $publicIp = $this->ask('Please, provide public IP address for this VPS'); |
||
179 | $privateIp = $this->ask('Please, provide private IP address for this VPS'); |
||
180 | |||
181 | $provision->usingPublicIp($publicIp)->usingPrivateIp($privateIp); |
||
182 | } |
||
183 | |||
184 | $hasCredentials = $provider->hasPayload('credential_id'); |
||
185 | $credentialMessage = 'Seems that you\'re using predefined credential. Do you want to change credential for this server?'; |
||
186 | $updateCredential = $hasCredentials === false || $this->confirm($credentialMessage, false); |
||
187 | |||
188 | if ($updateCredential) { |
||
189 | $credentialId = $this->ask('Enter credential ID'); |
||
190 | $provider->usingCredential($credentialId); |
||
191 | } else { |
||
192 | $this->comment('OK, default credential will be used.'); |
||
193 | } |
||
194 | |||
195 | try { |
||
196 | $server = $provider->save(); |
||
197 | } catch (RequestException $e) { |
||
198 | $response = $e->getResponse(); |
||
199 | |||
200 | $this->error('Request ended with error.'); |
||
201 | $this->error('HTTP Status Code: '.$response->getStatusCode()); |
||
202 | |||
203 | return $this->error((string) $response->getBody()); |
||
204 | } |
||
205 | |||
206 | $this->info('Great! Your new server "'.$server->name().'" was created!'); |
||
207 | $this->info('Please allow up to 10-15 minutes to finish server provision.'); |
||
208 | } |
||
209 | |||
242 |