Conditions | 20 |
Paths | 1451 |
Total Lines | 80 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 12 | ||
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 |
||
90 | public function create(array $args = []) |
||
91 | { |
||
92 | if (!isset($args['build']) || !($args['build'] instanceof Interfaces\Package\Build)) { |
||
93 | throw new Exception('Invalid or NULL object passed as Interfaces\\Package\\Build'); |
||
94 | } |
||
95 | $this->build = $build = $args['build']; |
||
96 | |||
97 | $info = $build->getInfo(); |
||
98 | |||
99 | $tmp_dir = $build->getTempDir(); |
||
|
|||
100 | |||
101 | $tmp = $build->getLog('configure'); |
||
102 | $m = null; |
||
103 | if (preg_match(',Build dir:\\s+([\\:\\-\\.0-9a-zA-Z\\\\_]+),', $tmp, $m)) { |
||
104 | if (preg_match(',^[a-z]\\:\\\\,i', $m[1]) && is_dir($m[1])) { |
||
105 | /* Parsed the fully qualified path */ |
||
106 | $build_dir = $m[1]; |
||
107 | } else { |
||
108 | /* otherwise construct */ |
||
109 | $build_dir = $tmp_dir . DIRECTORY_SEPARATOR . $m[1]; |
||
110 | } |
||
111 | } else { |
||
112 | $build_dir = $info['arch'] == 'x86' ? $tmp_dir : $tmp_dir . DIRECTORY_SEPARATOR . 'x64'; |
||
113 | $build_dir .= DIRECTORY_SEPARATOR . (($info['is_release'] ?? true) ? 'Release' : 'Debug'); |
||
114 | $build_dir .= ($info['thread_safe'] ? '_TS' : ''); |
||
115 | } |
||
116 | |||
117 | /* Various file paths to pack. */ |
||
118 | $composer_json = $this->pkg->getRootDir() . DIRECTORY_SEPARATOR . 'composer.json'; |
||
119 | |||
120 | if (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'LICENSE')) { |
||
121 | $license = $tmp_dir . DIRECTORY_SEPARATOR . 'LICENSE'; |
||
122 | } elseif (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'COPYING')) { |
||
123 | $license = $tmp_dir . DIRECTORY_SEPARATOR . 'COPYING'; |
||
124 | } elseif (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'LICENSE.md')) { |
||
125 | $license = $tmp_dir . DIRECTORY_SEPARATOR . 'LICENSE.md'; |
||
126 | } elseif (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'COPYING.md')) { |
||
127 | $license = $tmp_dir . DIRECTORY_SEPARATOR . 'COPYING.md'; |
||
128 | } else { |
||
129 | throw new Exception("Couldn't find LICENSE"); |
||
130 | } |
||
131 | |||
132 | $readme = null; |
||
133 | if (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'README')) { |
||
134 | $readme = $tmp_dir . DIRECTORY_SEPARATOR . 'README'; |
||
135 | } elseif (file_exists($tmp_dir . DIRECTORY_SEPARATOR . 'README.md')) { |
||
136 | $readme = $tmp_dir . DIRECTORY_SEPARATOR . 'README.md'; |
||
137 | } |
||
138 | |||
139 | /* pack the outcome */ |
||
140 | $zip_name = $this->getZipBaseName($build) . '.zip'; |
||
141 | |||
142 | $zipClass = Archive\Factory::getZipperClassName(); |
||
143 | $zip = new $zipClass($zip_name, Interfaces\Archive\Zipper::FLAG_CREATE_OVERWRITE); |
||
144 | /** @var \Pickle\Base\Interfaces\Archive\Zipper $zip */ |
||
145 | $ext_dll_found = false; |
||
146 | $ext_names = $this->getMultiExtensionNames(); |
||
147 | foreach ($ext_names as $ext_name) { |
||
148 | $dll_file = $build_dir . DIRECTORY_SEPARATOR . 'php_' . $ext_name . '.dll'; |
||
149 | |||
150 | if (!file_exists($dll_file)) { |
||
151 | continue; |
||
152 | } |
||
153 | $ext_dll_found = true; |
||
154 | $zip->addFileWithoutPath($dll_file); |
||
155 | |||
156 | $pdb_file = $build_dir . DIRECTORY_SEPARATOR . 'php_' . $ext_name . '.pdb'; |
||
157 | if (file_exists($pdb_file)) { |
||
158 | $zip->addFileWithoutPath($pdb_file); |
||
159 | } |
||
160 | } |
||
161 | |||
162 | if (!$ext_dll_found) { |
||
163 | throw new Exception("Couldn't find extension DLL"); |
||
164 | } |
||
165 | |||
166 | $zip->addFileWithoutPath($composer_json); |
||
167 | $zip->addFileWithoutPath($license); |
||
168 | if ($readme) { |
||
169 | $zip->addFileWithoutPath($readme); |
||
170 | } |
||
255 |