| Conditions | 8 |
| Paths | 16 |
| Total Lines | 66 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 1 | 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 |
||
| 45 | public function register(Container $app) |
||
| 46 | { |
||
| 47 | $this->app = $app; |
||
| 48 | |||
| 49 | foreach ($this->config as $key => $value) { |
||
| 50 | $this->app[$key] = $value; |
||
| 51 | } |
||
| 52 | |||
| 53 | // register default locator if haven't defined yet |
||
| 54 | if (! $app->offsetExists('tactician.locator')) { |
||
| 55 | $app['tactician.locator'] = function () use ($app) { |
||
| 56 | return new SilexLocator($app); |
||
| 57 | }; |
||
| 58 | } |
||
| 59 | |||
| 60 | // register default command extractor if haven't defined yet |
||
| 61 | if (! $app->offsetExists('tactician.command_extractor')) { |
||
| 62 | $app['tactician.command_extractor'] = function () { |
||
| 63 | return new SilexCommandExtractor(); |
||
| 64 | }; |
||
| 65 | } |
||
| 66 | |||
| 67 | // if inflector is string then resolve it |
||
| 68 | if (is_string($app['tactician.inflector'])) { |
||
| 69 | $app['tactician.inflector'] = $this->resolveStringBaseMethodInflector($app['tactician.inflector']); |
||
| 70 | } |
||
| 71 | |||
| 72 | $app['tactician.command_bus'] = function () use ($app) { |
||
| 73 | // type checking, make sure all command bus component are valid |
||
| 74 | if (! $app['tactician.command_extractor'] instanceof CommandNameExtractor) { |
||
| 75 | throw new \InvalidArgumentException(sprintf( |
||
| 76 | 'Tactician command extractor must implement %s', |
||
| 77 | CommandNameExtractor::class |
||
| 78 | )); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (! $app['tactician.locator'] instanceof HandlerLocator) { |
||
| 82 | throw new \InvalidArgumentException(sprintf( |
||
| 83 | 'Tactician locator must implement %s', |
||
| 84 | HandlerLocator::class |
||
| 85 | )); |
||
| 86 | } |
||
| 87 | |||
| 88 | if (! $app['tactician.inflector'] instanceof MethodNameInflector) { |
||
| 89 | throw new \InvalidArgumentException(sprintf( |
||
| 90 | 'Tactician inflector must implement %s', |
||
| 91 | MethodNameInflector::class |
||
| 92 | )); |
||
| 93 | } |
||
| 94 | |||
| 95 | $handler_middleware = new CommandHandlerMiddleware( |
||
| 96 | $app['tactician.command_extractor'], |
||
| 97 | $app['tactician.locator'], |
||
| 98 | $app['tactician.inflector'] |
||
| 99 | ); |
||
| 100 | |||
| 101 | // combine middleware together |
||
| 102 | $middleware = $app['tactician.middleware']; |
||
| 103 | array_walk($middleware, function (&$value) { |
||
| 104 | $value = $this->resolveMiddleware($value); |
||
| 105 | }); |
||
| 106 | array_push($middleware, $handler_middleware); |
||
| 107 | |||
| 108 | return new CommandBus($middleware); |
||
| 109 | }; |
||
| 110 | } |
||
| 111 | |||
| 169 |