Rsync   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 40
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A call() 0 19 1
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Utility;
9
10
use Symfony\Component\Process\Process;
11
12
class Rsync
13
{
14
    /**
15
     * @var ProcessOutputPrinter
16
     */
17
    private $pop;
18
19
    public function __construct(ProcessOutputPrinter $pop)
20
    {
21
        $this->pop = $pop;
22
    }
23
24
    /**
25
     * Start rsync process
26
     *
27
     * @param $hostname
28
     * @param $source
29
     * @param $destination
30
     * @param array $config
31
     */
32
    public function call($hostname, $source, $destination, array $config = [])
33
    {
34
        $defaults = [
35
            'timeout' => null,
36
            'options' => [],
37
        ];
38
        $config = array_merge($defaults, $config);
39
40
        $escapedSource = escapeshellarg($source);
41
        $escapedDestination = escapeshellarg($destination);
42
        $rsync = "rsync -azP " . implode(' ', $config['options']) . " $escapedSource $escapedDestination";
43
44
        $this->pop->command($hostname, $rsync);
45
46
        $process = new Process($rsync);
47
        $process
48
            ->setTimeout($config['timeout'])
49
            ->mustRun($this->pop->callback($hostname));
50
    }
51
}
52