Conditions | 13 |
Paths | 192 |
Total Lines | 43 |
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 |
||
31 | protected function renderBodyEndHtml($ajaxMode) |
||
32 | { |
||
33 | $lines = []; |
||
34 | |||
35 | if (!empty($this->jsFiles[self::POS_END])) { |
||
36 | $lines[] = implode("\n", $this->jsFiles[self::POS_END]); |
||
37 | } |
||
38 | |||
39 | if (!empty($this->json)) { |
||
40 | foreach($this->json[self::POS_READY] as $json_name => $json_value) { |
||
41 | $lines[] = Html::script($json_value, ['type' => 'application/json', 'id' => $json_name]); |
||
42 | } |
||
43 | } |
||
44 | |||
45 | if ($ajaxMode) { |
||
46 | $scripts = []; |
||
47 | if (!empty($this->js[self::POS_END])) { |
||
48 | $scripts[] = implode("\n", $this->js[self::POS_END]); |
||
49 | } |
||
50 | if (!empty($this->js[self::POS_READY])) { |
||
51 | $scripts[] = implode("\n", $this->js[self::POS_READY]); |
||
52 | } |
||
53 | if (!empty($this->js[self::POS_LOAD])) { |
||
54 | $scripts[] = implode("\n", $this->js[self::POS_LOAD]); |
||
55 | } |
||
56 | if (!empty($scripts)) { |
||
57 | $lines[] = Html::script(implode("\n", $scripts), ['type' => 'text/javascript']); |
||
58 | } |
||
59 | } else { |
||
60 | if (!empty($this->js[self::POS_END])) { |
||
61 | $lines[] = Html::script(implode("\n", $this->js[self::POS_END]), ['type' => 'text/javascript']); |
||
62 | } |
||
63 | if (!empty($this->js[self::POS_READY])) { |
||
64 | $js = "jQuery(document).ready(function () {\n" . implode("\n", $this->js[self::POS_READY]) . "\n});"; |
||
65 | $lines[] = Html::script($js, ['type' => 'text/javascript']); |
||
66 | } |
||
67 | if (!empty($this->js[self::POS_LOAD])) { |
||
68 | $js = "jQuery(window).load(function () {\n" . implode("\n", $this->js[self::POS_LOAD]) . "\n});"; |
||
69 | $lines[] = Html::script($js, ['type' => 'text/javascript']); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | return empty($lines) ? '' : implode("\n", $lines); |
||
74 | } |
||
76 |