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