Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
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 |
||
21 | public function addToContainer(Container $c) |
||
22 | { |
||
23 | $c[ViewEngine::class] = $c->get(ViewEngine::class); |
||
24 | |||
25 | $c[NotFoundDecorator::class] = $c->factory(function (Container $c) { |
||
26 | $layout = $c->get('default_layout'); |
||
27 | $templates = $c->get('error_pages'); |
||
28 | $viewEngine = $c->get(ViewEngine::class); |
||
29 | $notFoundDecorator = new NotFoundDecorator($viewEngine, $templates); |
||
30 | $notFoundDecorator->setLayout($layout); |
||
31 | |||
32 | return $notFoundDecorator; |
||
33 | }); |
||
34 | |||
35 | $c[NotAllowedDecorator::class] = $c->factory(function (Container $c) { |
||
36 | $layout = $c->get('default_layout'); |
||
37 | $templates = $c->get('error_pages'); |
||
38 | $viewEngine = $c->get(ViewEngine::class); |
||
39 | $notAllowedDecorator = new NotAllowedDecorator($viewEngine, $templates); |
||
40 | $notAllowedDecorator->setLayout($layout); |
||
41 | |||
42 | return $notAllowedDecorator; |
||
43 | }); |
||
44 | |||
45 | $c[ExceptionDecorator::class] = $c->factory(function (Container $c) { |
||
46 | $viewEngine = $c->get(ViewEngine::class); |
||
47 | $layout = $c->get('default_layout'); |
||
48 | $templates = $c->get('error_pages'); |
||
49 | $decorator = new ExceptionDecorator($viewEngine, $templates); |
||
50 | $decorator->setLayout($layout); |
||
51 | |||
52 | return $decorator; |
||
53 | }); |
||
54 | |||
55 | $c[PlatesStrategy::class] = $c->factory(function (Container $c) { |
||
56 | $viewEngine = $c->get(ViewEngine::class); |
||
57 | $notFoundDecorator = $c->get(NotFoundDecorator::class); |
||
58 | $notAllowedDecorator = $c->get(NotAllowedDecorator::class); |
||
59 | $exceptionDecorator = $c->get(ExceptionDecorator::class); |
||
60 | $layout = $c->get('default_layout'); |
||
61 | $strategy = new PlatesStrategy($viewEngine, $notFoundDecorator, $notAllowedDecorator, $layout, $exceptionDecorator); |
||
62 | |||
63 | return $strategy; |
||
64 | }); |
||
65 | |||
66 | /** @var PlatesStrategy $strategy */ |
||
67 | $strategy = $c->get(PlatesStrategy::class); |
||
68 | $strategy->setContainer($c); |
||
69 | |||
70 | $router = $c->get(Router::class); |
||
71 | $router->setStrategy($strategy); |
||
72 | } |
||
74 |