| Conditions | 5 |
| Paths | 5 |
| Total Lines | 51 |
| Code Lines | 33 |
| 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 |
||
| 115 | public function configure(ContainerBuilder $container, $alias) |
||
| 116 | { |
||
| 117 | $this->alias = $alias.'.oauth'; |
||
| 118 | $clientConfigurations = $container->getParameter($this->alias.'.clients'); |
||
| 119 | $clientServiceKeys = []; |
||
| 120 | /** @var $clientConfigurations array */ |
||
| 121 | foreach ($clientConfigurations as $key => $clientConfig) { |
||
| 122 | $tree = new TreeBuilder(); |
||
| 123 | $processor = new Processor(); |
||
| 124 | |||
| 125 | if (!isset($clientConfig['type'])) { |
||
| 126 | throw new InvalidConfigurationException(sprintf('Your "sludio_helper_oauth_client.clients.%s" config entry is missing the "type" key.', $key)); |
||
| 127 | } |
||
| 128 | |||
| 129 | $this->type = $clientConfig['type']; |
||
| 130 | unset($clientConfig['type']); |
||
| 131 | if (!isset(self::$supportedProviderTypes[$this->type])) { |
||
| 132 | $supportedKeys = array_keys(self::$supportedProviderTypes); |
||
| 133 | sort($supportedKeys); |
||
| 134 | throw new InvalidConfigurationException(sprintf('The "sludio_helper_oauth_client.clients" config "type" key "%s" is not supported. We support: %s', $this->type, implode(', ', $supportedKeys))); |
||
| 135 | } |
||
| 136 | |||
| 137 | $node = $tree->root('sludio_helper_oauth_client/clients/'.$key); |
||
| 138 | $this->buildClientConfiguration($node); |
||
| 139 | $config = $processor->process($tree->buildTree(), [$clientConfig]); |
||
| 140 | |||
| 141 | $configurator = $this->getConfigurator($this->type); |
||
| 142 | |||
| 143 | $options = [ |
||
| 144 | 'provider_class' => $configurator->getProviderClass($config), |
||
| 145 | 'client_class' => $configurator->getClientClass($config), |
||
| 146 | 'provider_options' => $configurator->getProviderOptions($config), |
||
| 147 | 'state' => $config['use_state'], |
||
| 148 | ]; |
||
| 149 | |||
| 150 | $clientServiceKey = $this->configureClient($container, $key, $options); |
||
| 151 | |||
| 152 | $service = [ |
||
| 153 | 'key' => $clientServiceKey, |
||
| 154 | ]; |
||
| 155 | if (isset($config['provider_options']['name'])) { |
||
| 156 | $service['name'] = $config['provider_options']['name']; |
||
| 157 | } else { |
||
| 158 | $service['name'] = ucfirst($key); |
||
| 159 | } |
||
| 160 | |||
| 161 | $clientServiceKeys[$key] = $service; |
||
| 162 | } |
||
| 163 | |||
| 164 | $container->getDefinition($this->alias.'.registry')->replaceArgument(0, $clientServiceKeys); |
||
| 165 | $container->getDefinition($alias.'.registry')->replaceArgument(0, $clientServiceKeys); |
||
| 166 | } |
||
| 188 |