Completed
Push — master ( 95a54c...7178fa )
by Samuel
10:58
created

DownloadDnsDock::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
namespace Dock\Installer\DNS\Mac;
4
5
use Dock\Docker\Machine\DockerMachineCli;
6
use Dock\Installer\InstallerTask;
7
use Dock\IO\ProcessRunner;
8
use Dock\IO\UserInteraction;
9
use SRIO\ChainOfResponsibility\DependentChainProcessInterface;
10
11
class DownloadDnsDock extends InstallerTask implements DependentChainProcessInterface
12
{
13
    /**
14
     * @var UserInteraction
15
     */
16
    private $userInteraction;
17
18
    /**
19
     * @var ProcessRunner
20
     */
21
    private $processRunner;
22
23
    /**
24
     * @var DockerMachineCli
25
     */
26
    private $machine;
27
28
    /**
29
     * @param UserInteraction $userInteraction
30
     * @param ProcessRunner $processRunner
31
     * @param DockerMachineCli $machine
32
     */
33
    public function __construct(UserInteraction $userInteraction, ProcessRunner $processRunner, DockerMachineCli $machine)
34
    {
35
        $this->userInteraction = $userInteraction;
36
        $this->processRunner = $processRunner;
37
        $this->machine = $machine;
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function run()
44
    {
45
        $this->userInteraction->writeTitle("Pulling image tonistiigi/dnsdock");
46
        $this->userInteraction->write("Check docker machine is running");
47
        if (!$this->machine->isRunning()) {
48
            $this->userInteraction->write("Starting machine");
49
            $this->machine->start();
50
        }
51
        $this->userInteraction->write("Setting environment variables");
52
        $this->processRunner->run($this->machine->getEnvironmentDeclaration());
53
54
        $this->userInteraction->write("Pulling image tonistiigi/dnsdock, this could take a while when run for the first time");
55
        $this->processRunner->run('docker pull tonistiigi/dnsdock');
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function dependsOn()
62
    {
63
        return ['machine'];
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function getName()
70
    {
71
        return 'dnsdock_image';
72
    }
73
}