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