| Conditions | 12 |
| Paths | 38 |
| Total Lines | 58 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | 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 |
||
| 31 | private function setHeader() |
||
| 32 | { |
||
| 33 | ob_get_clean(); |
||
| 34 | header('Content-Type: '.$this->mime); |
||
| 35 | header('Cache-Control: max-age=2592000, public'); |
||
| 36 | header('Expires: '.gmdate('D, d M Y H:i:s', time() + 2592000).' GMT'); |
||
| 37 | header('Last-Modified: '.gmdate('D, d M Y H:i:s', @filemtime($this->path)).' GMT'); |
||
| 38 | $this->start = 0; |
||
| 39 | $this->size = filesize($this->path); |
||
| 40 | $this->end = $this->size - 1; |
||
| 41 | header('Accept-Ranges: 0-'.$this->end); |
||
| 42 | |||
| 43 | if (! isset($_SERVER['HTTP_RANGE'])) { |
||
| 44 | header('Content-Length: '.$this->size); |
||
| 45 | |||
| 46 | return; |
||
| 47 | } |
||
| 48 | |||
| 49 | $c_end = $this->end; |
||
| 50 | [ |
||
| 51 | , |
||
| 52 | $range, |
||
| 53 | ] = explode('=', $_SERVER['HTTP_RANGE'], 2); |
||
| 54 | |||
| 55 | |||
| 56 | if (strpos($range, ',') !== false) { |
||
| 57 | header('HTTP/1.1 416 Requested Range Not Satisfiable'); |
||
| 58 | header("Content-Range: bytes $this->start-$this->end/$this->size"); |
||
| 59 | exit; |
||
| 60 | } |
||
| 61 | |||
| 62 | if ($range == '-') { |
||
| 63 | $c_start = $this->size - substr($range, 1); |
||
| 64 | } else { |
||
| 65 | $range = explode('-', $range); |
||
| 66 | $c_start = $range[0]; |
||
| 67 | |||
| 68 | if ( isset($range[1]) && is_numeric($range[1]) ) { |
||
| 69 | \Log::info('$range:'. $range[1]. gettype($range[1])); |
||
| 70 | } else { |
||
| 71 | \Log::info('default: '. $c_end); |
||
| 72 | } |
||
| 73 | |||
| 74 | $c_end = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $c_end; |
||
| 75 | } |
||
| 76 | $c_end = ($c_end > $this->end) ? $this->end : $c_end; |
||
| 77 | if ($c_start > $c_end || $c_start > $this->size - 1 || $c_end >= $this->size) { |
||
| 78 | header('HTTP/1.1 416 Requested Range Not Satisfiable'); |
||
| 79 | header("Content-Range: bytes $this->start-$this->end/$this->size"); |
||
| 80 | exit; |
||
| 81 | } |
||
| 82 | $this->start = $c_start; |
||
| 83 | $this->end = $c_end; |
||
| 84 | $length = $this->end - $this->start + 1; |
||
| 85 | fseek($this->stream, $this->start); |
||
|
|
|||
| 86 | header('HTTP/1.1 206 Partial Content'); |
||
| 87 | header('Content-Length: '.$length); |
||
| 88 | header("Content-Range: bytes $this->start-$this->end/".$this->size); |
||
| 89 | } |
||
| 137 |