Conditions | 10 |
Paths | 52 |
Total Lines | 39 |
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 |
||
25 | function Download ($content, $filename = '', $mime = 'application/force-download') { |
||
26 | list($usec, $sec) = explode(" ", microtime()); |
||
27 | $usec = substr(strval($usec), 2, 3); |
||
28 | $tmpfilename = $sec . $usec; |
||
29 | |||
30 | if (empty($filename)) { |
||
31 | // Use timestamp as filename if not provide |
||
32 | $filename = $tmpfilename; |
||
33 | } |
||
34 | |||
35 | if (NixOs()) { |
||
|
|||
36 | $filepath = '/tmp/'; |
||
37 | } else { |
||
38 | $s_tmp = ''; |
||
39 | if (!empty($_ENV["TEMP"])) |
||
40 | $s_tmp = $_ENV["TEMP"]; |
||
41 | if (empty($s_tmp) && !empty($_ENV["TMP"])) |
||
42 | $s_tmp = $_ENV["TMP"]; |
||
43 | // Default, this should never accur |
||
44 | if (empty($s_tmp)) |
||
45 | $s_tmp = 'c:/windows/temp/'; |
||
46 | // And check again |
||
47 | if (!is_dir($s_tmp) || !is_writable($s_tmp)) |
||
48 | die('No temp dir to store file content which need to downloaded.'); |
||
49 | |||
50 | $filepath = $s_tmp; |
||
51 | } |
||
52 | // Add the ending '/' to tmp path |
||
53 | if ('/' != substr($filepath, -1)) |
||
54 | $filepath .= '/'; |
||
55 | // Then got full path of tmp file |
||
56 | $tmpfilename = $filepath . $tmpfilename; |
||
57 | |||
58 | file_put_contents($tmpfilename, $content); |
||
59 | $result = DownloadFile($tmpfilename, $filename, $mime); |
||
60 | |||
61 | unlink($tmpfilename); |
||
62 | return $result; |
||
63 | } // end of func Download |
||
64 | |||
125 |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.