| Conditions | 10 |
| Paths | 8 |
| Total Lines | 59 |
| Code Lines | 37 |
| Lines | 35 |
| Ratio | 59.32 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) |
||
| 87 | { |
||
| 88 | $this->initFactory($serviceLocator); |
||
| 89 | |||
| 90 | /** @var FixtureLoaderManagerInterface $serviceLocator*/ |
||
| 91 | |||
| 92 | |||
| 93 | $loadersConfigs = $this->fixtureLoaderConfig[$requestedName]; |
||
| 94 | |||
| 95 | $chains = []; |
||
| 96 | foreach ($loadersConfigs as $index => $item) { |
||
| 97 | View Code Duplication | if (!is_array($item)) { |
|
| 98 | $errMsg = sprintf( |
||
| 99 | 'Item [%s][fixtures][%s] of type %s is invalid. Must array', |
||
| 100 | Module::CONFIG_KEY, |
||
| 101 | $index, |
||
| 102 | (is_object($item) ? get_class($item) : gettype($item)) |
||
| 103 | ); |
||
| 104 | throw new Exception\RuntimeException($errMsg); |
||
| 105 | } |
||
| 106 | |||
| 107 | View Code Duplication | if (!array_key_exists('name', $item)) { |
|
| 108 | $errMsg = sprintf( |
||
| 109 | 'Required parameter [%s][fixtures][%s][\'name\'] not found', |
||
| 110 | Module::CONFIG_KEY, |
||
| 111 | $index |
||
| 112 | ); |
||
| 113 | throw new Exception\RuntimeException($errMsg); |
||
| 114 | } |
||
| 115 | |||
| 116 | View Code Duplication | if (!is_string($item['name'])) { |
|
| 117 | $errMsg = sprintf( |
||
| 118 | 'Parameter [%s][fixtures][%s][\'name\'] of type %s is invalid. Must string', |
||
| 119 | Module::CONFIG_KEY, |
||
| 120 | $index, |
||
| 121 | (is_object($item['name']) ? get_class($item['name']) : gettype($item['name'])) |
||
| 122 | ); |
||
| 123 | throw new Exception\RuntimeException($errMsg); |
||
| 124 | } |
||
| 125 | |||
| 126 | $name = $item['name']; |
||
| 127 | $options = array_key_exists('options', $item) ? $item['options'] : []; |
||
| 128 | View Code Duplication | if (!is_array($options)) { |
|
| 129 | $errMsg = sprintf( |
||
| 130 | 'Parameter [%s][fixtures][%s][\'options\'] of type %s is invalid. Must array', |
||
| 131 | Module::CONFIG_KEY, |
||
| 132 | $index, |
||
| 133 | (is_object($options) ? get_class($options) : gettype($options)) |
||
| 134 | ); |
||
| 135 | throw new Exception\RuntimeException($errMsg); |
||
| 136 | } |
||
| 137 | |||
| 138 | $chains[] = $serviceLocator->get($name, $options); |
||
| 139 | } |
||
| 140 | |||
| 141 | return $serviceLocator->get(ChainLoader::class, [ |
||
| 142 | 'loaderList' => $chains |
||
| 143 | ]); |
||
| 144 | } |
||
| 145 | } |
||
| 146 |