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

RsyncTask   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 23.91 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 11
loc 46
ccs 0
cts 34
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 4 1
A getDescription() 0 4 1
A execute() 0 21 2
A getExcludes() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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