Conditions | 2 |
Paths | 2 |
Total Lines | 52 |
Code Lines | 42 |
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 |
||
114 | function addFile($data, $name, $time = 0) |
||
115 | { |
||
116 | $name = str_replace('\\', '/', $name); |
||
117 | $hexdtime = pack('V', $this->unix2DosTime($time)); |
||
118 | $fr = "\x50\x4b\x03\x04"; |
||
119 | $fr .= "\x14\x00"; // ver needed to extract |
||
120 | $fr .= "\x00\x00"; // gen purpose bit flag |
||
121 | $fr .= "\x08\x00"; // compression method |
||
122 | $fr .= $hexdtime; // last mod time and date |
||
123 | // "local file header" segment |
||
124 | $unc_len = strlen($data); |
||
125 | $crc = crc32($data); |
||
126 | $zdata = gzcompress($data); |
||
127 | $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); // fix crc bug |
||
128 | $c_len = strlen($zdata); |
||
129 | $fr .= pack('V', $crc); // crc32 |
||
130 | $fr .= pack('V', $c_len); // compressed filesize |
||
131 | $fr .= pack('V', $unc_len); // uncompressed filesize |
||
132 | $fr .= pack('v', strlen($name)); // length of filename |
||
133 | $fr .= pack('v', 0); // extra field length |
||
134 | $fr .= $name; |
||
135 | // "file data" segment |
||
136 | $fr .= $zdata; |
||
137 | // echo this entry on the fly, ... |
||
138 | if ($this->doWrite) { |
||
139 | echo $fr; |
||
140 | } else { // ... OR add this entry to array |
||
141 | $this->datasec[] = $fr; |
||
142 | } |
||
143 | // now add to central directory record |
||
144 | $cdrec = "\x50\x4b\x01\x02"; |
||
145 | $cdrec .= "\x00\x00"; // version made by |
||
146 | $cdrec .= "\x14\x00"; // version needed to extract |
||
147 | $cdrec .= "\x00\x00"; // gen purpose bit flag |
||
148 | $cdrec .= "\x08\x00"; // compression method |
||
149 | $cdrec .= $hexdtime; // last mod time & date |
||
150 | $cdrec .= pack('V', $crc); // crc32 |
||
151 | $cdrec .= pack('V', $c_len); // compressed filesize |
||
152 | $cdrec .= pack('V', $unc_len); // uncompressed filesize |
||
153 | $cdrec .= pack('v', strlen($name)); // length of filename |
||
154 | $cdrec .= pack('v', 0); // extra field length |
||
155 | $cdrec .= pack('v', 0); // file comment length |
||
156 | $cdrec .= pack('v', 0); // disk number start |
||
157 | $cdrec .= pack('v', 0); // internal file attributes |
||
158 | $cdrec .= pack('V', 32); // external file attributes |
||
159 | // - 'archive' bit set |
||
160 | $cdrec .= pack('V', $this->old_offset); // relative offset of local header |
||
161 | $this->old_offset += strlen($fr); |
||
162 | $cdrec .= $name; |
||
163 | // optional extra field, file comment goes here |
||
164 | // save to central directory |
||
165 | $this->ctrl_dir[] = $cdrec; |
||
166 | } |
||
235 |
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.