Conditions | 32 |
Paths | > 20000 |
Total Lines | 156 |
Code Lines | 76 |
Lines | 0 |
Ratio | 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 |
||
107 | public function handleRequest() { |
||
108 | $files = array(); |
||
109 | $supportsGzip = false; |
||
110 | $expiresOffset = $this->parseTime($this->settings["expires"]); |
||
111 | $tinymceDir = dirname(__FILE__); |
||
112 | |||
113 | // Plugins |
||
114 | $plugins = self::getParam("plugins"); |
||
115 | if ($plugins) { |
||
116 | $this->settings["plugins"] = $plugins; |
||
117 | } |
||
118 | |||
119 | $plugins = array_unique(preg_split('/,/', $this->settings["plugins"], -1, PREG_SPLIT_NO_EMPTY)); |
||
120 | |||
121 | // Themes |
||
122 | $themes = self::getParam("themes"); |
||
123 | if ($themes) { |
||
124 | $this->settings["themes"] = $themes; |
||
125 | } |
||
126 | |||
127 | $themes = array_unique(preg_split('/,/', $this->settings["themes"], -1, PREG_SPLIT_NO_EMPTY)); |
||
128 | |||
129 | // Languages |
||
130 | $languages = self::getParam("languages"); |
||
131 | if ($languages) { |
||
132 | $this->settings["languages"] = $languages; |
||
133 | } |
||
134 | |||
135 | $languages = array_unique(preg_split('/,/', $this->settings["languages"], -1, PREG_SPLIT_NO_EMPTY)); |
||
136 | |||
137 | // Files |
||
138 | $tagFiles = self::getParam("files"); |
||
139 | if ($tagFiles) { |
||
140 | $this->settings["files"] = $tagFiles; |
||
141 | } |
||
142 | |||
143 | // Diskcache option |
||
144 | $diskCache = self::getParam("diskcache"); |
||
145 | if ($diskCache) { |
||
146 | $this->settings["disk_cache"] = ($diskCache === "true"); |
||
147 | } |
||
148 | |||
149 | // Source or minified version |
||
150 | $src = self::getParam("src"); |
||
151 | if ($src) { |
||
152 | $this->settings["source"] = ($src === "true"); |
||
153 | } |
||
154 | |||
155 | // Add core js |
||
156 | if (self::getParam("core", "true") === "true") { |
||
157 | $files[] = "tinymce"; |
||
158 | } |
||
159 | |||
160 | // Add core languages |
||
161 | foreach ($languages as $language) { |
||
162 | $files[] = "langs/" . $language; |
||
163 | } |
||
164 | |||
165 | // Add plugins |
||
166 | foreach ($plugins as $plugin) { |
||
167 | $files[] = "plugins/" . $plugin . "/plugin"; |
||
168 | |||
169 | foreach ($languages as $language) { |
||
170 | $files[] = "plugins/" . $plugin . "/langs/" . $language; |
||
171 | } |
||
172 | } |
||
173 | |||
174 | // Add themes |
||
175 | foreach ($themes as $theme) { |
||
176 | $files[] = "themes/" . $theme . "/theme"; |
||
177 | |||
178 | foreach ($languages as $language) { |
||
179 | $files[] = "themes/" . $theme . "/langs/" . $language; |
||
180 | } |
||
181 | } |
||
182 | |||
183 | // Add any specified files. |
||
184 | $allFiles = array_merge($files, array_unique(preg_split('/,/', $this->settings['files'], -1, PREG_SPLIT_NO_EMPTY))); |
||
185 | |||
186 | // Process source files |
||
187 | for ($i = 0; $i < count($allFiles); $i++) { |
||
188 | $file = $allFiles[$i]; |
||
189 | |||
190 | if ($this->settings["source"] && file_exists($file . ".js")) { |
||
191 | $file .= ".js"; |
||
192 | } else if (file_exists($file . ".min.js")) { |
||
193 | $file .= ".min.js"; |
||
194 | } else { |
||
195 | $file = ""; |
||
196 | } |
||
197 | |||
198 | $allFiles[$i] = $file; |
||
199 | } |
||
200 | |||
201 | // Generate hash for all files |
||
202 | $hash = md5(implode('', $allFiles) . $_SERVER['SCRIPT_NAME']); |
||
203 | |||
204 | // Check if it supports gzip |
||
205 | $zlibOn = ini_get('zlib.output_compression') || (ini_set('zlib.output_compression', 0) === false); |
||
206 | $encodings = (isset($_SERVER['HTTP_ACCEPT_ENCODING'])) ? strtolower($_SERVER['HTTP_ACCEPT_ENCODING']) : ""; |
||
207 | $encoding = preg_match( '/\b(x-gzip|gzip)\b/', $encodings, $match) ? $match[1] : ""; |
||
208 | |||
209 | // Is northon antivirus header |
||
210 | if (isset($_SERVER['---------------'])) { |
||
211 | $encoding = "x-gzip"; |
||
212 | } |
||
213 | |||
214 | $supportsGzip = $this->settings['compress'] && !empty($encoding) && !$zlibOn && function_exists('gzencode'); |
||
215 | |||
216 | // Set cache file name |
||
217 | $cacheFile = $this->settings["cache_dir"] . "/tinymce.gzip-" . $hash . ($supportsGzip ? ".gz" : ".js"); |
||
218 | |||
219 | // Set headers |
||
220 | header("Content-type: text/javascript"); |
||
221 | header("Vary: Accept-Encoding"); // Handle proxies |
||
222 | header("Expires: " . gmdate("D, d M Y H:i:s", time() + $expiresOffset) . " GMT"); |
||
223 | header("Cache-Control: public, max-age=" . $expiresOffset); |
||
224 | |||
225 | if ($supportsGzip) { |
||
226 | header("Content-Encoding: " . $encoding); |
||
227 | } |
||
228 | |||
229 | // Use cached file |
||
230 | if ($this->settings['disk_cache'] && file_exists($cacheFile)) { |
||
231 | readfile($cacheFile); |
||
232 | return; |
||
233 | } |
||
234 | |||
235 | // Set base URL for where tinymce is loaded from |
||
236 | $buffer = "var tinyMCEPreInit={base:'" . dirname($_SERVER["SCRIPT_NAME"]) . "',suffix:'.min'};"; |
||
237 | |||
238 | // Load all tinymce script files into buffer |
||
239 | foreach ($allFiles as $file) { |
||
240 | if ($file) { |
||
241 | $fileContents = $this->getFileContents($tinymceDir . "/" . $file); |
||
242 | // $buffer .= "\n//-FILE-$tinymceDir/$file (". strlen($fileContents) . " bytes)\n"; |
||
243 | $buffer .= $fileContents; |
||
244 | } |
||
245 | } |
||
246 | |||
247 | // Mark all themes, plugins and languages as done |
||
248 | $buffer .= 'tinymce.each("' . implode(',', $files) . '".split(","),function(f){tinymce.ScriptLoader.markDone(tinyMCE.baseURL+"/"+f+".js");});'; |
||
249 | |||
250 | // Compress data |
||
251 | if ($supportsGzip) { |
||
252 | $buffer = gzencode($buffer, 9, FORCE_GZIP); |
||
253 | } |
||
254 | |||
255 | // Write cached file |
||
256 | if ($this->settings["disk_cache"]) { |
||
257 | @file_put_contents($cacheFile, $buffer); |
||
258 | } |
||
259 | |||
260 | // Stream contents to client |
||
261 | echo $buffer; |
||
262 | } |
||
263 | |||
386 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.