| Conditions | 6 |
| Paths | 13 |
| Total Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 25 | public function Analyze() { |
||
| 26 | $info = &$this->getid3->info; |
||
| 27 | |||
| 28 | $info['fileformat'] = 'ivf'; |
||
| 29 | $info['video']['dataformat'] = 'ivf'; |
||
| 30 | |||
| 31 | $this->fseek($info['avdataoffset']); |
||
| 32 | $IVFheader = $this->fread(32); |
||
| 33 | |||
| 34 | if (substr($IVFheader, 0, 4) == 'DKIF') { |
||
| 35 | |||
| 36 | // https://wiki.multimedia.cx/index.php/IVF |
||
| 37 | $info['ivf']['header']['signature'] = substr($IVFheader, 0, 4); |
||
| 38 | $info['ivf']['header']['version'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 4, 2)); // should be 0 |
||
| 39 | $info['ivf']['header']['headersize'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 6, 2)); |
||
| 40 | $info['ivf']['header']['fourcc'] = substr($IVFheader, 8, 4); |
||
| 41 | $info['ivf']['header']['resolution_x'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 12, 2)); |
||
| 42 | $info['ivf']['header']['resolution_y'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 14, 2)); |
||
| 43 | $info['ivf']['header']['timebase_numerator'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 16, 4)); |
||
| 44 | $info['ivf']['header']['timebase_denominator'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 20, 4)); |
||
| 45 | $info['ivf']['header']['frame_count'] = getid3_lib::LittleEndian2Int(substr($IVFheader, 24, 4)); |
||
| 46 | //$info['ivf']['header']['reserved'] = substr($IVFheader, 28, 4); |
||
| 47 | |||
| 48 | $info['ivf']['header']['frame_rate'] = (float) $info['ivf']['header']['timebase_numerator'] / $info['ivf']['header']['timebase_denominator']; |
||
| 49 | |||
| 50 | if ($info['ivf']['header']['version'] > 0) { |
||
| 51 | $this->warning('Expecting IVF header version 0, found version '.$info['ivf']['header']['version'].', results may not be accurate'); |
||
| 52 | } |
||
| 53 | |||
| 54 | $info['video']['resolution_x'] = $info['ivf']['header']['resolution_x']; |
||
| 55 | $info['video']['resolution_y'] = $info['ivf']['header']['resolution_y']; |
||
| 56 | $info['video']['codec'] = $info['ivf']['header']['fourcc']; |
||
| 57 | |||
| 58 | $info['ivf']['frame_count'] = 0; |
||
| 59 | while (!$this->feof()) { |
||
| 60 | if ($frameheader = $this->fread(12)) { |
||
| 61 | $framesize = getid3_lib::LittleEndian2Int(substr($frameheader, 0, 4)); // size of frame in bytes (not including the 12-byte header) |
||
| 62 | $timestamp = getid3_lib::LittleEndian2Int(substr($frameheader, 4, 8)); // 64-bit presentation timestamp |
||
| 63 | $this->fseek($framesize, SEEK_CUR); |
||
|
|
|||
| 64 | $info['ivf']['frame_count']++; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | if ($info['ivf']['frame_count']) { |
||
| 68 | $info['playtime_seconds'] = $timestamp / 100000; |
||
| 69 | $info['video']['frame_rate'] = (float) $info['ivf']['frame_count'] / $info['playtime_seconds']; |
||
| 70 | } |
||
| 71 | |||
| 72 | } else { |
||
| 73 | $this->error('Expecting "DKIF" at offset '.$info['avdataoffset'].', found "'.getid3_lib::PrintHexBytes(substr($IVFheader, 0, 4)).'"'); |
||
| 74 | return false; |
||
| 75 | } |
||
| 76 | |||
| 77 | return true; |
||
| 78 | } |
||
| 79 | |||
| 81 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.