| Total Complexity | 40 |
| Total Lines | 221 |
| Duplicated Lines | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 0 |
Complex classes like Windows often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Windows, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 44 | class Windows extends Abstracts\Package\Build implements Interfaces\Package\Build |
||
| 45 | { |
||
| 46 | public function prepare() |
||
| 47 | { |
||
| 48 | if (!file_exists('c:\\php-sdk\\bin')) { |
||
| 49 | throw new Exception('PHP SDK not found'); |
||
| 50 | } |
||
| 51 | putenv('path=c:\\php-sdk\\bin;' . getenv('path')); |
||
| 52 | |||
| 53 | if (!$this->runCommand('phpsdk_setvars')) { |
||
| 54 | throw new Exception('phpsdk_setvars failed'); |
||
| 55 | } |
||
| 56 | |||
| 57 | $this->phpize(); |
||
| 58 | } |
||
| 59 | |||
| 60 | public function phpize() |
||
| 61 | { |
||
| 62 | $backCwd = getcwd(); |
||
| 63 | chdir($this->pkg->getSourceDir()); |
||
| 64 | |||
| 65 | $res = $this->runCommand('phpize'); |
||
| 66 | chdir($backCwd); |
||
| 67 | if (!$res) { |
||
| 68 | throw new Exception('phpize failed'); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | public function configure($opts = null) |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | public function make() |
||
| 106 | } |
||
| 107 | } |
||
| 108 | |||
| 109 | public function install() |
||
| 110 | { |
||
| 111 | $backCwd = getcwd(); |
||
| 112 | chdir($this->tempDir); |
||
| 113 | |||
| 114 | /* Record the produced DLL filenames. */ |
||
| 115 | $files = (array) glob('*/*/php_*.dll'); |
||
| 116 | $files = array_merge($files, glob('*/php_*.dll')); |
||
| 117 | $dlls = []; |
||
| 118 | foreach ($files as $file) { |
||
| 119 | $dlls[] = basename($file); |
||
| 120 | } |
||
| 121 | |||
| 122 | $res = $this->runCommand('nmake install'); |
||
| 123 | chdir($backCwd); |
||
| 124 | if (!$res) { |
||
| 125 | throw new Exception('nmake install failed'); |
||
| 126 | } |
||
| 127 | |||
| 128 | $ini = \Pickle\Engine\Ini::factory(Engine::factory()); |
||
| 129 | $ini->updatePickleSection($dlls); |
||
| 130 | } |
||
| 131 | |||
| 132 | public function getInfo() |
||
| 133 | { |
||
| 134 | $info = []; |
||
| 135 | $info = array_merge($info, $this->getInfoFromPhpizeLog()); |
||
| 136 | $info = array_merge($info, $this->getInfoFromConfigureLog()); |
||
| 137 | $m = null; |
||
| 138 | if (!preg_match(',(.+)/(.+),', $info['name'], $m)) { |
||
| 139 | $info['vendor'] = null; |
||
| 140 | } else { |
||
| 141 | $info['name'] = $m[2]; |
||
| 142 | $info['vendor'] = $m[1]; |
||
| 143 | } |
||
| 144 | |||
| 145 | return $info; |
||
| 146 | } |
||
| 147 | |||
| 148 | protected function prepareConfigOpts() |
||
| 170 | } |
||
| 171 | |||
| 172 | protected function getInfoFromPhpizeLog() |
||
| 173 | { |
||
| 174 | $ret = [ |
||
| 175 | 'php_major' => null, |
||
| 176 | 'php_minor' => null, |
||
| 177 | 'php_patch' => null, |
||
| 178 | ]; |
||
| 179 | |||
| 180 | $tmp = $this->getLog('phpize'); |
||
| 181 | $m = null; |
||
| 182 | if (!preg_match(",Rebuilding configure.js[\n\r\\d:]+\\s+(.+)[\n\r]+,", $tmp, $m)) { |
||
| 183 | throw new Exception("Couldn't determine PHP development SDK path"); |
||
| 184 | } |
||
| 185 | $sdk = $m[1]; |
||
| 186 | |||
| 187 | $ver_header = file_get_contents("{$sdk}/include/main/php_version.h"); |
||
| 188 | |||
| 189 | if (!preg_match(',PHP_MAJOR_VERSION\\s+(\\d+),', $ver_header, $m)) { |
||
| 190 | throw new Exception("Couldn't determine PHP_MAJOR_VERSION"); |
||
| 191 | } |
||
| 192 | $ret['php_major'] = $m[1]; |
||
| 193 | |||
| 194 | if (!preg_match(',PHP_MINOR_VERSION\\s+(\\d+),', $ver_header, $m)) { |
||
| 195 | throw new Exception("Couldn't determine PHP_MINOR_VERSION"); |
||
| 196 | } |
||
| 197 | $ret['php_minor'] = $m[1]; |
||
| 198 | |||
| 199 | if (!preg_match(',PHP_RELEASE_VERSION\\s+(\\d+),', $ver_header, $m)) { |
||
| 200 | throw new Exception("Couldn't determine PHP_RELEASE_VERSION"); |
||
| 201 | } |
||
| 202 | $ret['php_patch'] = $m[1]; |
||
| 203 | |||
| 204 | return $ret; |
||
| 205 | } |
||
| 206 | |||
| 207 | protected function getInfoFromConfigureLog() |
||
| 208 | { |
||
| 209 | $info = [ |
||
| 210 | 'thread_safe' => null, |
||
| 211 | 'compiler' => null, |
||
| 212 | 'arch' => null, |
||
| 213 | 'version' => null, |
||
| 214 | 'name' => null, |
||
| 215 | 'is_release' => null, |
||
| 216 | ]; |
||
| 217 | |||
| 218 | $tmp = $this->getLog('configure'); |
||
| 219 | $m = null; |
||
| 220 | if (!preg_match(',Build type\\s+\\|\\s+([a-zA-Z]+),', $tmp, $m)) { |
||
| 221 | throw new Exception("Couldn't determine the build thread safety"); |
||
| 222 | } |
||
| 223 | $info['is_release'] = $m[1] === 'Release'; |
||
| 224 | |||
| 225 | if (!preg_match(',Thread Safety\\s+\\|\\s+([a-zA-Z]+),', $tmp, $m)) { |
||
| 226 | throw new Exception("Couldn't determine the build thread safety"); |
||
| 227 | } |
||
| 228 | $info['thread_safe'] = strtolower($m[1]) == 'yes'; |
||
| 229 | |||
| 230 | if (!preg_match(',Compiler\\s+\\|\\s+MSVC(\\d+),', $tmp, $m)) { |
||
| 231 | throw new Exception('Currently only MSVC is supported'); |
||
| 232 | } |
||
| 233 | $info['compiler'] = 'vc' . $m[1]; |
||
| 234 | |||
| 235 | if (!preg_match(',Architecture\\s+\\|\\s+([a-zA-Z0-9]+),', $tmp, $m)) { |
||
| 236 | throw new Exception("Couldn't determine the build architecture"); |
||
| 237 | } |
||
| 238 | $info['arch'] = $m[1]; |
||
| 239 | |||
| 240 | $info['version'] = $this->getPackage()->getPrettyVersion(); |
||
| 241 | $info['name'] = $this->getPackage()->getName(); |
||
| 242 | |||
| 243 | return $info; |
||
| 244 | } |
||
| 245 | |||
| 246 | /** |
||
| 247 | * @param string $src |
||
| 248 | */ |
||
| 249 | private function copySrcDir($src, $dest) |
||
| 265 | } |
||
| 266 | } |
||
| 267 | } |
||
| 268 | } |
||
| 272 |