Completed
Push — master ( bc0986...2b3e20 )
by Greg
163:49 queued 121:06
created

SiteProcess::getCommandLine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
namespace Consolidation\SiteProcess;
3
4
use Consolidation\SiteAlias\AliasRecord;
5
use Consolidation\SiteProcess\Util\ArgumentProcessor;
6
7
/**
8
 * A wrapper around Symfony Process that uses site aliases
9
 * (https://github.com/consolidation/site-alias)
10
 *
11
 * - Interpolate arguments using values from the alias
12
 *   e.g. `$process = new SiteProcess($alias, ['git', '-C', '{{root}}']);`
13
 * - Make remote calls via ssh as if they were local.
14
 */
15
class SiteProcess extends ProcessBase
16
{
17
    /**
18
     * Process arguments and options per the site alias and build the
19
     * actual command to run.
20
     */
21
    public function __construct(AliasRecord $siteAlias, $args, $options = [], $optionsPassedAsArgs = [])
22
    {
23
        $processor = new ArgumentProcessor();
24
        $processedArgs = $processor->selectArgs($siteAlias, $args, $options, $optionsPassedAsArgs);
25
        parent::__construct($processedArgs);
26
    }
27
28
    /**
29
     * @inheritDoc
30
     */
31
    public function getCommandLine()
32
    {
33
        $commandLine = parent::getCommandLine();
34
        if ($this->isTty()) {
35
            $commandLine = preg_replace('#^([^a-z]*)ssh([^a-z ]*)#', '\1ssh\2 -t', $commandLine);
36
        }
37
        return $commandLine;
38
    }
39
}
40