| Conditions | 10 |
| Paths | 72 |
| Total Lines | 41 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 36 | public function createService(ServiceLocatorInterface $serviceLocator) |
||
| 37 | { |
||
| 38 | /** @var AbstractPluginManager $serviceLocator */ |
||
| 39 | |||
| 40 | |||
| 41 | $creationOptions = $this->getCreationOptions(); |
||
| 42 | $options = is_array($creationOptions) ? $creationOptions : []; |
||
| 43 | |||
| 44 | $resolvers = array_key_exists('resolvers', $options) && is_array($options['resolvers']) ? $options['resolvers'] : []; |
||
| 45 | |||
| 46 | $chain = new EntryNameResolverChain(); |
||
| 47 | foreach ($resolvers as $entryNameResolverConfig) { |
||
| 48 | if (!is_array($entryNameResolverConfig)) { |
||
| 49 | $errMsg = 'Entry name resolver config is not array'; |
||
| 50 | throw new Exception\RuntimeException($errMsg); |
||
| 51 | } |
||
| 52 | |||
| 53 | if (!array_key_exists('name', $entryNameResolverConfig)) { |
||
| 54 | $errMsg = 'Resolver entry name not found'; |
||
| 55 | throw new Exception\RuntimeException($errMsg); |
||
| 56 | } |
||
| 57 | |||
| 58 | $name = $entryNameResolverConfig['name']; |
||
| 59 | |||
| 60 | $resolverOptions = array_key_exists('options', $entryNameResolverConfig) ? $entryNameResolverConfig['options'] : []; |
||
| 61 | |||
| 62 | if (!is_array($resolverOptions)) { |
||
| 63 | $errMsg = 'Resolver options is not array'; |
||
| 64 | throw new Exception\RuntimeException($errMsg); |
||
| 65 | } |
||
| 66 | |||
| 67 | /** @var EntryNameResolverInterface $resolver */ |
||
| 68 | $resolver = $serviceLocator->get($name, $resolverOptions); |
||
| 69 | |||
| 70 | $priority = array_key_exists('priority', $entryNameResolverConfig) ? (integer)$entryNameResolverConfig['priority'] : EntryNameResolverChain::DEFAULT_PRIORITY; |
||
| 71 | |||
| 72 | $chain->attach($resolver, $priority); |
||
| 73 | } |
||
| 74 | |||
| 75 | return $chain; |
||
| 76 | } |
||
| 77 | } |
||
| 78 |