| Conditions | 13 |
| Paths | 81 |
| Total Lines | 64 |
| Code Lines | 45 |
| 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 |
||
| 86 | public function configure(ContainerBuilder $container, $alias) |
||
| 87 | { |
||
| 88 | $this->alias = $alias.'.openidconnect'; |
||
| 89 | $clientConfigurations = $container->getParameter($this->alias.'.clients'); |
||
| 90 | $clientServiceKeys = []; |
||
| 91 | /** @var $clientConfigurations array */ |
||
| 92 | foreach ($clientConfigurations as $key => $clientConfig) { |
||
| 93 | $tree = new TreeBuilder(); |
||
| 94 | $processor = new Processor(); |
||
| 95 | $node = $tree->root('sludio_helper_openidconnect_client/clients/'.$key); |
||
| 96 | $this->buildClientConfiguration($node); |
||
| 97 | /** @var array $config */ |
||
| 98 | $config = $processor->process($tree->buildTree(), [$clientConfig]); |
||
| 99 | $clientServiceKey = $this->alias.'.client.'.$key; |
||
| 100 | $container->setParameter($clientServiceKey, $clientConfig); |
||
| 101 | $service = [ |
||
| 102 | 'key' => $clientServiceKey, |
||
| 103 | ]; |
||
| 104 | if (isset($config['options']['name'])) { |
||
| 105 | $service['name'] = $config['options']['name']; |
||
| 106 | } else { |
||
| 107 | $service['name'] = ucfirst($key); |
||
| 108 | } |
||
| 109 | |||
| 110 | $clientServiceKeys[$key] = $service; |
||
| 111 | foreach ($config as $configKey => $configValue) { |
||
| 112 | if ('options' === $configKey) { |
||
| 113 | if (\is_array($configValue)) { |
||
| 114 | foreach ($configValue as $parameterKey => $parameterValue) { |
||
| 115 | $container->setParameter($clientServiceKey.'.option.'.$parameterKey, $parameterValue); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | } else { |
||
| 119 | $container->setParameter($clientServiceKey.'.'.$configKey, $configValue); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | $uriConfigurations = $container->getParameter($this->alias.'.client.'.$key.'.uris'); |
||
| 123 | /** @var $uriConfigurations array */ |
||
| 124 | foreach ($uriConfigurations as $subKey => $uriConfig) { |
||
| 125 | $tree = new TreeBuilder(); |
||
| 126 | $processor = new Processor(); |
||
| 127 | $node = $tree->root('sludio_helper_openidconnect_client/clients/'.$key.'/uris/'.$subKey); |
||
| 128 | $this->buildUri($node); |
||
| 129 | $config = $processor->process($tree->buildTree(), [$uriConfig]); |
||
| 130 | $params = []; |
||
| 131 | foreach ($config as $subConfigKey => $subConfigValue) { |
||
| 132 | if ($subConfigKey === 'params') { |
||
| 133 | if (\is_array($subConfigValue)) { |
||
| 134 | foreach ($subConfigValue as $subParameterKey => $subParameterValue) { |
||
| 135 | $params[$subParameterKey] = $subParameterValue; |
||
| 136 | } |
||
| 137 | if (!empty($params)) { |
||
| 138 | $params['client_id'] = $container->getParameter($this->alias.'.client.'.$key.'.client_key'); |
||
| 139 | $container->setParameter($clientServiceKey.'.'.$subKey.'.'.$subConfigKey, $params); |
||
| 140 | } |
||
| 141 | } |
||
| 142 | } else { |
||
| 143 | $container->setParameter($clientServiceKey.'.'.$subKey.'.'.$subConfigKey, $subConfigValue); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | } |
||
| 147 | $this->configureClient($container, $clientServiceKey); |
||
| 148 | } |
||
| 149 | $container->getDefinition($this->alias.'.registry')->replaceArgument(0, $clientServiceKeys); |
||
| 150 | } |
||
| 152 |