| Conditions | 11 |
| Paths | 49 |
| Total Lines | 48 |
| Code Lines | 20 |
| 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 |
||
| 59 | public function define(Container $container) |
||
| 60 | { |
||
| 61 | // Convert config to an object and inject it |
||
| 62 | $container->set('config', new ArrayObject($this->config, ArrayObject::ARRAY_AS_PROPS)); |
||
| 63 | |||
| 64 | if (empty($this->config['dependencies'])) { |
||
| 65 | return; |
||
| 66 | } |
||
| 67 | |||
| 68 | $dependencies = $this->config['dependencies']; |
||
| 69 | |||
| 70 | // Inject delegator factories |
||
| 71 | // This is done early because Aura.Di does not allow modification of a |
||
| 72 | // service after creation. As such, we need to create custom factories |
||
| 73 | // for each service with delegators. |
||
| 74 | if (isset($dependencies['delegators'])) { |
||
| 75 | $dependencies = $this->marshalDelegators($container, $dependencies); |
||
| 76 | } |
||
| 77 | |||
| 78 | // Inject services |
||
| 79 | if (isset($dependencies['services'])) { |
||
| 80 | foreach ($dependencies['services'] as $name => $service) { |
||
| 81 | $container->set($name, $service); |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | // Inject factories |
||
| 86 | if (isset($dependencies['factories'])) { |
||
| 87 | foreach ($dependencies['factories'] as $service => $factory) { |
||
| 88 | $container->set($factory, $container->lazyNew($factory)); |
||
| 89 | $container->set($service, $container->lazyGetCall($factory, '__invoke', $container)); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | // Inject invokables |
||
| 94 | if (isset($dependencies['invokables'])) { |
||
| 95 | foreach ($dependencies['invokables'] as $service => $class) { |
||
| 96 | $container->set($service, $container->lazyNew($class)); |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | // Inject aliases |
||
| 101 | if (isset($dependencies['aliases'])) { |
||
| 102 | foreach ($dependencies['aliases'] as $alias => $target) { |
||
| 103 | $container->set($alias, $container->lazyGet($target)); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 172 |