These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | * This file is part of the Magallanes package. |
||
4 | * |
||
5 | * (c) Andrés Montañez <[email protected]> |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | */ |
||
10 | |||
11 | namespace Mage\Task\BuiltIn\Deploy; |
||
12 | |||
13 | use Mage\Task\Exception\ErrorException; |
||
14 | use Symfony\Component\Process\Process; |
||
15 | use Mage\Task\AbstractTask; |
||
16 | |||
17 | /** |
||
18 | * Rsync Task - Copy files with Rsync |
||
19 | * |
||
20 | * @author Andrés Montañez <[email protected]> |
||
21 | */ |
||
22 | class RsyncTask extends AbstractTask |
||
23 | { |
||
24 | 38 | public function getName() |
|
25 | { |
||
26 | 38 | return 'deploy/rsync'; |
|
27 | } |
||
28 | |||
29 | 17 | public function getDescription() |
|
30 | { |
||
31 | 17 | return '[Deploy] Copying files with Rsync'; |
|
32 | } |
||
33 | |||
34 | 17 | public function execute() |
|
35 | { |
||
36 | 17 | $flags = $this->runtime->getEnvOption('rsync', '-avz'); |
|
37 | 17 | $sshConfig = $this->runtime->getSSHConfig(); |
|
38 | 17 | $user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser()); |
|
39 | 17 | $host = $this->runtime->getWorkingHost(); |
|
40 | 17 | $hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/'); |
|
41 | 17 | $targetDir = rtrim($hostPath, '/'); |
|
42 | |||
43 | 17 | if ($this->runtime->getEnvOption('releases', false)) { |
|
44 | 1 | throw new ErrorException('Can\'t be used with Releases, use "deploy/tar/copy"'); |
|
45 | } |
||
46 | |||
47 | 16 | $excludes = $this->getExcludes(); |
|
48 | 16 | $from = $this->runtime->getEnvOption('from', './'); |
|
49 | 16 | $cmdRsync = sprintf('rsync -e "ssh -p %d %s" %s %s %s %s@%s:%s', $sshConfig['port'], $sshConfig['flags'], $flags, $excludes, $from, $user, $host, $targetDir); |
|
50 | |||
51 | /** @var Process $process */ |
||
52 | 16 | $process = $this->runtime->runLocalCommand($cmdRsync, 600); |
|
53 | 16 | return $process->isSuccessful(); |
|
54 | } |
||
55 | |||
56 | 16 | View Code Duplication | protected function getExcludes() |
0 ignored issues
–
show
|
|||
57 | { |
||
58 | 16 | $excludes = $this->runtime->getMergedOption('exclude', []); |
|
59 | 16 | $excludes = array_merge(['.git'], array_filter($excludes)); |
|
60 | |||
61 | 16 | foreach ($excludes as &$exclude) { |
|
62 | 16 | $exclude = '--exclude=' . $exclude; |
|
63 | 16 | } |
|
64 | |||
65 | 16 | return implode(' ', $excludes); |
|
66 | } |
||
67 | } |
||
68 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.