| Conditions | 18 |
| Paths | 14 |
| Total Lines | 58 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 129 | function PMA_readFile($path, $mime = '') |
||
| 130 | { |
||
| 131 | global $cfg; |
||
| 132 | |||
| 133 | if (!is_file($path)) { |
||
| 134 | return false; |
||
| 135 | } |
||
| 136 | switch ($mime) { |
||
| 137 | case '': |
||
| 138 | if (!$file = fopen($path, 'rb')) { |
||
| 139 | return false; |
||
| 140 | } |
||
| 141 | $test = fread($file, 3); |
||
| 142 | fclose($file); |
||
| 143 | if ($test[0] === chr(31) && $test[1] === chr(139)) { |
||
| 144 | return PMA_readFile($path, 'application/x-gzip'); |
||
| 145 | } |
||
| 146 | if ('BZh' == $test) { |
||
| 147 | return PMA_readFile($path, 'application/x-bzip'); |
||
| 148 | } |
||
| 149 | return PMA_readFile($path, 'text/plain'); |
||
| 150 | case 'text/plain': |
||
| 151 | if (!$file = fopen($path, 'rb')) { |
||
| 152 | return false; |
||
| 153 | } |
||
| 154 | $content = fread($file, filesize($path)); |
||
| 155 | fclose($file); |
||
| 156 | break; |
||
| 157 | case 'application/x-gzip': |
||
| 158 | if ($cfg['GZipDump'] && function_exists('gzopen')) { |
||
| 159 | if (!$file = gzopen($path, 'rb')) { |
||
| 160 | return false; |
||
| 161 | } |
||
| 162 | $content = ''; |
||
| 163 | while (!gzeof($file)) { |
||
| 164 | $content .= gzgetc($file); |
||
| 165 | } |
||
| 166 | gzclose($file); |
||
| 167 | } else { |
||
| 168 | return false; |
||
| 169 | } |
||
| 170 | break; |
||
| 171 | case 'application/x-bzip': |
||
| 172 | if ($cfg['BZipDump'] && function_exists('bzdecompress')) { |
||
| 173 | if (!$file = fopen($path, 'rb')) { |
||
| 174 | return false; |
||
| 175 | } |
||
| 176 | $content = fread($file, filesize($path)); |
||
| 177 | fclose($file); |
||
| 178 | $content = bzdecompress($content); |
||
| 179 | } else { |
||
| 180 | return false; |
||
| 181 | } |
||
| 182 | break; |
||
| 183 | default: |
||
| 184 | return false; |
||
| 185 | } |
||
| 186 | return $content; |
||
| 187 | } |
||
| 188 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.