Conditions | 5 |
Paths | 2 |
Total Lines | 51 |
Code Lines | 26 |
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 |
||
12 | public function templateEngine(array $config): void |
||
13 | { |
||
14 | parent::templateEngine($config); |
||
15 | |||
16 | $d = new Twig_SimpleFunction('d', function ($var) { |
||
17 | return d($var); |
||
18 | }); |
||
19 | |||
20 | $this->getTwig()->addFunction($d); |
||
21 | |||
22 | $date = new Twig_SimpleFunction('date', function ($var) { |
||
23 | return date($var); |
||
24 | }); |
||
25 | |||
26 | $this->getTwig()->addFunction($date); |
||
27 | |||
28 | $auth = new Twig_SimpleFunction('auth', function () { |
||
29 | return $this->container()->get('auth')->access(true); |
||
30 | }); |
||
31 | |||
32 | $this->getTwig()->addFunction($auth); |
||
33 | |||
34 | $active = new Twig_SimpleFunction('active', function ($link, $page) { |
||
35 | if ($link == $page) { |
||
36 | echo 'class="active"'; |
||
37 | } |
||
38 | }); |
||
39 | |||
40 | $this->getTwig()->addFunction($active); |
||
41 | |||
42 | $value = new Twig_SimpleFunction('value', function ($var) { |
||
43 | if ($this->container()->hasSession('value', $var)) { |
||
44 | return $this->container()->getSession('value', $var); |
||
45 | } |
||
46 | }); |
||
47 | |||
48 | $this->getTwig()->addFunction($value); |
||
49 | |||
50 | $alert = new Twig_SimpleFunction('alert', function ($value, $style, $label = null) { |
||
51 | if ($this->container()->hasSession('alert', $value)) { |
||
52 | return '<div class="alert alert-' . $style . '" style="padding: 15px">' . $this->container()->getSession('alert', $value) . $label . '</div>'; |
||
53 | } |
||
54 | }); |
||
55 | |||
56 | $this->getTwig()->addFunction($alert); |
||
57 | |||
58 | if (DEV) { |
||
59 | $debugbarRenderer = $this->container()->get('debugbar')->getJavascriptRenderer(); |
||
60 | $this->getTwig()->addGlobal('debugbar', $debugbarRenderer); |
||
61 | } |
||
62 | } |
||
63 | |||
73 | } |