DockerRouting::isUsingDnsDockDnsServer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Dock\Installer\DNS\Linux\RedHat;
4
5
use Dock\Installer\DNS\Linux\DnsDock;
6
use Dock\Installer\InstallerTask;
7
use Dock\IO\ProcessRunner;
8
use Dock\IO\UserInteraction;
9
10 View Code Duplication
class DockerRouting extends InstallerTask
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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