| Conditions | 17 |
| Paths | 201 |
| Total Lines | 111 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 | function Analyze() { |
||
|
|
|||
| 32 | |||
| 33 | $info = &$this->getid3->info; |
||
| 34 | |||
| 35 | $info['fileformat'] = 'tar'; |
||
| 36 | |||
| 37 | $fp = $this->getid3->fp; |
||
| 38 | |||
| 39 | fseek($fp, 0); |
||
| 40 | |||
| 41 | $unpack_header = 'a100fname/a8mode/a8uid/a8gid/a12size/a12mtime/a8chksum/a1typflag/a100lnkname/a6magic/a2ver/a32uname/a32gname/a8devmaj/a8devmin/a155/prefix'; |
||
| 42 | |||
| 43 | $null_512k = str_repeat("\0", 512); // end-of-file marker |
||
| 44 | |||
| 45 | $already_warned = false; |
||
| 46 | |||
| 47 | while (!feof($fp)) { |
||
| 48 | |||
| 49 | $buffer = fread($fp, 512); |
||
| 50 | |||
| 51 | // check the block |
||
| 52 | $checksum = 0; |
||
| 53 | for ($i = 0; $i < 148; $i++) { |
||
| 54 | $checksum += ord(substr($buffer, $i, 1)); |
||
| 55 | } |
||
| 56 | for ($i = 148; $i < 156; $i++) { |
||
| 57 | $checksum += ord(' '); |
||
| 58 | } |
||
| 59 | for ($i = 156; $i < 512; $i++) { |
||
| 60 | $checksum += ord(substr($buffer, $i, 1)); |
||
| 61 | } |
||
| 62 | $attr = unpack($unpack_header, $buffer); |
||
| 63 | $name = trim(@$attr['fname']); |
||
| 64 | $mode = octdec(trim(@$attr['mode'])); |
||
| 65 | $uid = octdec(trim(@$attr['uid'])); |
||
| 66 | $gid = octdec(trim(@$attr['gid'])); |
||
| 67 | $size = octdec(trim(@$attr['size'])); |
||
| 68 | $mtime = octdec(trim(@$attr['mtime'])); |
||
| 69 | $chksum = octdec(trim(@$attr['chksum'])); |
||
| 70 | $typflag = trim(@$attr['typflag']); |
||
| 71 | $lnkname = trim(@$attr['lnkname']); |
||
| 72 | $magic = trim(@$attr['magic']); |
||
| 73 | $ver = trim(@$attr['ver']); |
||
| 74 | $uname = trim(@$attr['uname']); |
||
| 75 | $gname = trim(@$attr['gname']); |
||
| 76 | $devmaj = octdec(trim(@$attr['devmaj'])); |
||
| 77 | $devmin = octdec(trim(@$attr['devmin'])); |
||
| 78 | $prefix = trim(@$attr['prefix']); |
||
| 79 | |||
| 80 | // EOF Found |
||
| 81 | if (($checksum == 256) && ($chksum == 0)) { |
||
| 82 | break; |
||
| 83 | } |
||
| 84 | |||
| 85 | // Check if filename if 7bit as spec requires |
||
| 86 | if (!$already_warned) { |
||
| 87 | for ($i = 0; $i < strlen($name); $i++) { |
||
| 88 | if ($name{$i} < chr(32) || $name{$i} > chr(127)) { |
||
| 89 | $this->getid3->warning('Some filenames contains extended characters, which breaks the tar specifation. This is not uncommon, but you will have to handle the character encoding for filenames yourself.'); |
||
| 90 | $already_warned = true; |
||
| 91 | break; |
||
| 92 | } |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | if ($prefix) { |
||
| 97 | $name = $prefix.'/'.$name; |
||
| 98 | } |
||
| 99 | if ((preg_match('#/$#', $name)) && !$name) { |
||
| 100 | $typeflag = 5; |
||
| 101 | } |
||
| 102 | |||
| 103 | // If it's the end of the tar-file... |
||
| 104 | if ($buffer == $null_512k) { |
||
| 105 | break; |
||
| 106 | } |
||
| 107 | |||
| 108 | // Protect against tar-files with garbage at the end |
||
| 109 | if ($name == '') { |
||
| 110 | break; |
||
| 111 | } |
||
| 112 | |||
| 113 | $info['tar']['file_details'][$name] = array ( |
||
| 114 | 'name' => $name, |
||
| 115 | 'mode_raw' => $mode, |
||
| 116 | 'mode' => getid3_tar::display_perms($mode), |
||
| 117 | 'uid' => $uid, |
||
| 118 | 'gid' => $gid, |
||
| 119 | 'size' => $size, |
||
| 120 | 'mtime' => $mtime, |
||
| 121 | 'chksum' => $chksum, |
||
| 122 | 'typeflag' => getid3_tar::get_flag_type($typflag), |
||
| 123 | 'linkname' => $lnkname, |
||
| 124 | 'magic' => $magic, |
||
| 125 | 'version' => $ver, |
||
| 126 | 'uname' => $uname, |
||
| 127 | 'gname' => $gname, |
||
| 128 | 'devmajor' => $devmaj, |
||
| 129 | 'devminor' => $devmin |
||
| 130 | ); |
||
| 131 | |||
| 132 | // Skip the next chunk |
||
| 133 | fseek($fp, $size, SEEK_CUR); |
||
| 134 | |||
| 135 | // Throw away padding |
||
| 136 | if ($size % 512) { |
||
| 137 | fseek($fp, 512 - $diff, SEEK_CUR); |
||
| 138 | } |
||
| 139 | |||
| 140 | } |
||
| 141 | return true; |
||
| 142 | } |
||
| 231 | ?> |
||
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.