| Conditions | 24 |
| Paths | 818 |
| Total Lines | 92 |
| Code Lines | 59 |
| Lines | 7 |
| Ratio | 7.61 % |
| 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 |
||
| 200 | protected function output(array $data) |
||
| 201 | { |
||
| 202 | // unlock session data for multiple access |
||
| 203 | $this->elFinder->getSession()->close(); |
||
| 204 | // client disconnect should abort |
||
| 205 | ignore_user_abort(false); |
||
| 206 | |||
| 207 | if ($this->header) { |
||
| 208 | self::sendHeader($this->header); |
||
| 209 | } |
||
| 210 | |||
| 211 | if (isset($data['pointer'])) { |
||
| 212 | // set time limit to 0 |
||
| 213 | elFinder::extendTimeLimit(0); |
||
| 214 | |||
| 215 | // send optional header |
||
| 216 | if (! empty($data['header'])) { |
||
| 217 | self::sendHeader($data['header']); |
||
| 218 | } |
||
| 219 | |||
| 220 | // clear output buffer |
||
| 221 | while (ob_get_level() && ob_end_clean()) { |
||
| 222 | } |
||
| 223 | |||
| 224 | $toEnd = true; |
||
| 225 | $fp = $data['pointer']; |
||
| 226 | if (($this->reqMethod === 'GET' || $this->reqMethod === 'HEAD') |
||
| 227 | && elFinder::isSeekableStream($fp) |
||
| 228 | && (array_search('Accept-Ranges: none', headers_list()) === false)) { |
||
| 229 | header('Accept-Ranges: bytes'); |
||
| 230 | $psize = null; |
||
| 231 | if (! empty($_SERVER['HTTP_RANGE'])) { |
||
| 232 | $size = $data['info']['size']; |
||
| 233 | $start = 0; |
||
| 234 | $end = $size - 1; |
||
| 235 | if (preg_match('/bytes=(\d*)-(\d*)(,?)/i', $_SERVER['HTTP_RANGE'], $matches)) { |
||
| 236 | if (empty($matches[3])) { |
||
| 237 | if (empty($matches[1]) && $matches[1] !== '0') { |
||
| 238 | $start = $size - $matches[2]; |
||
| 239 | } else { |
||
| 240 | $start = intval($matches[1]); |
||
| 241 | if (! empty($matches[2])) { |
||
| 242 | $end = intval($matches[2]); |
||
| 243 | if ($end >= $size) { |
||
| 244 | $end = $size - 1; |
||
| 245 | } |
||
| 246 | $toEnd = ($end == ($size - 1)); |
||
| 247 | } |
||
| 248 | } |
||
| 249 | $psize = $end - $start + 1; |
||
| 250 | |||
| 251 | header('HTTP/1.1 206 Partial Content'); |
||
| 252 | header('Content-Length: '.$psize); |
||
| 253 | header('Content-Range: bytes '.$start.'-'.$end.'/'.$size); |
||
| 254 | |||
| 255 | fseek($fp, $start); |
||
| 256 | } |
||
| 257 | } |
||
| 258 | } |
||
| 259 | if (is_null($psize)) { |
||
| 260 | elFinder::rewind($fp); |
||
| 261 | } |
||
| 262 | } else { |
||
| 263 | header('Accept-Ranges: none'); |
||
| 264 | if (isset($data['info']) && ! $data['info']['size']) { |
||
| 265 | if (function_exists('header_remove')) { |
||
| 266 | header_remove('Content-Length'); |
||
| 267 | } else { |
||
| 268 | header('Content-Length:'); |
||
| 269 | } |
||
| 270 | } |
||
| 271 | } |
||
| 272 | |||
| 273 | if ($reqMethod !== 'HEAD') { |
||
| 274 | View Code Duplication | if ($toEnd) { |
|
| 275 | fpassthru($fp); |
||
| 276 | } else { |
||
| 277 | $out = fopen('php://output', 'wb'); |
||
| 278 | stream_copy_to_stream($fp, $out, $psize); |
||
| 279 | fclose($out); |
||
| 280 | } |
||
| 281 | } |
||
| 282 | |||
| 283 | if (! empty($data['volume'])) { |
||
| 284 | $data['volume']->close($data['pointer'], $data['info']['hash']); |
||
| 285 | } |
||
| 286 | exit(); |
||
| 287 | } else { |
||
| 288 | self::outputJson($data); |
||
| 289 | exit(0); |
||
| 290 | } |
||
| 291 | } |
||
| 292 | |||
| 335 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.