| Conditions | 10 |
| Paths | 72 |
| Total Lines | 51 |
| Code Lines | 36 |
| 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 namespace XoopsModules\Smartobject; |
||
| 175 | public function saveCsv($content) |
||
| 176 | { |
||
| 177 | if (!$this->filepath) { |
||
| 178 | $this->filepath = XOOPS_UPLOAD_PATH . '/'; |
||
| 179 | } |
||
| 180 | if (!$this->filename) { |
||
| 181 | $this->filename .= time(); |
||
| 182 | $this->filename .= '.csv'; |
||
| 183 | } |
||
| 184 | |||
| 185 | $fullFileName = $this->filepath . $this->filename; |
||
| 186 | |||
| 187 | if (!$handle = fopen($fullFileName, 'a+')) { |
||
| 188 | trigger_error('Unable to open ' . $fullFileName, E_USER_WARNING); |
||
| 189 | } elseif (false === fwrite($handle, $content)) { |
||
| 190 | trigger_error('Unable to write in ' . $fullFileName, E_USER_WARNING); |
||
| 191 | } else { |
||
| 192 | $mimeType = 'text/csv'; |
||
| 193 | $file = strrev($this->filename); |
||
| 194 | $temp_name = strtolower(strrev(substr($file, 0, strpos($file, '--')))); |
||
| 195 | if ('' === $temp_name) { |
||
| 196 | $file_name = $this->filename; |
||
| 197 | } else { |
||
| 198 | $file_name = $temp_name; |
||
| 199 | } |
||
| 200 | $fullFileName = $this->filepath . stripslashes(trim($this->filename)); |
||
| 201 | |||
| 202 | if (ini_get('zlib.output_compression')) { |
||
| 203 | ini_set('zlib.output_compression', 'Off'); |
||
| 204 | } |
||
| 205 | |||
| 206 | header('Pragma: public'); |
||
| 207 | header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); |
||
| 208 | header('Cache-Control: private', false); |
||
| 209 | header('Content-Transfer-Encoding: binary'); |
||
| 210 | if (isset($mimeType)) { |
||
| 211 | header('Content-Type: ' . $mimeType); |
||
| 212 | } |
||
| 213 | |||
| 214 | header('Content-Disposition: attachment; filename=' . $file_name); |
||
| 215 | |||
| 216 | if (isset($mimeType) && false !== strpos($mimeType, 'text/')) { |
||
| 217 | $fp = fopen($fullFileName, 'r'); |
||
| 218 | } else { |
||
| 219 | $fp = fopen($fullFileName, 'rb'); |
||
| 220 | } |
||
| 221 | fpassthru($fp); |
||
| 222 | exit(); |
||
| 223 | } |
||
| 224 | fclose($handle); |
||
| 225 | } |
||
| 226 | } |
||
| 227 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.