| Conditions | 19 |
| Paths | 19 |
| Total Lines | 304 |
| Code Lines | 213 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 2 | Features | 1 |
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 |
||
| 114 | private function configureSms(InputInterface $input, OutputInterface $output) { |
||
| 115 | $helper = $this->getHelper('question'); |
||
| 116 | |||
| 117 | $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): ', 'websms'); |
||
| 118 | $provider = $helper->ask($input, $output, $providerQuestion); |
||
| 119 | |||
| 120 | /** @var SMSConfig $config */ |
||
| 121 | $config = $this->smsGateway->getConfig(); |
||
| 122 | switch ($provider) { |
||
| 123 | case 'websms': |
||
| 124 | $config->setProvider($provider); |
||
| 125 | /** @var WebSmsConfig $providerConfig */ |
||
| 126 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 127 | |||
| 128 | $usernameQuestion = new Question('Please enter your websms.de username: '); |
||
| 129 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
| 130 | $passwordQuestion = new Question('Please enter your websms.de password: '); |
||
| 131 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
| 132 | |||
| 133 | $providerConfig->setUser($username); |
||
| 134 | $providerConfig->setPassword($password); |
||
| 135 | break; |
||
| 136 | |||
| 137 | case 'sipgate': |
||
| 138 | $config->setProvider($provider); |
||
| 139 | /** @var SipGateConfig $providerConfig */ |
||
| 140 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 141 | |||
| 142 | $tokenIdQuestion = new Question('Please enter your sipgate token-id: '); |
||
| 143 | $tokenId = $helper->ask($input, $output, $tokenIdQuestion); |
||
| 144 | $accessTokenQuestion = new Question('Please enter your sipgate access token: '); |
||
| 145 | $accessToken = $helper->ask($input, $output, $accessTokenQuestion); |
||
| 146 | $webSmsExtensionQuestion = new Question('Please enter your sipgate web-sms extension: '); |
||
| 147 | $webSmsExtension = $helper->ask($input, $output, $webSmsExtensionQuestion); |
||
| 148 | |||
| 149 | $providerConfig->setTokenId($tokenId); |
||
| 150 | $providerConfig->setAccessToken($accessToken); |
||
| 151 | $providerConfig->setWebSmsExtension($webSmsExtension); |
||
| 152 | break; |
||
| 153 | |||
| 154 | case 'playsms': |
||
| 155 | $config->setProvider($provider); |
||
| 156 | /** @var PlaySMSConfig $providerConfig */ |
||
| 157 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 158 | |||
| 159 | $urlQuestion = new Question('Please enter your PlaySMS URL: '); |
||
| 160 | $url = $helper->ask($input, $output, $urlQuestion); |
||
| 161 | $usernameQuestion = new Question('Please enter your PlaySMS username: '); |
||
| 162 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
| 163 | $passwordQuestion = new Question('Please enter your PlaySMS password: '); |
||
| 164 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
| 165 | |||
| 166 | $providerConfig->setUrl($url); |
||
| 167 | $providerConfig->setUser($username); |
||
| 168 | $providerConfig->setPassword($password); |
||
| 169 | break; |
||
| 170 | |||
| 171 | case 'clockworksms': |
||
| 172 | $config->setProvider($provider); |
||
| 173 | /** @var ClockworkSMSConfig $providerConfig */ |
||
| 174 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 175 | |||
| 176 | $apitokenQuestion = new Question('Please enter your clockworksms api token: '); |
||
| 177 | $apitoken = $helper->ask($input, $output, $apitokenQuestion); |
||
| 178 | |||
| 179 | $providerConfig->setApiToken($apitoken); |
||
| 180 | break; |
||
| 181 | |||
| 182 | case 'puzzelsms': |
||
| 183 | $config->setProvider($provider); |
||
| 184 | |||
| 185 | /** @var PuzzelSMSConfig $providerConfig */ |
||
| 186 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 187 | |||
| 188 | $urlQuestion = new Question('Please enter your PuzzelSMS URL: '); |
||
| 189 | $url = $helper->ask($input, $output, $urlQuestion); |
||
| 190 | |||
| 191 | $usernameQuestion = new Question('Please enter your PuzzelSMS username: '); |
||
| 192 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
| 193 | |||
| 194 | $passwordQuestion = new Question('Please enter your PuzzelSMS password: '); |
||
| 195 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
| 196 | |||
| 197 | $serviceQuestion = new Question('Please enter your PuzzelSMS service ID: '); |
||
| 198 | $serviceId = $helper->ask($input, $output, $serviceQuestion); |
||
| 199 | |||
| 200 | $providerConfig->setUrl($url); |
||
| 201 | $providerConfig->setUser($username); |
||
| 202 | $providerConfig->setPassword($password); |
||
| 203 | $providerConfig->setServiceId($serviceId); |
||
| 204 | break; |
||
| 205 | |||
| 206 | case 'ecallsms': |
||
| 207 | $config->setProvider($provider); |
||
| 208 | /** @var EcallSMSConfig $providerConfig */ |
||
| 209 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 210 | |||
| 211 | $usernameQuestion = new Question('Please enter your eCall.ch username: '); |
||
| 212 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
| 213 | $passwordQuestion = new Question('Please enter your eCall.ch password: '); |
||
| 214 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
| 215 | $senderIdQuestion = new Question('Please enter your eCall.ch sender ID: '); |
||
| 216 | $senderId = $helper->ask($input, $output, $senderIdQuestion); |
||
| 217 | |||
| 218 | $providerConfig->setUser($username); |
||
| 219 | $providerConfig->setPassword($password); |
||
| 220 | $providerConfig->setSenderId($senderId); |
||
| 221 | break; |
||
| 222 | |||
| 223 | case 'voipms': |
||
| 224 | $config->setProvider($provider); |
||
| 225 | |||
| 226 | /** @var VoipMsConfig $providerConfig */ |
||
| 227 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 228 | |||
| 229 | $usernameQuestion = new Question('Please enter your VoIP.ms API username: '); |
||
| 230 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
| 231 | |||
| 232 | $passwordQuestion = new Question('Please enter your VoIP.ms API password: '); |
||
| 233 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
| 234 | |||
| 235 | $didQuestion = new Question('Please enter your VoIP.ms DID: '); |
||
| 236 | $did = $helper->ask($input, $output, $didQuestion); |
||
| 237 | |||
| 238 | $providerConfig->setUser($username); |
||
| 239 | $providerConfig->setPassword($password); |
||
| 240 | $providerConfig->setDid($did); |
||
| 241 | break; |
||
| 242 | |||
| 243 | case 'voipbuster': |
||
| 244 | $config->setProvider($provider); |
||
| 245 | |||
| 246 | /** @var VoipbusterConfig $providerConfig */ |
||
| 247 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 248 | |||
| 249 | $usernameQuestion = new Question('Please enter your Voipbuster API username: '); |
||
| 250 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
| 251 | |||
| 252 | $passwordQuestion = new Question('Please enter your Voipbuster API password: '); |
||
| 253 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
| 254 | |||
| 255 | $didQuestion = new Question('Please enter your Voipbuster DID: '); |
||
| 256 | $did = $helper->ask($input, $output, $didQuestion); |
||
| 257 | |||
| 258 | $providerConfig->setUser($username); |
||
| 259 | $providerConfig->setPassword($password); |
||
| 260 | $providerConfig->setDid($did); |
||
| 261 | break; |
||
| 262 | |||
| 263 | case 'huawei_e3531': |
||
| 264 | $config->setProvider($provider); |
||
| 265 | /** @var HuaweiE3531Config $providerConfig */ |
||
| 266 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 267 | |||
| 268 | $urlQuestion = new Question('Please enter the base URL of the Huawei E3531 stick: ', 'http://192.168.8.1/api'); |
||
| 269 | $url = $helper->ask($input, $output, $urlQuestion); |
||
| 270 | |||
| 271 | $providerConfig->setUrl($url); |
||
| 272 | break; |
||
| 273 | |||
| 274 | case 'spryng': |
||
| 275 | $config->setProvider($provider); |
||
| 276 | /** @var SpryngSMSConfig $providerConfig */ |
||
| 277 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 278 | |||
| 279 | $apitokenQuestion = new Question('Please enter your Spryng api token: '); |
||
| 280 | $apitoken = $helper->ask($input, $output, $apitokenQuestion); |
||
| 281 | |||
| 282 | $providerConfig->setApiToken($apitoken); |
||
| 283 | break; |
||
| 284 | |||
| 285 | case 'sms77io': |
||
| 286 | $config->setProvider($provider); |
||
| 287 | /** @var Sms77IoConfig $providerConfig */ |
||
| 288 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 289 | |||
| 290 | $apiKeyQuestion = new Question('Please enter your sms77.io API key: '); |
||
| 291 | $apiKey = $helper->ask($input, $output, $apiKeyQuestion); |
||
| 292 | |||
| 293 | $providerConfig->setApiKey($apiKey); |
||
| 294 | break; |
||
| 295 | |||
| 296 | case 'ovh': |
||
| 297 | $config->setProvider($provider); |
||
| 298 | |||
| 299 | /** @var OvhConfig $providerConfig */ |
||
| 300 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 301 | |||
| 302 | $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): '); |
||
| 303 | $endpoint = $helper->ask($input, $output, $endpointQ); |
||
| 304 | |||
| 305 | $appKeyQ = new Question('Please enter your application key: '); |
||
| 306 | $appKey = $helper->ask($input, $output, $appKeyQ); |
||
| 307 | |||
| 308 | $appSecretQ = new Question('Please enter your application secret: '); |
||
| 309 | $appSecret = $helper->ask($input, $output, $appSecretQ); |
||
| 310 | |||
| 311 | $consumerKeyQ = new Question('Please enter your consumer key: '); |
||
| 312 | $consumerKey = $helper->ask($input, $output, $consumerKeyQ); |
||
| 313 | |||
| 314 | $accountQ = new Question('Please enter your account (sms-*****): '); |
||
| 315 | $account = $helper->ask($input, $output, $accountQ); |
||
| 316 | |||
| 317 | $senderQ = new Question('Please enter your sender: '); |
||
| 318 | $sender = $helper->ask($input, $output, $senderQ); |
||
| 319 | |||
| 320 | $providerConfig->setApplicationKey($appKey); |
||
| 321 | $providerConfig->setApplicationSecret($appSecret); |
||
| 322 | $providerConfig->setConsumerKey($consumerKey); |
||
| 323 | $providerConfig->setEndpoint($endpoint); |
||
| 324 | $providerConfig->setAccount($account); |
||
| 325 | $providerConfig->setSender($sender); |
||
| 326 | break; |
||
| 327 | |||
| 328 | case 'clickatellcentral': |
||
| 329 | $config->setProvider($provider); |
||
| 330 | /** @var ClickatellCentralConfig $providerConfig */ |
||
| 331 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 332 | |||
| 333 | $apiQuestion = new Question('Please enter your central.clickatell.com API-ID: '); |
||
| 334 | $api = $helper->ask($input, $output, $apiQuestion); |
||
| 335 | $usernameQuestion = new Question('Please enter your central.clickatell.com username: '); |
||
| 336 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
| 337 | $passwordQuestion = new Question('Please enter your central.clickatell.com password: '); |
||
| 338 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
| 339 | |||
| 340 | $providerConfig->setApi($api); |
||
| 341 | $providerConfig->setUser($username); |
||
| 342 | $providerConfig->setPassword($password); |
||
| 343 | break; |
||
| 344 | |||
| 345 | case 'clickatellportal': |
||
| 346 | $config->setProvider($provider); |
||
| 347 | /** @var ClickatellPortalConfig $providerConfig */ |
||
| 348 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 349 | |||
| 350 | $apiQuestion = new Question('Please enter your portal.clickatell.com API-Key: '); |
||
| 351 | $apiKey = $helper->ask($input, $output, $apiQuestion); |
||
| 352 | $fromQuestion = new Question('Please enter your sender number for two-way messaging. Leave it empty for one-way messaging: '); |
||
| 353 | $fromNumber = $helper->ask($input, $output, $fromQuestion); |
||
| 354 | |||
| 355 | $providerConfig->setApiKey($apiKey); |
||
| 356 | |||
| 357 | if (empty($fromNumber)) { |
||
| 358 | $providerConfig->deleteFromNumber(); |
||
| 359 | } else { |
||
| 360 | $providerConfig->setFromNumber($fromNumber); |
||
| 361 | } |
||
| 362 | break; |
||
| 363 | |||
| 364 | case 'clicksend': |
||
| 365 | $config->setProvider($provider); |
||
| 366 | /** @var ClickSendConfig $providerConfig */ |
||
| 367 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 368 | |||
| 369 | $usernameQuestion = new Question('Please enter your clicksend.com username: '); |
||
| 370 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
| 371 | $apiKeyQuestion = new Question('Please enter your clicksend.com API Key (or, if subuser, the password): '); |
||
| 372 | $apiKey = $helper->ask($input, $output, $apiKeyQuestion); |
||
| 373 | |||
| 374 | $providerConfig->setUser($username); |
||
| 375 | $providerConfig->setApiKey($apiKey); |
||
| 376 | break; |
||
| 377 | |||
| 378 | case 'smsglobal': |
||
| 379 | $config->setProvider($provider); |
||
| 380 | /** @var SMSGlobalConfig $providerConfig */ |
||
| 381 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 382 | |||
| 383 | $urlproposal = 'https://api.smsglobal.com/http-api.php'; |
||
| 384 | $urlQuestion = new Question('Please enter your SMSGlobal http-api:', $urlproposal); |
||
| 385 | $url = $helper->ask($input, $output, $urlQuestion); |
||
| 386 | $usernameQuestion = new Question('Please enter your SMSGlobal username (for http-api):'); |
||
| 387 | $username = $helper->ask($input, $output, $usernameQuestion); |
||
| 388 | $passwordQuestion = new Question('Please enter your SMSGlobal password: (for http-api):'); |
||
| 389 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
| 390 | |||
| 391 | $providerConfig->setUrl($url); |
||
| 392 | $providerConfig->setUser($username); |
||
| 393 | $providerConfig->setPassword($password); |
||
| 394 | break; |
||
| 395 | |||
| 396 | case 'serwersms': |
||
| 397 | $config->setProvider($provider); |
||
| 398 | /** @var SerwerSMSConfig $providerConfig */ |
||
| 399 | $providerConfig = $config->getProvider()->getConfig(); |
||
| 400 | |||
| 401 | $loginQuestion = new Question('Please enter your SerwerSMS.pl API login: '); |
||
| 402 | $login = $helper->ask($input, $output, $loginQuestion); |
||
| 403 | $passwordQuestion = new Question('Please enter your SerwerSMS.pl API password: '); |
||
| 404 | $password = $helper->ask($input, $output, $passwordQuestion); |
||
| 405 | $senderQuestion = new Question('Please enter your SerwerSMS.pl sender name: '); |
||
| 406 | $sender = $helper->ask($input, $output, $senderQuestion); |
||
| 407 | |||
| 408 | $providerConfig->setLogin($login); |
||
| 409 | $providerConfig->setPassword($password); |
||
| 410 | $providerConfig->setSender($sender); |
||
| 411 | break; |
||
| 412 | |||
| 413 | default: |
||
| 414 | $output->writeln("Invalid provider $provider"); |
||
| 415 | break; |
||
| 416 | } |
||
| 417 | return 0; |
||
| 418 | } |
||
| 432 |