| Conditions | 13 |
| Paths | 97 |
| Total Lines | 66 |
| Code Lines | 39 |
| 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 |
||
| 101 | private function processClientsConfiguration(array $config, ContainerBuilder $container, $debug) |
||
| 102 | { |
||
| 103 | foreach ($config as $name => $options) { |
||
| 104 | $client = new Definition($options['class']); |
||
| 105 | $client->setLazy($options['lazy']); |
||
| 106 | $useAuthentication = $options['credentials']['enabled']; |
||
| 107 | |||
| 108 | if ($useAuthentication === true) { |
||
| 109 | if (!Helper::multiset(array_values($options['credentials']))) { |
||
| 110 | throw new InvalidArgumentException(sprintf('If authentication parameter is set, htpasswd user and password can not be null')); |
||
| 111 | } |
||
| 112 | $credentials = [ |
||
| 113 | 'auth' => [ |
||
| 114 | $options['credentials']['user'], |
||
| 115 | $options['credentials']['pass'], |
||
| 116 | $options['authentication_type'], |
||
| 117 | ], |
||
| 118 | ]; |
||
| 119 | |||
| 120 | if (!isset($options['config'])) { |
||
| 121 | $options['config'] = $credentials; |
||
| 122 | } else { |
||
| 123 | $options['config'] = array_merge($options['config'], $credentials); |
||
| 124 | } |
||
| 125 | |||
| 126 | } |
||
| 127 | |||
| 128 | if (isset($options['config'])) { |
||
| 129 | if (!is_array($options['config'])) { |
||
| 130 | throw new InvalidArgumentException(sprintf('Config for "'.$this->alias.'.client.%s" should be an array, but got %s', $name, gettype($options['config']))); |
||
| 131 | } |
||
| 132 | $client->addArgument($this->buildGuzzleConfig($options['config'], $debug)); |
||
| 133 | } |
||
| 134 | |||
| 135 | $attributes = []; |
||
| 136 | |||
| 137 | if (!empty($options['middleware'])) { |
||
| 138 | if ($debug) { |
||
| 139 | $addDebugMiddleware = true; |
||
| 140 | |||
| 141 | foreach ($options['middleware'] as $middleware) { |
||
| 142 | if ('!' === ($middleware[0])) { |
||
| 143 | $addDebugMiddleware = false; |
||
| 144 | break; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | if ($addDebugMiddleware) { |
||
| 149 | $options['middleware'] = array_merge($options['middleware'], [ |
||
| 150 | 'stopwatch', |
||
| 151 | 'history', |
||
| 152 | 'logger', |
||
| 153 | ]); |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | $attributes['middleware'] = implode(' ', array_unique($options['middleware'])); |
||
| 158 | } |
||
| 159 | |||
| 160 | $client->addTag(MiddlewarePass::CLIENT_TAG, $attributes); |
||
| 161 | |||
| 162 | $clientServiceId = sprintf($this->alias.'.client.%s', $name); |
||
| 163 | $container->setDefinition($clientServiceId, $client); |
||
| 164 | |||
| 165 | if (isset($options['alias'])) { |
||
| 166 | $container->setAlias($options['alias'], $clientServiceId); |
||
| 167 | } |
||
| 186 | } |