Conditions | 27 |
Paths | 3623 |
Total Lines | 139 |
Code Lines | 83 |
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 |
||
219 | public function main() |
||
220 | { |
||
221 | $project = $this->getProject(); |
||
222 | |||
223 | $ftp = new \Net_FTP($this->host, $this->port); |
||
224 | if ($this->ssl) { |
||
225 | $ret = $ftp->setSsl(); |
||
226 | if (@\PEAR::isError($ret)) { |
||
227 | throw new BuildException( |
||
228 | 'SSL connection not supported by php: ' . $ret->getMessage() |
||
229 | ); |
||
230 | } |
||
231 | |||
232 | $this->log('Use SSL connection', $this->logLevel); |
||
233 | } |
||
234 | $ret = $ftp->connect(); |
||
235 | if (@\PEAR::isError($ret)) { |
||
236 | throw new BuildException( |
||
237 | 'Could not connect to FTP server ' . $this->host . ' on port ' . $this->port . ': ' . $ret->getMessage() |
||
238 | ); |
||
239 | } |
||
240 | |||
241 | $this->log('Connected to FTP server ' . $this->host . ' on port ' . $this->port, $this->logLevel); |
||
242 | |||
243 | $ret = $ftp->login($this->username, $this->password); |
||
244 | if (@\PEAR::isError($ret)) { |
||
245 | throw new BuildException( |
||
246 | 'Could not login to FTP server ' . $this->host . ' on port ' . $this->port . ' with username ' . $this->username . ': ' . $ret->getMessage() |
||
247 | ); |
||
248 | } |
||
249 | |||
250 | $this->log('Logged in to FTP server with username ' . $this->username, $this->logLevel); |
||
251 | |||
252 | if ($this->passive) { |
||
253 | $this->log('Setting passive mode', $this->logLevel); |
||
254 | $ret = $ftp->setPassive(); |
||
255 | if (@\PEAR::isError($ret)) { |
||
256 | $ftp->disconnect(); |
||
257 | throw new BuildException('Could not set PASSIVE mode: ' . $ret->getMessage()); |
||
258 | } |
||
259 | } |
||
260 | |||
261 | // append '/' to the end if necessary |
||
262 | $dir = substr($this->dir, -1) === '/' ? $this->dir : $this->dir . '/'; |
||
263 | |||
264 | if ($this->clearFirst) { |
||
265 | // TODO change to a loop through all files and directories within current directory |
||
266 | $this->log('Clearing directory ' . $dir, $this->logLevel); |
||
267 | $ftp->rm($dir, true); |
||
268 | } |
||
269 | |||
270 | // Create directory just in case |
||
271 | $ret = $ftp->mkdir($dir, true); |
||
272 | if (@\PEAR::isError($ret)) { |
||
273 | $ftp->disconnect(); |
||
274 | throw new BuildException('Could not create directory ' . $dir . ': ' . $ret->getMessage()); |
||
275 | } |
||
276 | |||
277 | $ret = $ftp->cd($dir); |
||
278 | if (@\PEAR::isError($ret)) { |
||
279 | $ftp->disconnect(); |
||
280 | throw new BuildException('Could not change to directory ' . $dir . ': ' . $ret->getMessage()); |
||
281 | } |
||
282 | |||
283 | $this->log('Changed directory ' . $dir, $this->logLevel); |
||
284 | |||
285 | $fs = FileSystem::getFileSystem(); |
||
286 | $convert = $fs->getSeparator() === '\\'; |
||
287 | |||
288 | foreach ($this->filesets as $fs) { |
||
289 | // Array for holding directory content informations |
||
290 | $remoteFileInformations = []; |
||
291 | |||
292 | $ds = $fs->getDirectoryScanner($project); |
||
293 | $fromDir = $fs->getDir($project); |
||
294 | $srcFiles = $ds->getIncludedFiles(); |
||
295 | $srcDirs = $ds->getIncludedDirectories(); |
||
296 | |||
297 | foreach ($srcDirs as $dirname) { |
||
298 | if ($convert) { |
||
299 | $dirname = str_replace('\\', '/', $dirname); |
||
300 | } |
||
301 | |||
302 | // Read directory informations, if file exists, else create the directory |
||
303 | if (!$this->directoryInformations($ftp, $remoteFileInformations, $dirname)) { |
||
304 | $this->log('Will create directory ' . $dirname, $this->logLevel); |
||
305 | $ret = $ftp->mkdir($dirname, true); |
||
306 | if (@\PEAR::isError($ret)) { |
||
307 | $ftp->disconnect(); |
||
308 | throw new BuildException('Could not create directory ' . $dirname . ': ' . $ret->getMessage()); |
||
309 | } |
||
310 | } |
||
311 | if ($this->dirmode) { |
||
312 | if ($this->dirmode === 'inherit') { |
||
313 | $mode = fileperms($dirname); |
||
314 | } else { |
||
315 | $mode = $this->dirmode; |
||
316 | } |
||
317 | // Because Net_FTP does not support a chmod call we call ftp_chmod directly |
||
318 | ftp_chmod($ftp->_handle, $mode, $dirname); |
||
319 | } |
||
320 | } |
||
321 | |||
322 | foreach ($srcFiles as $filename) { |
||
323 | $file = new File($fromDir->getAbsolutePath(), $filename); |
||
324 | if ($convert) { |
||
325 | $filename = str_replace('\\', '/', $filename); |
||
326 | } |
||
327 | |||
328 | $local_filemtime = filemtime($file->getCanonicalPath()); |
||
329 | $remoteFileModificationTime = $remoteFileInformations[$filename]['stamp'] ?? 0; |
||
330 | |||
331 | if (!$this->depends || ($local_filemtime > $remoteFileModificationTime)) { |
||
332 | if ($this->skipOnSameSize === true && $file->length() === $ftp->size($filename)) { |
||
333 | $this->log('Skipped ' . $file->getCanonicalPath(), $this->logLevel); |
||
334 | continue; |
||
335 | } |
||
336 | |||
337 | $this->log('Will copy ' . $file->getCanonicalPath() . ' to ' . $filename, $this->logLevel); |
||
338 | $ret = $ftp->put($file->getCanonicalPath(), $filename, true, $this->mode); |
||
339 | if (@\PEAR::isError($ret)) { |
||
340 | $ftp->disconnect(); |
||
341 | throw new BuildException('Could not deploy file ' . $filename . ': ' . $ret->getMessage()); |
||
342 | } |
||
343 | } |
||
344 | if ($this->filemode) { |
||
345 | if ($this->filemode === 'inherit') { |
||
346 | $mode = fileperms($filename); |
||
347 | } else { |
||
348 | $mode = $this->filemode; |
||
349 | } |
||
350 | // Because Net_FTP does not support a chmod call we call ftp_chmod directly |
||
351 | ftp_chmod($ftp->_handle, $mode, $filename); |
||
352 | } |
||
353 | } |
||
354 | } |
||
355 | |||
356 | $ftp->disconnect(); |
||
357 | $this->log('Disconnected from FTP server', $this->logLevel); |
||
358 | } |
||
449 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths