Conditions | 16 |
Paths | 17 |
Total Lines | 72 |
Code Lines | 41 |
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 |
||
81 | function process_page(bool $obfuscatejs, \MVC\themes $theme) |
||
82 | { |
||
83 | //global $theme; |
||
84 | $dom = new SmartDOMDocument('1.0', 'ISO-8859-15'); |
||
85 | $dom->preserveWhiteSpace = true; |
||
86 | $dom->formatOutput = true; |
||
87 | |||
88 | $c = ob_get(); |
||
89 | |||
90 | if (!$dom->loadHTML($c)) { |
||
91 | \HTML\js::var('HTML_ERROR', json_encode(['error' => true, 'message' => 'HTML Optimizer failed'])); |
||
92 | echo $c; |
||
93 | |||
94 | return; |
||
95 | } |
||
96 | |||
97 | $xpath = new SmartDOMXpath($dom); |
||
98 | $title = getTitle($dom); |
||
99 | |||
100 | $scripts = $xpath->query('//script'); |
||
101 | if (!empty($scripts)) { |
||
102 | foreach ($scripts as $script) { |
||
103 | if ($script->hasAttribute('type') && 'application/ld+json' == $script->getAttribute('type')) { |
||
104 | $script->innerHTML = json_encode(json_decode(innerHTML($script))); |
||
105 | } |
||
106 | } |
||
107 | } |
||
108 | |||
109 | $imgs = $xpath->query('//img'); |
||
110 | if (!empty($imgs)) { |
||
111 | foreach ($imgs as $img) { |
||
112 | if (!$img->hasAttribute('title')) { |
||
113 | $img->setAttribute('title', $title); |
||
114 | } |
||
115 | if (!$img->hasAttribute('alt')) { |
||
116 | $img->setAttribute('alt', $title); |
||
117 | } |
||
118 | if (!$img->hasAttribute('rel')) { |
||
119 | $img->setAttribute('rel', 'image'); |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | |||
124 | $styles = $xpath->query('//style'); |
||
125 | if (!empty($styles)) { |
||
126 | foreach ($styles as $style) { |
||
127 | $style->innerHTML = trim(mincss(innerHTML($style))); |
||
128 | } |
||
129 | } |
||
130 | |||
131 | $textareas = $xpath->query('//textarea'); |
||
132 | if (!empty($textareas)) { |
||
133 | foreach ($textareas as $area) { |
||
134 | $inner = trim(html_entity_decode($area->innerHTML)); |
||
135 | if (is_json(trim($inner))) { |
||
136 | $area->setAttribute('innerhtml', base64_encode(\JSON\json::json($inner, false, false))); |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | |||
141 | $result = $dom->saveHTML(); |
||
142 | $result = prefilter(htmlmin($result)); |
||
143 | resolve_dir(dirname(page_cache())); |
||
144 | \Filemanager\file::file(page_cache(), $result, true); |
||
145 | /** |
||
146 | * @var string Load admin toolbox |
||
147 | */ |
||
148 | $result = str_replace('</html>', '', $result); |
||
149 | echo $result; |
||
150 | //$theme->load_admin_tools(); |
||
151 | |||
152 | echo '</html>'; |
||
153 | } |
||
154 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.