| Conditions | 6 |
| Paths | 10 |
| Total Lines | 81 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 10 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 33 | public function load(array $config, ContainerBuilder $container) |
||
| 34 | { |
||
| 35 | $processor = new Processor(); |
||
| 36 | $config = $processor->processConfiguration(new Configuration(), $config); |
||
| 37 | |||
| 38 | $container->setParameter('logging.application_name', $config['logging']['application_name']); |
||
| 39 | |||
| 40 | $loader = new YamlFileLoader( |
||
| 41 | $container, |
||
| 42 | new FileLocator(__DIR__ . '/../Resources/config') |
||
| 43 | ); |
||
| 44 | $loader->load('services.yml'); |
||
| 45 | |||
| 46 | if (isset($config['loa_definition'])) { |
||
| 47 | $this->defineLoas($config['loa_definition'], $container); |
||
| 48 | } else { |
||
| 49 | $container->removeDefinition('surfnet_stepup.service.loa_resolution'); |
||
| 50 | } |
||
| 51 | |||
| 52 | if ($config['sms']['enabled'] === false) { |
||
| 53 | $container->removeDefinition('surfnet_stepup.service.sms_second_factor'); |
||
| 54 | $container->removeDefinition('surfnet_stepup.service.challenge_handler'); |
||
| 55 | $container->removeDefinition('surfnet_stepup.service.sms_second_factor'); |
||
| 56 | } else { |
||
| 57 | $smsSecondFactorService = $container->getDefinition('surfnet_stepup.service.sms_second_factor'); |
||
| 58 | $smsSecondFactorService->replaceArgument(2, $config['sms']['originator']); |
||
| 59 | |||
| 60 | $container |
||
| 61 | ->getDefinition('surfnet_stepup.service.challenge_handler') |
||
| 62 | ->replaceArgument(2, $config['sms']['otp_expiry_interval']) |
||
| 63 | ->replaceArgument(3, $config['sms']['maximum_otp_requests']); |
||
| 64 | |||
| 65 | $container |
||
| 66 | ->getDefinition('surfnet_stepup.service.sms_second_factor') |
||
| 67 | ->replaceArgument(0, new Reference($config['sms']['service'])); |
||
| 68 | |||
| 69 | if (!$config['gateway_api']['enabled'] && $config['sms']['service'] === Configuration::DEFAULT_SMS_SERVICE) { |
||
|
|
|||
| 70 | throw new RuntimeException('The gateway API is not enabled and no replacement SMS service is configured'); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($config['gateway_api']['enabled']) { |
||
| 75 | # Configure the Gateway API SMS service's Guzzle client. |
||
| 76 | $gatewayGuzzleOptions = [ |
||
| 77 | 'base_url' => $config['gateway_api']['url'], |
||
| 78 | 'defaults' => [ |
||
| 79 | 'auth' => [ |
||
| 80 | $config['gateway_api']['credentials']['username'], |
||
| 81 | $config['gateway_api']['credentials']['password'], |
||
| 82 | 'basic' |
||
| 83 | ], |
||
| 84 | 'headers' => [ |
||
| 85 | 'Accept' => 'application/json' |
||
| 86 | ] |
||
| 87 | ] |
||
| 88 | ]; |
||
| 89 | |||
| 90 | $gatewayGuzzle = $container->getDefinition('surfnet_stepup.guzzle.gateway_api'); |
||
| 91 | $gatewayGuzzle->replaceArgument(0, $gatewayGuzzleOptions); |
||
| 92 | } else { |
||
| 93 | # Remove the Gateway API SMS service and its Guzzle client. |
||
| 94 | $container->removeDefinition('surfnet_stepup.service.gateway_api_sms'); |
||
| 95 | $container->removeDefinition('surfnet_stepup.guzzle.gateway_api'); |
||
| 96 | } |
||
| 97 | |||
| 98 | $container->getDefinition('surfnet_stepup.locale_cookie_settings') |
||
| 99 | ->setArguments( |
||
| 100 | [ |
||
| 101 | $config['locale_cookie']['name'], |
||
| 102 | null, |
||
| 103 | $config['locale_cookie']['expire'], |
||
| 104 | $config['locale_cookie']['path'], |
||
| 105 | $config['locale_cookie']['domain'], |
||
| 106 | $config['locale_cookie']['secure'], |
||
| 107 | $config['locale_cookie']['http_only'], |
||
| 108 | ] |
||
| 109 | ); |
||
| 110 | |||
| 111 | $container->getDefinition('surfnet_stepup.form.choice_list.locales') |
||
| 112 | ->replaceArgument(0, $container->getParameter('locales')); |
||
| 113 | } |
||
| 114 | |||
| 126 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.