Completed
Push — master ( 4849ce...812ae9 )
by Greg
01:26
created

VagrantTransport::addChdir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Consolidation\SiteProcess\Transport;
4
5
use Consolidation\SiteProcess\SiteProcess;
6
use Consolidation\SiteProcess\Util\Escape;
7
use Consolidation\SiteAlias\SiteAliasInterface;
8
use Consolidation\SiteProcess\Util\Shell;
9
10
/**
11
 * VagrantTransport knows how to wrap a command such that it runs on a remote
12
 * system via the vagrant cli.
13
 */
14
class VagrantTransport implements TransportInterface
15
{
16
    protected $tty;
17
    protected $siteAlias;
18
19
    public function __construct(SiteAliasInterface $siteAlias)
20
    {
21
        $this->siteAlias = $siteAlias;
22
    }
23
24
    /**
25
     * @inheritdoc
26
     */
27
    public function configure(SiteProcess $process)
28
    {
29
        $this->tty = $process->isTty();
30
    }
31
32
    /**
33
     * inheritdoc
34
     */
35
    public function wrap($args)
36
    {
37
        $transport = ['vagrant', 'ssh'];
38
        $transportOptions = $this->getTransportOptions();
39
        $commandToExecute = $this->getCommandToExecute($args);
40
41
        return array_merge(
42
            $transport,
43
            $transportOptions,
44
            ['-c'],
45
            $commandToExecute
46
        );
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function addChdir($cd_remote, $args)
53
    {
54
        return array_merge(
55
            [
56
                'cd',
57
                $cd_remote,
58
                Shell::op('&&'),
59
            ],
60
            $args
61
        );
62
    }
63
64
    /**
65
     * getTransportOptions returns the transport options for the tranport
66
     * mechanism itself
67
     */
68
    protected function getTransportOptions()
69
    {
70
        return $this->tty ? ['-t'] : [];
71
    }
72
73
    /**
74
     * getCommandToExecute processes the arguments for the command to
75
     * be executed such that they are appropriate for the transport mechanism.
76
     */
77 View Code Duplication
    protected function getCommandToExecute($args)
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...
78
    {
79
        // Escape each argument for the target system and then join
80
        $args = Escape::argsForSite($this->siteAlias, $args);
81
        $commandToExecute = implode(' ', $args);
82
83
        return [$commandToExecute];
84
    }
85
}
86