Conditions | 46 |
Paths | 4405 |
Total Lines | 372 |
Lines | 23 |
Ratio | 6.18 % |
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 |
||
29 | public function Analyze() { |
||
30 | |||
31 | $getid3 = $this->getid3; |
||
32 | |||
33 | $getid3->include_module('audio-video.riff'); |
||
34 | |||
35 | $getid3->info['fileformat'] = 'real'; |
||
36 | $getid3->info['bitrate'] = 0; |
||
37 | $getid3->info['playtime_seconds'] = 0; |
||
38 | |||
39 | fseek($getid3->fp, $getid3->info['avdataoffset'], SEEK_SET); |
||
40 | $chunk_counter = 0; |
||
41 | |||
42 | while (ftell($getid3->fp) < $getid3->info['avdataend']) { |
||
43 | |||
44 | $chunk_data = fread($getid3->fp, 8); |
||
45 | $chunk_name = substr($chunk_data, 0, 4); |
||
46 | $chunk_size = getid3_lib::BigEndian2Int(substr($chunk_data, 4, 4)); |
||
47 | |||
48 | if ($chunk_name == '.ra'."\xFD") { |
||
49 | $chunk_data .= fread($getid3->fp, $chunk_size - 8); |
||
50 | |||
51 | if ($this->ParseOldRAheader(substr($chunk_data, 0, 128), $getid3->info['real']['old_ra_header'])) { |
||
52 | |||
53 | $getid3->info['audio']['dataformat'] = 'real'; |
||
54 | $getid3->info['audio']['lossless'] = false; |
||
55 | $getid3->info['audio']['sample_rate'] = $getid3->info['real']['old_ra_header']['sample_rate']; |
||
56 | $getid3->info['audio']['bits_per_sample'] = $getid3->info['real']['old_ra_header']['bits_per_sample']; |
||
57 | $getid3->info['audio']['channels'] = $getid3->info['real']['old_ra_header']['channels']; |
||
58 | |||
59 | $getid3->info['playtime_seconds'] = 60 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['real']['old_ra_header']['bytes_per_minute']); |
||
60 | $getid3->info['audio']['bitrate'] = 8 * ($getid3->info['real']['old_ra_header']['audio_bytes'] / $getid3->info['playtime_seconds']); |
||
61 | $getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($getid3->info['real']['old_ra_header']['fourcc'], $getid3->info['audio']['bitrate']); |
||
62 | |||
63 | foreach ($getid3->info['real']['old_ra_header']['comments'] as $key => $value_array) { |
||
64 | |||
65 | if (strlen(trim($value_array[0])) > 0) { |
||
66 | $getid3->info['real']['comments'][$key][] = trim($value_array[0]); |
||
67 | } |
||
68 | } |
||
69 | return true; |
||
70 | } |
||
71 | |||
72 | throw new getid3_exception('There was a problem parsing this RealAudio file. Please submit it for analysis to http://www.getid3.org/upload/ or [email protected]'); |
||
73 | } |
||
74 | |||
75 | $getid3->info['real']['chunks'][$chunk_counter] = array (); |
||
76 | $info_real_chunks_current_chunk = &$getid3->info['real']['chunks'][$chunk_counter]; |
||
77 | |||
78 | $info_real_chunks_current_chunk['name'] = $chunk_name; |
||
79 | $info_real_chunks_current_chunk['offset'] = ftell($getid3->fp) - 8; |
||
80 | $info_real_chunks_current_chunk['length'] = $chunk_size; |
||
81 | |||
82 | if (($info_real_chunks_current_chunk['offset'] + $info_real_chunks_current_chunk['length']) > $getid3->info['avdataend']) { |
||
83 | $getid3->warning('Chunk "'.$info_real_chunks_current_chunk['name'].'" at offset '.$info_real_chunks_current_chunk['offset'].' claims to be '.$info_real_chunks_current_chunk['length'].' bytes long, which is beyond end of file'); |
||
84 | return false; |
||
85 | } |
||
86 | |||
87 | if ($chunk_size > (getid3::FREAD_BUFFER_SIZE + 8)) { |
||
88 | $chunk_data .= fread($getid3->fp, getid3::FREAD_BUFFER_SIZE - 8); |
||
89 | fseek($getid3->fp, $info_real_chunks_current_chunk['offset'] + $chunk_size, SEEK_SET); |
||
90 | |||
91 | } elseif(($chunk_size - 8) > 0) { |
||
92 | $chunk_data .= fread($getid3->fp, $chunk_size - 8); |
||
93 | } |
||
94 | $offset = 8; |
||
95 | |||
96 | switch ($chunk_name) { |
||
97 | |||
98 | case '.RMF': // RealMedia File Header |
||
99 | |||
100 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
101 | $offset += 2; |
||
102 | |||
103 | switch ($info_real_chunks_current_chunk['object_version']) { |
||
104 | |||
105 | case 0: |
||
106 | $info_real_chunks_current_chunk['file_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); |
||
107 | $offset += 4; |
||
108 | |||
109 | $info_real_chunks_current_chunk['headers_count'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); |
||
110 | $offset += 4; |
||
111 | break; |
||
112 | |||
113 | default: |
||
114 | //$getid3->warning('Expected .RMF-object_version to be "0", actual value is "'.$info_real_chunks_current_chunk['object_version'].'" (should not be a problem)'; |
||
115 | break; |
||
116 | |||
117 | } |
||
118 | break; |
||
119 | |||
120 | |||
121 | case 'PROP': // Properties Header |
||
122 | |||
123 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
124 | $offset += 2; |
||
125 | |||
126 | if ($info_real_chunks_current_chunk['object_version'] == 0) { |
||
127 | |||
128 | getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, |
||
129 | array ( |
||
130 | 'max_bit_rate' => 4, |
||
131 | 'avg_bit_rate' => 4, |
||
132 | 'max_packet_size' => 4, |
||
133 | 'avg_packet_size' => 4, |
||
134 | 'num_packets' => 4, |
||
135 | 'duration' => 4, |
||
136 | 'preroll' => 4, |
||
137 | 'index_offset' => 4, |
||
138 | 'data_offset' => 4, |
||
139 | 'num_streams' => 2, |
||
140 | 'flags_raw' => 2 |
||
141 | ) |
||
142 | ); |
||
143 | $offset += 40; |
||
144 | |||
145 | $getid3->info['playtime_seconds'] = $info_real_chunks_current_chunk['duration'] / 1000; |
||
146 | if ($info_real_chunks_current_chunk['duration'] > 0) { |
||
147 | $getid3->info['bitrate'] += $info_real_chunks_current_chunk['avg_bit_rate']; |
||
148 | } |
||
149 | |||
150 | $info_real_chunks_current_chunk['flags']['save_enabled'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0001); |
||
151 | $info_real_chunks_current_chunk['flags']['perfect_play'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0002); |
||
152 | $info_real_chunks_current_chunk['flags']['live_broadcast'] = (bool)($info_real_chunks_current_chunk['flags_raw'] & 0x0004); |
||
153 | } |
||
154 | break; |
||
155 | |||
156 | |||
157 | case 'MDPR': // Media Properties Header |
||
158 | |||
159 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
160 | $offset += 2; |
||
161 | |||
162 | if ($info_real_chunks_current_chunk['object_version'] == 0) { |
||
163 | |||
164 | getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, |
||
165 | array ( |
||
166 | 'stream_number' => 2, |
||
167 | 'max_bit_rate' => 4, |
||
168 | 'avg_bit_rate' => 4, |
||
169 | 'max_packet_size' => 4, |
||
170 | 'avg_packet_size' => 4, |
||
171 | 'start_time' => 4, |
||
172 | 'preroll' => 4, |
||
173 | 'duration' => 4, |
||
174 | 'stream_name_size' => 1 |
||
175 | ) |
||
176 | ); |
||
177 | $offset += 31; |
||
178 | |||
179 | $info_real_chunks_current_chunk['stream_name'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['stream_name_size']); |
||
180 | $offset += $info_real_chunks_current_chunk['stream_name_size']; |
||
181 | |||
182 | $info_real_chunks_current_chunk['mime_type_size'] = getid3_lib::BigEndian2Int($chunk_data{$offset++}); |
||
183 | |||
184 | $info_real_chunks_current_chunk['mime_type'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['mime_type_size']); |
||
185 | $offset += $info_real_chunks_current_chunk['mime_type_size']; |
||
186 | |||
187 | $info_real_chunks_current_chunk['type_specific_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 4)); |
||
188 | $offset += 4; |
||
189 | |||
190 | $info_real_chunks_current_chunk['type_specific_data'] = substr($chunk_data, $offset, $info_real_chunks_current_chunk['type_specific_len']); |
||
191 | $offset += $info_real_chunks_current_chunk['type_specific_len']; |
||
192 | |||
193 | $info_real_chunks_current_chunk_typespecificdata = &$info_real_chunks_current_chunk['type_specific_data']; |
||
194 | |||
195 | switch ($info_real_chunks_current_chunk['mime_type']) { |
||
196 | |||
197 | case 'video/x-pn-realvideo': |
||
198 | case 'video/x-pn-multirate-realvideo': |
||
199 | // http://www.freelists.org/archives/matroska-devel/07-2003/msg00010.html |
||
200 | |||
201 | $info_real_chunks_current_chunk['video_info'] = array (); |
||
202 | $info_real_chunks_current_chunk_video_info = &$info_real_chunks_current_chunk['video_info']; |
||
203 | |||
204 | getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk_video_info, $info_real_chunks_current_chunk_typespecificdata, 0, |
||
205 | array ( |
||
206 | 'dwSize' => 4, |
||
207 | 'fourcc1' => -4, |
||
208 | 'fourcc2' => -4, |
||
209 | 'width' => 2, |
||
210 | 'height' => 2, |
||
211 | 'bits_per_sample' => 2, |
||
212 | 'IGNORE-unknown1' => 2, |
||
213 | 'IGNORE-unknown2' => 2, |
||
214 | 'frames_per_second' => 2, |
||
215 | 'IGNORE-unknown3' => 2, |
||
216 | 'IGNORE-unknown4' => 2, |
||
217 | 'IGNORE-unknown5' => 2, |
||
218 | 'IGNORE-unknown6' => 2, |
||
219 | 'IGNORE-unknown7' => 2, |
||
220 | 'IGNORE-unknown8' => 2, |
||
221 | 'IGNORE-unknown9' => 2 |
||
222 | ) |
||
223 | ); |
||
224 | |||
225 | $info_real_chunks_current_chunk_video_info['codec'] = getid3_riff::RIFFfourccLookup($info_real_chunks_current_chunk_video_info['fourcc2']); |
||
226 | |||
227 | $getid3->info['video']['resolution_x'] = $info_real_chunks_current_chunk_video_info['width']; |
||
228 | $getid3->info['video']['resolution_y'] = $info_real_chunks_current_chunk_video_info['height']; |
||
229 | $getid3->info['video']['frame_rate'] = (float)$info_real_chunks_current_chunk_video_info['frames_per_second']; |
||
230 | $getid3->info['video']['codec'] = $info_real_chunks_current_chunk_video_info['codec']; |
||
231 | $getid3->info['video']['bits_per_sample'] = $info_real_chunks_current_chunk_video_info['bits_per_sample']; |
||
232 | break; |
||
233 | |||
234 | |||
235 | case 'audio/x-pn-realaudio': |
||
236 | case 'audio/x-pn-multirate-realaudio': |
||
237 | |||
238 | $this->ParseOldRAheader($info_real_chunks_current_chunk_typespecificdata, $info_real_chunks_current_chunk['parsed_audio_data']); |
||
239 | |||
240 | $getid3->info['audio']['sample_rate'] = $info_real_chunks_current_chunk['parsed_audio_data']['sample_rate']; |
||
241 | $getid3->info['audio']['bits_per_sample'] = $info_real_chunks_current_chunk['parsed_audio_data']['bits_per_sample']; |
||
242 | $getid3->info['audio']['channels'] = $info_real_chunks_current_chunk['parsed_audio_data']['channels']; |
||
243 | |||
244 | if (!empty($getid3->info['audio']['dataformat'])) { |
||
245 | foreach ($getid3->info['audio'] as $key => $value) { |
||
246 | if ($key != 'streams') { |
||
247 | $getid3->info['audio']['streams'][$info_real_chunks_current_chunk['stream_number']][$key] = $value; |
||
248 | } |
||
249 | } |
||
250 | } |
||
251 | break; |
||
252 | |||
253 | |||
254 | case 'logical-fileinfo': |
||
255 | |||
256 | $info_real_chunks_current_chunk['logical_fileinfo']['logical_fileinfo_length'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 0, 4)); |
||
257 | // $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown1'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 4, 4)); |
||
258 | $info_real_chunks_current_chunk['logical_fileinfo']['num_tags'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 8, 4)); |
||
259 | // $info_real_chunks_current_chunk['logical_fileinfo']['IGNORE-unknown2'] = getid3_lib::BigEndian2Int(substr($info_real_chunks_current_chunk_typespecificdata, 12, 4)); |
||
260 | break; |
||
261 | |||
262 | } |
||
263 | |||
264 | |||
265 | if (empty($getid3->info['playtime_seconds'])) { |
||
266 | $getid3->info['playtime_seconds'] = max($getid3->info['playtime_seconds'], ($info_real_chunks_current_chunk['duration'] + $info_real_chunks_current_chunk['start_time']) / 1000); |
||
267 | } |
||
268 | |||
269 | if ($info_real_chunks_current_chunk['duration'] > 0) { |
||
270 | |||
271 | switch ($info_real_chunks_current_chunk['mime_type']) { |
||
272 | |||
273 | case 'audio/x-pn-realaudio': |
||
274 | case 'audio/x-pn-multirate-realaudio': |
||
275 | |||
276 | $getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; |
||
277 | $getid3->info['audio']['codec'] = $this->RealAudioCodecFourCClookup($info_real_chunks_current_chunk['parsed_audio_data']['fourcc'], $getid3->info['audio']['bitrate']); |
||
278 | $getid3->info['audio']['dataformat'] = 'real'; |
||
279 | $getid3->info['audio']['lossless'] = false; |
||
280 | break; |
||
281 | |||
282 | |||
283 | case 'video/x-pn-realvideo': |
||
284 | case 'video/x-pn-multirate-realvideo': |
||
285 | |||
286 | $getid3->info['video']['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; |
||
287 | $getid3->info['video']['bitrate_mode'] = 'cbr'; |
||
288 | $getid3->info['video']['dataformat'] = 'real'; |
||
289 | $getid3->info['video']['lossless'] = false; |
||
290 | $getid3->info['video']['pixel_aspect_ratio'] = (float)1; |
||
291 | break; |
||
292 | |||
293 | |||
294 | case 'audio/x-ralf-mpeg4-generic': |
||
295 | |||
296 | $getid3->info['audio']['bitrate'] = (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0) + $info_real_chunks_current_chunk['avg_bit_rate']; |
||
297 | $getid3->info['audio']['codec'] = 'RealAudio Lossless'; |
||
298 | $getid3->info['audio']['dataformat'] = 'real'; |
||
299 | $getid3->info['audio']['lossless'] = true; |
||
300 | break; |
||
301 | |||
302 | } |
||
303 | |||
304 | $getid3->info['bitrate'] = (isset($getid3->info['video']['bitrate']) ? $getid3->info['video']['bitrate'] : 0) + (isset($getid3->info['audio']['bitrate']) ? $getid3->info['audio']['bitrate'] : 0); |
||
305 | } |
||
306 | } |
||
307 | break; |
||
308 | |||
309 | |||
310 | case 'CONT': // Content Description Header (text comments) |
||
311 | |||
312 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
313 | $offset += 2; |
||
314 | |||
315 | if ($info_real_chunks_current_chunk['object_version'] == 0) { |
||
316 | |||
317 | $info_real_chunks_current_chunk['title_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
318 | $offset += 2; |
||
319 | |||
320 | $info_real_chunks_current_chunk['title'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['title_len']); |
||
321 | $offset += $info_real_chunks_current_chunk['title_len']; |
||
322 | |||
323 | $info_real_chunks_current_chunk['artist_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
324 | $offset += 2; |
||
325 | |||
326 | $info_real_chunks_current_chunk['artist'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['artist_len']); |
||
327 | $offset += $info_real_chunks_current_chunk['artist_len']; |
||
328 | |||
329 | $info_real_chunks_current_chunk['copyright_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
330 | $offset += 2; |
||
331 | |||
332 | $info_real_chunks_current_chunk['copyright'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['copyright_len']); |
||
333 | $offset += $info_real_chunks_current_chunk['copyright_len']; |
||
334 | |||
335 | $info_real_chunks_current_chunk['comment_len'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
336 | $offset += 2; |
||
337 | |||
338 | $info_real_chunks_current_chunk['comment'] = (string) substr($chunk_data, $offset, $info_real_chunks_current_chunk['comment_len']); |
||
339 | $offset += $info_real_chunks_current_chunk['comment_len']; |
||
340 | |||
341 | foreach (array ('title'=>'title', 'artist'=>'artist', 'copyright'=>'copyright', 'comment'=>'comment') as $key => $val) { |
||
342 | if ($info_real_chunks_current_chunk[$key]) { |
||
343 | $getid3->info['real']['comments'][$val][] = trim($info_real_chunks_current_chunk[$key]); |
||
344 | } |
||
345 | } |
||
346 | } |
||
347 | break; |
||
348 | |||
349 | |||
350 | case 'DATA': // Data Chunk Header |
||
351 | |||
352 | // do nothing |
||
353 | break; |
||
354 | |||
355 | |||
356 | case 'INDX': // Index Section Header |
||
357 | |||
358 | $info_real_chunks_current_chunk['object_version'] = getid3_lib::BigEndian2Int(substr($chunk_data, $offset, 2)); |
||
359 | $offset += 2; |
||
360 | |||
361 | if ($info_real_chunks_current_chunk['object_version'] == 0) { |
||
362 | |||
363 | getid3_lib::ReadSequence('BigEndian2Int', $info_real_chunks_current_chunk, $chunk_data, $offset, |
||
364 | array ( |
||
365 | 'num_indices' => 4, |
||
366 | 'stream_number' => 2, |
||
367 | 'next_index_header' => 4 |
||
368 | ) |
||
369 | ); |
||
370 | $offset += 10; |
||
371 | |||
372 | if ($info_real_chunks_current_chunk['next_index_header'] == 0) { |
||
373 | // last index chunk found, ignore rest of file |
||
374 | break 2; |
||
375 | } else { |
||
376 | // non-last index chunk, seek to next index chunk (skipping actual index data) |
||
377 | fseek($getid3->fp, $info_real_chunks_current_chunk['next_index_header'], SEEK_SET); |
||
378 | } |
||
379 | } |
||
380 | break; |
||
381 | |||
382 | |||
383 | default: |
||
384 | $getid3->warning('Unhandled RealMedia chunk "'.$chunk_name.'" at offset '.$info_real_chunks_current_chunk['offset']); |
||
385 | break; |
||
386 | } |
||
387 | $chunk_counter++; |
||
388 | } |
||
389 | |||
390 | if (!empty($getid3->info['audio']['streams'])) { |
||
391 | |||
392 | $getid3->info['audio']['bitrate'] = 0; |
||
393 | |||
394 | foreach ($getid3->info['audio']['streams'] as $key => $value_array) { |
||
395 | $getid3->info['audio']['bitrate'] += $value_array['bitrate']; |
||
396 | } |
||
397 | } |
||
398 | |||
399 | return true; |
||
400 | } |
||
401 | |||
591 | ?> |
||
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.