Completed
Push — master ( fb685a...a194ad )
by Moshe
399:40 queued 375:30
created

SiteProcess   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 41
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getCommandLine() 0 9 2
A start() 0 11 3
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
            $this->setCommandLine($commandLine);
37
        }
38
        return $commandLine;
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function start(callable $callback = null)
45
    {
46
        $cmd = $this->getCommandLine();
47
        if ($this->getVerbose()) {
48
            $this->io()->section('Start: ' . $cmd);
49
        }
50
        parent::start($callback);
51
        if ($this->getVerbose()) {
52
            $this->io()->section('End: ' . $cmd);
53
        }
54
    }
55
}
56