| Conditions | 6 |
| Paths | 10 |
| Total Lines | 68 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| 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 |
||
| 34 | public function load(array $config, ContainerBuilder $container) |
||
| 35 | { |
||
| 36 | $processor = new Processor(); |
||
| 37 | $config = $processor->processConfiguration(new Configuration(), $config); |
||
| 38 | |||
| 39 | $container->setParameter('logging.application_name', $config['logging']['application_name']); |
||
| 40 | |||
| 41 | $loader = new YamlFileLoader( |
||
| 42 | $container, |
||
| 43 | new FileLocator(__DIR__ . '/../Resources/config') |
||
| 44 | ); |
||
| 45 | $loader->load('services.yml'); |
||
| 46 | |||
| 47 | if (isset($config['loa_definition'])) { |
||
| 48 | $this->defineLoas($config['loa_definition'], $container); |
||
| 49 | } else { |
||
| 50 | $container->removeDefinition('surfnet_stepup.service.loa_resolution'); |
||
| 51 | } |
||
| 52 | |||
| 53 | if ($config['sms']['enabled'] === false) { |
||
| 54 | $container->removeDefinition('surfnet_stepup.service.sms_second_factor'); |
||
| 55 | $container->removeDefinition('surfnet_stepup.service.challenge_handler'); |
||
| 56 | $container->removeDefinition('surfnet_stepup.service.sms_second_factor'); |
||
| 57 | } else { |
||
| 58 | $smsSecondFactorService = $container->getDefinition('surfnet_stepup.service.sms_second_factor'); |
||
| 59 | $smsSecondFactorService->replaceArgument(2, $config['sms']['originator']); |
||
| 60 | |||
| 61 | $container |
||
| 62 | ->getDefinition('surfnet_stepup.service.challenge_handler') |
||
| 63 | ->replaceArgument(2, $config['sms']['otp_expiry_interval']) |
||
| 64 | ->replaceArgument(3, $config['sms']['maximum_otp_requests']); |
||
| 65 | |||
| 66 | $container |
||
| 67 | ->getDefinition('surfnet_stepup.service.sms_second_factor') |
||
| 68 | ->replaceArgument(0, new Reference($config['sms']['service'])); |
||
| 69 | |||
| 70 | if (!$config['gateway_api']['enabled'] && $config['sms']['service'] === Configuration::DEFAULT_SMS_SERVICE) { |
||
|
|
|||
| 71 | throw new RuntimeException('The gateway API is not enabled and no replacement SMS service is configured'); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($config['gateway_api']['enabled']) { |
||
| 76 | # Configure the Gateway API SMS service's Guzzle client. |
||
| 77 | $gatewayGuzzleOptions = [ |
||
| 78 | 'base_url' => $config['gateway_api']['url'], |
||
| 79 | 'defaults' => [ |
||
| 80 | 'auth' => [ |
||
| 81 | $config['gateway_api']['credentials']['username'], |
||
| 82 | $config['gateway_api']['credentials']['password'], |
||
| 83 | 'basic' |
||
| 84 | ], |
||
| 85 | 'headers' => [ |
||
| 86 | 'Accept' => 'application/json' |
||
| 87 | ] |
||
| 88 | ] |
||
| 89 | ]; |
||
| 90 | |||
| 91 | $gatewayGuzzle = $container->getDefinition('surfnet_stepup.guzzle.gateway_api'); |
||
| 92 | $gatewayGuzzle->replaceArgument(0, $gatewayGuzzleOptions); |
||
| 93 | } else { |
||
| 94 | # Remove the Gateway API SMS service and its Guzzle client. |
||
| 95 | $container->removeDefinition('surfnet_stepup.service.gateway_api_sms'); |
||
| 96 | $container->removeDefinition('surfnet_stepup.guzzle.gateway_api'); |
||
| 97 | } |
||
| 98 | |||
| 99 | $container->getDefinition('surfnet_stepup.form.choice_list.locales') |
||
| 100 | ->replaceArgument(0, $container->getParameter('locales')); |
||
| 101 | } |
||
| 102 | |||
| 153 |
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.