Test Failed
Pull Request — master (#448)
by
unknown
05:18
created

RsyncTask::getExcludes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 0
cts 9
cp 0
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 6
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
    public function getName()
25
    {
26
        return 'deploy/rsync';
27
    }
28
29
    public function getDescription()
30
    {
31
        return '[Deploy] Copying files with Rsync';
32
    }
33
34
    public function execute()
35
    {
36
        $flags = $this->runtime->getEnvOption('rsync', '-avz');
37
        $sshConfig = $this->runtime->getSSHConfig();
38
        $user = $this->runtime->getEnvOption('user', $this->runtime->getCurrentUser());
39
        $host = $this->runtime->getHostName();
40
        $hostPath = rtrim($this->runtime->getEnvOption('host_path'), '/');
41
        $targetDir = rtrim($hostPath, '/');
42
43
        if ($this->runtime->getEnvOption('releases', false)) {
44
            throw new ErrorException('Can\'t be used with Releases, use "deploy/tar/copy"');
45
        }
46
47
        $excludes = $this->getExcludes();
48
        $from = $this->runtime->getEnvOption('from', './');
49
        $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
        $process = $this->runtime->runLocalCommand($cmdRsync, null);
53
        return $process->isSuccessful();
54
    }
55
56 View Code Duplication
    protected function getExcludes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
57
    {
58
        $excludes = $this->runtime->getMergedOption('exclude', []);
59
        $excludes = array_merge(['.git'], array_filter($excludes));
60
61
        foreach ($excludes as &$exclude) {
62
            $exclude = '--exclude=' . $exclude;
63
        }
64
65
        return implode(' ', $excludes);
66
    }
67
}
68