Conditions | 21 |
Paths | 1464 |
Total Lines | 82 |
Code Lines | 56 |
Lines | 0 |
Ratio | 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 |
||
122 | protected function output(array $data) { |
||
123 | // clear output buffer |
||
124 | while(@ob_get_level()){ @ob_end_clean(); } |
||
125 | |||
126 | $header = isset($data['header']) ? $data['header'] : $this->header; |
||
127 | unset($data['header']); |
||
128 | if ($header) { |
||
129 | if (is_array($header)) { |
||
130 | foreach ($header as $h) { |
||
131 | header($h); |
||
132 | } |
||
133 | } else { |
||
134 | header($header); |
||
135 | } |
||
136 | } |
||
137 | |||
138 | if (isset($data['pointer'])) { |
||
139 | $toEnd = true; |
||
140 | $fp = $data['pointer']; |
||
141 | if (elFinder::isSeekableStream($fp)) { |
||
142 | header('Accept-Ranges: bytes'); |
||
143 | $psize = null; |
||
144 | if (!empty($_SERVER['HTTP_RANGE'])) { |
||
145 | $size = $data['info']['size']; |
||
146 | $start = 0; |
||
147 | $end = $size - 1; |
||
148 | if (preg_match('/bytes=(\d*)-(\d*)(,?)/i', $_SERVER['HTTP_RANGE'], $matches)) { |
||
149 | if (empty($matches[3])) { |
||
150 | if (empty($matches[1]) && $matches[1] !== '0') { |
||
151 | $start = $size - $matches[2]; |
||
152 | } else { |
||
153 | $start = intval($matches[1]); |
||
154 | if (!empty($matches[2])) { |
||
155 | $end = intval($matches[2]); |
||
156 | if ($end >= $size) { |
||
157 | $end = $size - 1; |
||
158 | } |
||
159 | $toEnd = ($end == ($size - 1)); |
||
160 | } |
||
161 | } |
||
162 | $psize = $end - $start + 1; |
||
163 | |||
164 | header('HTTP/1.1 206 Partial Content'); |
||
165 | header('Content-Length: ' . $psize); |
||
166 | header('Content-Range: bytes ' . $start . '-' . $end . '/' . $size); |
||
167 | |||
168 | fseek($fp, $start); |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | if (is_null($psize)){ |
||
173 | rewind($fp); |
||
174 | } |
||
175 | } else { |
||
176 | header('Accept-Ranges: none'); |
||
177 | } |
||
178 | |||
179 | // unlock session data for multiple access |
||
180 | session_id() && session_write_close(); |
||
181 | // client disconnect should abort |
||
182 | ignore_user_abort(false); |
||
183 | |||
184 | if ($toEnd) { |
||
185 | fpassthru($fp); |
||
186 | } else { |
||
187 | $out = fopen('php://output', 'wb'); |
||
188 | stream_copy_to_stream($fp, $out, $psize); |
||
189 | fclose($out); |
||
190 | } |
||
191 | if (!empty($data['volume'])) { |
||
192 | $data['volume']->close($data['pointer'], $data['info']['hash']); |
||
193 | } |
||
194 | exit(); |
||
195 | } else { |
||
196 | if (!empty($data['raw']) && !empty($data['error'])) { |
||
197 | exit($data['error']); |
||
198 | } else { |
||
199 | exit(json_encode($data)); |
||
200 | } |
||
201 | } |
||
202 | |||
203 | } |
||
204 | |||
226 |
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.