| Conditions | 21 |
| Paths | 1571 |
| Total Lines | 86 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 14 | ||
| Bugs | 3 | Features | 2 |
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 |
||
| 166 | public function create(array $args = array()) |
||
| 167 | { |
||
| 168 | if (!isset($args['build']) || !($args['build'] instanceof Interfaces\Package\Build)) { |
||
| 169 | throw new \Exception("Invalid or NULL object passed as Interfaces\Package\Build"); |
||
| 170 | } |
||
| 171 | $this->build = $build = $args['build']; |
||
| 172 | |||
| 173 | $info = $build->getInfo(); |
||
| 174 | |||
| 175 | $tmp_dir = $build->getTempDir(); |
||
| 176 | |||
| 177 | $tmp = $build->getLog('configure'); |
||
| 178 | if (preg_match(",Build dir:\s+([\:\-\.0-9a-zA-Z\\\\_]+),", $tmp, $m)) { |
||
| 179 | if (preg_match(",^[a-z]\:\\\\,i", $m[1]) && is_dir($m[1])) { |
||
| 180 | /* Parsed the fully qualified path */ |
||
| 181 | $build_dir = $m[1]; |
||
| 182 | } else { |
||
| 183 | /* otherwise construct */ |
||
| 184 | $build_dir = $tmp_dir.DIRECTORY_SEPARATOR.$m[1]; |
||
| 185 | } |
||
| 186 | } else { |
||
| 187 | $build_dir = 'x86' == $info['arch'] ? $tmp_dir : $tmp_dir.DIRECTORY_SEPARATOR.'x64'; |
||
| 188 | $build_dir .= DIRECTORY_SEPARATOR.($is_release ? 'Release' : 'Debug'); |
||
| 189 | $build_dir .= ($info['thread_safe'] ? '_TS' : ''); |
||
| 190 | } |
||
| 191 | |||
| 192 | /* Various file paths to pack. */ |
||
| 193 | $composer_json = $this->pkg->getRootDir().DIRECTORY_SEPARATOR.'composer.json'; |
||
| 194 | |||
| 195 | if (file_exists($tmp_dir.DIRECTORY_SEPARATOR.'LICENSE')) { |
||
| 196 | $license = $tmp_dir.DIRECTORY_SEPARATOR.'LICENSE'; |
||
| 197 | } elseif (file_exists($tmp_dir.DIRECTORY_SEPARATOR.'COPYING')) { |
||
| 198 | $license = $tmp_dir.DIRECTORY_SEPARATOR.'COPYING'; |
||
| 199 | } elseif (file_exists($tmp_dir.DIRECTORY_SEPARATOR.'LICENSE.md')) { |
||
| 200 | $license = $tmp_dir.DIRECTORY_SEPARATOR.'LICENSE.md'; |
||
| 201 | } elseif (file_exists($tmp_dir.DIRECTORY_SEPARATOR.'COPYING.md')) { |
||
| 202 | $license = $tmp_dir.DIRECTORY_SEPARATOR.'COPYING.md'; |
||
| 203 | } else { |
||
| 204 | throw new \Exception("Couldn't find LICENSE"); |
||
| 205 | } |
||
| 206 | |||
| 207 | $readme = null; |
||
| 208 | if (file_exists($tmp_dir.DIRECTORY_SEPARATOR.'README')) { |
||
| 209 | $readme = $tmp_dir.DIRECTORY_SEPARATOR.'README'; |
||
| 210 | } elseif (file_exists($tmp_dir.DIRECTORY_SEPARATOR.'README.md')) { |
||
| 211 | $readme = $tmp_dir.DIRECTORY_SEPARATOR.'README.md'; |
||
| 212 | } |
||
| 213 | |||
| 214 | /* pack the outcome */ |
||
| 215 | $zip_name = $this->getZipBaseName($build).'.zip'; |
||
| 216 | |||
| 217 | $zip = new \ZipArchive(); |
||
| 218 | if (!$zip->open($zip_name, \ZipArchive::CREATE | \ZipArchive::OVERWRITE)) { |
||
| 219 | throw new \Exception("Failed to open '$zip_name' for writing"); |
||
| 220 | } |
||
| 221 | |||
| 222 | $ext_dll_found = false; |
||
| 223 | $ext_names = $this->getMultiExtensionNames(); |
||
| 224 | foreach ($ext_names as $ext_name) { |
||
| 225 | $dll_name = 'php_'.$ext_name.'.dll'; |
||
| 226 | $dll_file = $build_dir.DIRECTORY_SEPARATOR.$dll_name; |
||
| 227 | |||
| 228 | if (!file_exists($dll_file)) { |
||
| 229 | continue; |
||
| 230 | } |
||
| 231 | $ext_dll_found = true; |
||
| 232 | $zip->addFile($dll_file, $dll_name); |
||
| 233 | |||
| 234 | $pdb_name = 'php_'.$ext_name.'.pdb'; |
||
| 235 | $pdb_file = $build_dir.DIRECTORY_SEPARATOR.$pdb_name; |
||
| 236 | if (file_exists($pdb_file)) { |
||
| 237 | $zip->addFile($pdb_file, $pdb_name); |
||
| 238 | } |
||
| 239 | } |
||
| 240 | |||
| 241 | if (!$ext_dll_found) { |
||
| 242 | throw new \Exception("Couldn't find extension DLL"); |
||
| 243 | } |
||
| 244 | |||
| 245 | $zip->addFile($composer_json, basename($composer_json)); |
||
| 246 | $zip->addFile($license, basename($license)); |
||
| 247 | if ($readme) { |
||
| 248 | $zip->addFile($readme, basename($readme)); |
||
| 249 | } |
||
| 250 | $zip->close(); |
||
| 251 | } |
||
| 252 | |||
| 288 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.