| Conditions | 17 |
| Paths | 96 |
| Total Lines | 80 |
| Code 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 |
||
| 113 | static function go($return = false) |
||
|
|
|||
| 114 | { |
||
| 115 | $fp = fopen(__FILE__, 'rb'); |
||
| 116 | fseek($fp, self::LEN); |
||
| 117 | $L = unpack('V', $a = fread($fp, 4)); |
||
| 118 | $m = ''; |
||
| 119 | |||
| 120 | do { |
||
| 121 | $read = 8192; |
||
| 122 | if ($L[1] - strlen($m) < 8192) { |
||
| 123 | $read = $L[1] - strlen($m); |
||
| 124 | } |
||
| 125 | $last = fread($fp, $read); |
||
| 126 | $m .= $last; |
||
| 127 | } while (strlen($last) && strlen($m) < $L[1]); |
||
| 128 | |||
| 129 | if (strlen($m) < $L[1]) { |
||
| 130 | die('ERROR: manifest length read was "' . |
||
| 131 | strlen($m) .'" should be "' . |
||
| 132 | $L[1] . '"'); |
||
| 133 | } |
||
| 134 | |||
| 135 | $info = self::_unpack($m); |
||
| 136 | $f = $info['c']; |
||
| 137 | |||
| 138 | if ($f & self::GZ) { |
||
| 139 | if (!function_exists('gzinflate')) { |
||
| 140 | die('Error: zlib extension is not enabled -' . |
||
| 141 | ' gzinflate() function needed for zlib-compressed .phars'); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | if ($f & self::BZ2) { |
||
| 146 | if (!function_exists('bzdecompress')) { |
||
| 147 | die('Error: bzip2 extension is not enabled -' . |
||
| 148 | ' bzdecompress() function needed for bz2-compressed .phars'); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | $temp = self::tmpdir(); |
||
| 153 | |||
| 154 | if (!$temp || !is_writable($temp)) { |
||
| 155 | $sessionpath = session_save_path(); |
||
| 156 | if (strpos ($sessionpath, ";") !== false) |
||
| 157 | $sessionpath = substr ($sessionpath, strpos ($sessionpath, ";")+1); |
||
| 158 | if (!file_exists($sessionpath) || !is_dir($sessionpath)) { |
||
| 159 | die('Could not locate temporary directory to extract phar'); |
||
| 160 | } |
||
| 161 | $temp = $sessionpath; |
||
| 162 | } |
||
| 163 | |||
| 164 | $temp .= '/pharextract/'.basename(__FILE__, '.phar'); |
||
| 165 | self::$temp = $temp; |
||
| 166 | self::$origdir = getcwd(); |
||
| 167 | @mkdir($temp, 0777, true); |
||
| 168 | $temp = realpath($temp); |
||
| 169 | |||
| 170 | if (!file_exists($temp . DIRECTORY_SEPARATOR . md5_file(__FILE__))) { |
||
| 171 | self::_removeTmpFiles($temp, getcwd()); |
||
| 172 | @mkdir($temp, 0777, true); |
||
| 173 | @file_put_contents($temp . '/' . md5_file(__FILE__), ''); |
||
| 174 | |||
| 175 | foreach ($info['m'] as $path => $file) { |
||
| 176 | $a = !file_exists(dirname($temp . '/' . $path)); |
||
| 177 | @mkdir(dirname($temp . '/' . $path), 0777, true); |
||
| 178 | clearstatcache(); |
||
| 179 | |||
| 180 | if ($path[strlen($path) - 1] == '/') { |
||
| 181 | @mkdir($temp . '/' . $path, 0777); |
||
| 182 | } else { |
||
| 183 | file_put_contents($temp . '/' . $path, self::extractFile($path, $file, $fp)); |
||
| 184 | @chmod($temp . '/' . $path, 0666); |
||
| 185 | } |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | chdir($temp); |
||
| 190 | |||
| 191 | if (!$return) { |
||
| 192 | include self::START; |
||
| 193 | } |
||
| 293 |
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.