Passed
Push — master ( 48eab7...6ad25b )
by Keoghan
05:02
created

CliCommandFactory::execContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace App\Support\Console\DockerCompose;
4
5
use App\Models\Site;
6
use App\Support\Contracts\Cli;
7
8
class CliCommandFactory
9
{
10
    /**
11
     * @var Cli
12
     */
13
    protected $cli;
14
15 168
    public function __construct(Cli $cli)
16
    {
17 168
        $this->cli = $cli;
18 168
    }
19
20
    /**
21
     * Create a Docker CLI command.
22
     *
23
     * @param string $command
24
     *
25
     * @return CliCommand
26
     */
27 13
    public function command($command)
28
    {
29 13
        return new CliCommand($this->cli, $command);
30
    }
31
32
    /**
33
     * Construct a docker-compose exec {$container} command.
34
     *
35
     * @param string|null $container
36
     *
37
     * @return CliCommand
38
     */
39 1
    public function execContainer($container = null)
40
    {
41 1
        return new CliCommand($this->cli, "exec {$container}");
42
    }
43
44
    /**
45
     * Construct a docker-compose run {$container} command.
46
     *
47
     * @param string|null $container
48
     *
49
     * @return CliCommand
50
     */
51 2
    public function runContainer($container = null)
52
    {
53 2
        $site = Site::resolveFromPathOrCurrentWorkingDirectory();
54 2
        $workingDir = $site ? ' -w /srv/app/'.$site->name : '';
55
56 2
        return new CliCommand($this->cli, "run{$workingDir} --rm --service-ports {$container}");
57
    }
58
}
59