Total Complexity | 41 |
Total Lines | 455 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 2 | Features | 0 |
Complex classes like Configure often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Configure, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
57 | class Configure extends Command { |
||
58 | |||
59 | /** @var SignalGateway */ |
||
60 | private $signalGateway; |
||
61 | |||
62 | /** @var SMSGateway */ |
||
63 | private $smsGateway; |
||
64 | |||
65 | /** @var TelegramGateway */ |
||
66 | private $telegramGateway; |
||
67 | |||
68 | /** @var XMPPGateway */ |
||
69 | private $xmppGateway; |
||
70 | |||
71 | public function __construct(SignalGateway $signalGateway, |
||
85 | ); |
||
86 | } |
||
87 | |||
88 | protected function execute(InputInterface $input, OutputInterface $output) { |
||
89 | $gatewayName = $input->getArgument('gateway'); |
||
90 | |||
91 | /** @var IGateway $gateway */ |
||
92 | $gateway = null; |
||
93 | switch ($gatewayName) { |
||
94 | case 'signal': |
||
95 | $this->configureSignal($input, $output); |
||
96 | return 0; |
||
97 | case 'sms': |
||
98 | $this->configureSms($input, $output); |
||
99 | return 0; |
||
100 | case 'telegram': |
||
101 | $this->configureTelegram($input, $output); |
||
102 | return 0; |
||
103 | case 'xmpp': |
||
104 | $this->configureXMPP($input, $output); |
||
105 | return 0; |
||
106 | default: |
||
107 | $output->writeln("<error>Invalid gateway $gatewayName</error>"); |
||
108 | return; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | private function configureSignal(InputInterface $input, OutputInterface $output) { |
||
122 | } |
||
123 | |||
124 | private function configureSms(InputInterface $input, OutputInterface $output) { |
||
125 | $helper = $this->getHelper('question'); |
||
126 | |||
127 | $providerQuestion = new Question('Please choose a SMS provider (sipgate, websms, playsms, clockworksms, puzzelsms, ecallsms, voipms, voipbuster, huawei_e3531, spryng, sms77io, ovh, clickatellcentral, clickatellportal, clicksend, serwersms, smsglobal, smsapi.com): ', 'websms'); |
||
128 | $provider = $helper->ask($input, $output, $providerQuestion); |
||
129 | |||
130 | /** @var SMSConfig $config */ |
||
131 | $config = $this->smsGateway->getConfig(); |
||
132 | switch ($provider) { |
||
133 | case 'websms': |
||
134 | $config->setProvider($provider); |
||
135 | /** @var WebSmsConfig $providerConfig */ |
||
136 | $providerConfig = $config->getProvider()->getConfig(); |
||
137 | |||
138 | $usernameQuestion = new Question('Please enter your websms.de username: '); |
||
139 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
140 | $passwordQuestion = new Question('Please enter your websms.de password: '); |
||
141 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
142 | |||
143 | $providerConfig->setUser($username); |
||
144 | $providerConfig->setPassword($password); |
||
145 | break; |
||
146 | |||
147 | case 'sipgate': |
||
148 | $config->setProvider($provider); |
||
149 | /** @var SipGateConfig $providerConfig */ |
||
150 | $providerConfig = $config->getProvider()->getConfig(); |
||
151 | |||
152 | $tokenIdQuestion = new Question('Please enter your sipgate token-id: '); |
||
153 | $tokenId = $helper->ask($input, $output, $tokenIdQuestion); |
||
154 | $accessTokenQuestion = new Question('Please enter your sipgate access token: '); |
||
155 | $accessToken = $helper->ask($input, $output, $accessTokenQuestion); |
||
156 | $webSmsExtensionQuestion = new Question('Please enter your sipgate web-sms extension: '); |
||
157 | $webSmsExtension = $helper->ask($input, $output, $webSmsExtensionQuestion); |
||
158 | |||
159 | $providerConfig->setTokenId($tokenId); |
||
160 | $providerConfig->setAccessToken($accessToken); |
||
161 | $providerConfig->setWebSmsExtension($webSmsExtension); |
||
162 | break; |
||
163 | |||
164 | case 'playsms': |
||
165 | $config->setProvider($provider); |
||
166 | /** @var PlaySMSConfig $providerConfig */ |
||
167 | $providerConfig = $config->getProvider()->getConfig(); |
||
168 | |||
169 | $urlQuestion = new Question('Please enter your PlaySMS URL: '); |
||
170 | $url = $helper->ask($input, $output, $urlQuestion); |
||
171 | $usernameQuestion = new Question('Please enter your PlaySMS username: '); |
||
172 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
173 | $passwordQuestion = new Question('Please enter your PlaySMS password: '); |
||
174 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
175 | |||
176 | $providerConfig->setUrl($url); |
||
177 | $providerConfig->setUser($username); |
||
178 | $providerConfig->setPassword($password); |
||
179 | break; |
||
180 | |||
181 | case 'clockworksms': |
||
182 | $config->setProvider($provider); |
||
183 | /** @var ClockworkSMSConfig $providerConfig */ |
||
184 | $providerConfig = $config->getProvider()->getConfig(); |
||
185 | |||
186 | $apitokenQuestion = new Question('Please enter your clockworksms api token: '); |
||
187 | $apitoken = $helper->ask($input, $output, $apitokenQuestion); |
||
188 | |||
189 | $providerConfig->setApiToken($apitoken); |
||
190 | break; |
||
191 | |||
192 | case 'puzzelsms': |
||
193 | $config->setProvider($provider); |
||
194 | |||
195 | /** @var PuzzelSMSConfig $providerConfig */ |
||
196 | $providerConfig = $config->getProvider()->getConfig(); |
||
197 | |||
198 | $urlQuestion = new Question('Please enter your PuzzelSMS URL: '); |
||
199 | $url = $helper->ask($input, $output, $urlQuestion); |
||
200 | |||
201 | $usernameQuestion = new Question('Please enter your PuzzelSMS username: '); |
||
202 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
203 | |||
204 | $passwordQuestion = new Question('Please enter your PuzzelSMS password: '); |
||
205 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
206 | |||
207 | $serviceQuestion = new Question('Please enter your PuzzelSMS service ID: '); |
||
208 | $serviceId = $helper->ask($input, $output, $serviceQuestion); |
||
209 | |||
210 | $providerConfig->setUrl($url); |
||
211 | $providerConfig->setUser($username); |
||
212 | $providerConfig->setPassword($password); |
||
213 | $providerConfig->setServiceId($serviceId); |
||
214 | break; |
||
215 | |||
216 | case 'ecallsms': |
||
217 | $config->setProvider($provider); |
||
218 | /** @var EcallSMSConfig $providerConfig */ |
||
219 | $providerConfig = $config->getProvider()->getConfig(); |
||
220 | |||
221 | $usernameQuestion = new Question('Please enter your eCall.ch username: '); |
||
222 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
223 | $passwordQuestion = new Question('Please enter your eCall.ch password: '); |
||
224 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
225 | $senderIdQuestion = new Question('Please enter your eCall.ch sender ID: '); |
||
226 | $senderId = $helper->ask($input, $output, $senderIdQuestion); |
||
227 | |||
228 | $providerConfig->setUser($username); |
||
229 | $providerConfig->setPassword($password); |
||
230 | $providerConfig->setSenderId($senderId); |
||
231 | break; |
||
232 | |||
233 | case 'voipms': |
||
234 | $config->setProvider($provider); |
||
235 | |||
236 | /** @var VoipMsConfig $providerConfig */ |
||
237 | $providerConfig = $config->getProvider()->getConfig(); |
||
238 | |||
239 | $usernameQuestion = new Question('Please enter your VoIP.ms API username: '); |
||
240 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
241 | |||
242 | $passwordQuestion = new Question('Please enter your VoIP.ms API password: '); |
||
243 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
244 | |||
245 | $didQuestion = new Question('Please enter your VoIP.ms DID: '); |
||
246 | $did = $helper->ask($input, $output, $didQuestion); |
||
247 | |||
248 | $providerConfig->setUser($username); |
||
249 | $providerConfig->setPassword($password); |
||
250 | $providerConfig->setDid($did); |
||
251 | break; |
||
252 | |||
253 | case 'voipbuster': |
||
254 | $config->setProvider($provider); |
||
255 | |||
256 | /** @var VoipbusterConfig $providerConfig */ |
||
257 | $providerConfig = $config->getProvider()->getConfig(); |
||
258 | |||
259 | $usernameQuestion = new Question('Please enter your Voipbuster API username: '); |
||
260 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
261 | |||
262 | $passwordQuestion = new Question('Please enter your Voipbuster API password: '); |
||
263 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
264 | |||
265 | $didQuestion = new Question('Please enter your Voipbuster DID: '); |
||
266 | $did = $helper->ask($input, $output, $didQuestion); |
||
267 | |||
268 | $providerConfig->setUser($username); |
||
269 | $providerConfig->setPassword($password); |
||
270 | $providerConfig->setDid($did); |
||
271 | break; |
||
272 | |||
273 | case 'huawei_e3531': |
||
274 | $config->setProvider($provider); |
||
275 | /** @var HuaweiE3531Config $providerConfig */ |
||
276 | $providerConfig = $config->getProvider()->getConfig(); |
||
277 | |||
278 | $urlQuestion = new Question('Please enter the base URL of the Huawei E3531 stick: ', 'http://192.168.8.1/api'); |
||
279 | $url = $helper->ask($input, $output, $urlQuestion); |
||
280 | |||
281 | $providerConfig->setUrl($url); |
||
282 | break; |
||
283 | |||
284 | case 'spryng': |
||
285 | $config->setProvider($provider); |
||
286 | /** @var SpryngSMSConfig $providerConfig */ |
||
287 | $providerConfig = $config->getProvider()->getConfig(); |
||
288 | |||
289 | $apitokenQuestion = new Question('Please enter your Spryng api token: '); |
||
290 | $apitoken = $helper->ask($input, $output, $apitokenQuestion); |
||
291 | |||
292 | $providerConfig->setApiToken($apitoken); |
||
293 | break; |
||
294 | |||
295 | case 'sms77io': |
||
296 | $config->setProvider($provider); |
||
297 | /** @var Sms77IoConfig $providerConfig */ |
||
298 | $providerConfig = $config->getProvider()->getConfig(); |
||
299 | |||
300 | $apiKeyQuestion = new Question('Please enter your sms77.io API key: '); |
||
301 | $apiKey = $helper->ask($input, $output, $apiKeyQuestion); |
||
302 | |||
303 | $providerConfig->setApiKey($apiKey); |
||
304 | break; |
||
305 | |||
306 | case 'ovh': |
||
307 | $config->setProvider($provider); |
||
308 | |||
309 | /** @var OvhConfig $providerConfig */ |
||
310 | $providerConfig = $config->getProvider()->getConfig(); |
||
311 | |||
312 | $endpointQ = new Question('Please enter the endpoint to use (ovh-eu, ovh-us, ovh-ca, soyoustart-eu, soyoustart-ca, kimsufi-eu, kimsufi-ca, runabove-ca): '); |
||
313 | $endpoint = $helper->ask($input, $output, $endpointQ); |
||
314 | |||
315 | $appKeyQ = new Question('Please enter your application key: '); |
||
316 | $appKey = $helper->ask($input, $output, $appKeyQ); |
||
317 | |||
318 | $appSecretQ = new Question('Please enter your application secret: '); |
||
319 | $appSecret = $helper->ask($input, $output, $appSecretQ); |
||
320 | |||
321 | $consumerKeyQ = new Question('Please enter your consumer key: '); |
||
322 | $consumerKey = $helper->ask($input, $output, $consumerKeyQ); |
||
323 | |||
324 | $accountQ = new Question('Please enter your account (sms-*****): '); |
||
325 | $account = $helper->ask($input, $output, $accountQ); |
||
326 | |||
327 | $senderQ = new Question('Please enter your sender: '); |
||
328 | $sender = $helper->ask($input, $output, $senderQ); |
||
329 | |||
330 | $providerConfig->setApplicationKey($appKey); |
||
331 | $providerConfig->setApplicationSecret($appSecret); |
||
332 | $providerConfig->setConsumerKey($consumerKey); |
||
333 | $providerConfig->setEndpoint($endpoint); |
||
334 | $providerConfig->setAccount($account); |
||
335 | $providerConfig->setSender($sender); |
||
336 | break; |
||
337 | |||
338 | case 'clickatellcentral': |
||
339 | $config->setProvider($provider); |
||
340 | /** @var ClickatellCentralConfig $providerConfig */ |
||
341 | $providerConfig = $config->getProvider()->getConfig(); |
||
342 | |||
343 | $apiQuestion = new Question('Please enter your central.clickatell.com API-ID: '); |
||
344 | $api = $helper->ask($input, $output, $apiQuestion); |
||
345 | $usernameQuestion = new Question('Please enter your central.clickatell.com username: '); |
||
346 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
347 | $passwordQuestion = new Question('Please enter your central.clickatell.com password: '); |
||
348 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
349 | |||
350 | $providerConfig->setApi($api); |
||
351 | $providerConfig->setUser($username); |
||
352 | $providerConfig->setPassword($password); |
||
353 | break; |
||
354 | |||
355 | case 'clickatellportal': |
||
356 | $config->setProvider($provider); |
||
357 | /** @var ClickatellPortalConfig $providerConfig */ |
||
358 | $providerConfig = $config->getProvider()->getConfig(); |
||
359 | |||
360 | $apiQuestion = new Question('Please enter your portal.clickatell.com API-Key: '); |
||
361 | $apiKey = $helper->ask($input, $output, $apiQuestion); |
||
362 | $fromQuestion = new Question('Please enter your sender number for two-way messaging. Leave it empty for one-way messaging: '); |
||
363 | $fromNumber = $helper->ask($input, $output, $fromQuestion); |
||
364 | |||
365 | $providerConfig->setApiKey($apiKey); |
||
366 | |||
367 | if (empty($fromNumber)) { |
||
368 | $providerConfig->deleteFromNumber(); |
||
369 | } else { |
||
370 | $providerConfig->setFromNumber($fromNumber); |
||
371 | } |
||
372 | break; |
||
373 | |||
374 | case 'clicksend': |
||
375 | $config->setProvider($provider); |
||
376 | /** @var ClickSendConfig $providerConfig */ |
||
377 | $providerConfig = $config->getProvider()->getConfig(); |
||
378 | |||
379 | $usernameQuestion = new Question('Please enter your clicksend.com username: '); |
||
380 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
381 | $apiKeyQuestion = new Question('Please enter your clicksend.com API Key (or, if subuser, the password): '); |
||
382 | $apiKey = $helper->ask($input, $output, $apiKeyQuestion); |
||
383 | |||
384 | $providerConfig->setUser($username); |
||
385 | $providerConfig->setApiKey($apiKey); |
||
386 | break; |
||
387 | |||
388 | case 'smsglobal': |
||
389 | $config->setProvider($provider); |
||
390 | /** @var SMSGlobalConfig $providerConfig */ |
||
391 | $providerConfig = $config->getProvider()->getConfig(); |
||
392 | |||
393 | $urlproposal = 'https://api.smsglobal.com/http-api.php'; |
||
394 | $urlQuestion = new Question('Please enter your SMSGlobal http-api:', $urlproposal); |
||
395 | $url = $helper->ask($input, $output, $urlQuestion); |
||
396 | $usernameQuestion = new Question('Please enter your SMSGlobal username (for http-api):'); |
||
397 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
398 | $passwordQuestion = new Question('Please enter your SMSGlobal password: (for http-api):'); |
||
399 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
400 | |||
401 | $providerConfig->setUrl($url); |
||
402 | $providerConfig->setUser($username); |
||
403 | $providerConfig->setPassword($password); |
||
404 | break; |
||
405 | |||
406 | case 'serwersms': |
||
407 | $config->setProvider($provider); |
||
408 | /** @var SerwerSMSConfig $providerConfig */ |
||
409 | $providerConfig = $config->getProvider()->getConfig(); |
||
410 | |||
411 | $loginQuestion = new Question('Please enter your SerwerSMS.pl API login: '); |
||
412 | $login = $helper->ask($input, $output, $loginQuestion); |
||
413 | $passwordQuestion = new Question('Please enter your SerwerSMS.pl API password: '); |
||
414 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
415 | $senderQuestion = new Question('Please enter your SerwerSMS.pl sender name: '); |
||
416 | $sender = $helper->ask($input, $output, $senderQuestion); |
||
417 | |||
418 | $providerConfig->setLogin($login); |
||
419 | $providerConfig->setPassword($password); |
||
420 | $providerConfig->setSender($sender); |
||
421 | break; |
||
422 | |||
423 | case 'smsapi.com': |
||
424 | $config->setProvider($provider); |
||
425 | /** @var SerwerSMSConfig $providerConfig */ |
||
426 | $providerConfig = $config->getProvider()->getConfig(); |
||
427 | |||
428 | $tokenQuestion = new Question('Please enter your SMSApi.com API token: '); |
||
429 | $token = $helper->ask($input, $output, $tokenQuestion); |
||
430 | $senderQuestion = new Question('Please enter your SMSApi.com sender name: '); |
||
431 | $sender = $helper->ask($input, $output, $senderQuestion); |
||
432 | |||
433 | $providerConfig->setToken($token); |
||
434 | $providerConfig->setSender($sender); |
||
435 | break; |
||
436 | |||
437 | default: |
||
438 | $output->writeln("Invalid provider $provider"); |
||
439 | break; |
||
440 | } |
||
441 | return 0; |
||
442 | } |
||
443 | |||
444 | private function configureTelegram(InputInterface $input, OutputInterface $output) { |
||
445 | $helper = $this->getHelper('question'); |
||
446 | $tokenQuestion = new Question('Please enter your Telegram bot token: '); |
||
447 | $token = $helper->ask($input, $output, $tokenQuestion); |
||
448 | $output->writeln("Using $token."); |
||
449 | |||
450 | /** @var TelegramConfig $config */ |
||
451 | $config = $this->telegramGateway->getConfig(); |
||
452 | |||
453 | $config->setBotToken($token); |
||
454 | } |
||
455 | |||
456 | private function configureXMPP(InputInterface $input, OutputInterface $output) { |
||
512 | } |
||
513 | } |
||
514 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths