Conditions | 13 |
Paths | 236 |
Total Lines | 44 |
Code Lines | 18 |
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 |
||
13 | protected function build($config, array $options) |
||
14 | { |
||
15 | // A service builder class can be specified in the class field |
||
16 | $class = !empty($config['class']) ? $config['class'] : __NAMESPACE__ . '\\ServiceBuilder'; |
||
17 | |||
18 | // Account for old style configs that do not have a services array |
||
19 | $services = isset($config['services']) ? $config['services'] : $config; |
||
20 | |||
21 | // Validate the configuration and handle extensions |
||
22 | foreach ($services as $name => &$service) { |
||
23 | |||
24 | $service['params'] = isset($service['params']) ? $service['params'] : array(); |
||
25 | |||
26 | // Check if this client builder extends another client |
||
27 | if (!empty($service['extends'])) { |
||
28 | |||
29 | // Make sure that the service it's extending has been defined |
||
30 | if (!isset($services[$service['extends']])) { |
||
31 | throw new ServiceNotFoundException( |
||
32 | "{$name} is trying to extend a non-existent service: {$service['extends']}" |
||
33 | ); |
||
34 | } |
||
35 | |||
36 | $extended = &$services[$service['extends']]; |
||
37 | |||
38 | // Use the correct class attribute |
||
39 | if (empty($service['class'])) { |
||
40 | $service['class'] = isset($extended['class']) ? $extended['class'] : ''; |
||
41 | } |
||
42 | if ($extendsParams = isset($extended['params']) ? $extended['params'] : false) { |
||
43 | $service['params'] = $service['params'] + $extendsParams; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | // Overwrite default values with global parameter values |
||
48 | if (!empty($options)) { |
||
49 | $service['params'] = $options + $service['params']; |
||
50 | } |
||
51 | |||
52 | $service['class'] = isset($service['class']) ? $service['class'] : ''; |
||
53 | } |
||
54 | |||
55 | return new $class($services); |
||
56 | } |
||
57 | |||
90 |