Code Duplication    Length = 46-47 lines in 2 locations

src/Installer/DNS/Linux/Debian/DockerRouting.php 1 location

@@ 10-56 (lines=47) @@
7
use Dock\IO\ProcessRunner;
8
use Dock\IO\UserInteraction;
9
10
class DockerRouting extends InstallerTask
11
{
12
    /**
13
     * @var ProcessRunner
14
     */
15
    private $processRunner;
16
    /**
17
     * @var UserInteraction
18
     */
19
    private $userInteraction;
20
21
    /**
22
     * @param UserInteraction $userInteraction
23
     * @param ProcessRunner   $processRunner
24
     */
25
    public function __construct(UserInteraction $userInteraction, ProcessRunner $processRunner)
26
    {
27
        $this->userInteraction = $userInteraction;
28
        $this->processRunner = $processRunner;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getName()
35
    {
36
        return 'routing';
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function run()
43
    {
44
        if (!$this->isUsingDnsDockDnsServer()) {
45
            $this->userInteraction->writeTitle('Configure routing for direct Docker containers access');
46
47
            $this->processRunner->run('echo "nameserver '.DnsDock::IP.'" | sudo tee -a /etc/resolvconf/resolv.conf.d/head');
48
            $this->processRunner->run('sudo resolvconf -u');
49
        }
50
    }
51
52
    private function isUsingDnsDockDnsServer()
53
    {
54
        return $this->processRunner->run('grep "'.DnsDock::IP.'" /etc/resolv.conf', false)->isSuccessful();
55
    }
56
}
57

src/Installer/DNS/Linux/RedHat/DockerRouting.php 1 location

@@ 10-55 (lines=46) @@
7
use Dock\IO\ProcessRunner;
8
use Dock\IO\UserInteraction;
9
10
class DockerRouting extends InstallerTask
11
{
12
    /**
13
     * @var ProcessRunner
14
     */
15
    private $processRunner;
16
    /**
17
     * @var UserInteraction
18
     */
19
    private $userInteraction;
20
21
    /**
22
     * @param UserInteraction $userInteraction
23
     * @param ProcessRunner   $processRunner
24
     */
25
    public function __construct(UserInteraction $userInteraction, ProcessRunner $processRunner)
26
    {
27
        $this->userInteraction = $userInteraction;
28
        $this->processRunner = $processRunner;
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getName()
35
    {
36
        return 'routing';
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function run()
43
    {
44
        if (!$this->isUsingDnsDockDnsServer()) {
45
            $this->userInteraction->writeTitle('Configure routing for direct Docker containers access');
46
47
            $this->processRunner->run("sudo sed -i -e '1inameserver ".DnsDock::IP."\\' /etc/resolv.conf");
48
        }
49
    }
50
51
    private function isUsingDnsDockDnsServer()
52
    {
53
        return $this->processRunner->run('grep "'.DnsDock::IP.'" /etc/resolv.conf', false)->isSuccessful();
54
    }
55
}
56