Completed
Pull Request — master (#108)
by Marek
02:50
created

DnsDock   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 12.96 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 5
c 4
b 0
f 1
lcom 1
cbo 2
dl 7
loc 54
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A dependsOn() 0 4 1
A getName() 0 4 1
A __construct() 0 5 1
A run() 0 6 1
A getDockerIp() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Dock\Installer\DNS\Linux;
4
5
use Dock\Installer\InstallerTask;
6
use Dock\IO\ProcessRunner;
7
use Dock\IO\UserInteraction;
8
use SRIO\ChainOfResponsibility\DependentChainProcessInterface;
9
10
class DnsDock extends InstallerTask implements DependentChainProcessInterface
11
{
12
    const IP = '172.17.42.1';
13
14
    /**
15
     * @var ProcessRunner
16
     */
17
    private $processRunner;
18
    /**
19
     * @var UserInteraction
20
     */
21
    private $userInteraction;
22
23
    /**
24
     * @param UserInteraction $userInteraction
25
     * @param ProcessRunner   $processRunner
26
     */
27
    public function __construct(UserInteraction $userInteraction, ProcessRunner $processRunner)
28
    {
29
        $this->userInteraction = $userInteraction;
30
        $this->processRunner = $processRunner;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function dependsOn()
37
    {
38
        return ['docker'];
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getName()
45
    {
46
        return 'dns';
47
    }
48
49
    public function run()
50
    {
51
        $ip = $this->getDockerIp();
52
53
        $this->processRunner->run('sudo docker start dnsdock || sudo docker run -d -v /var/run/docker.sock:/var/run/docker.sock --name dnsdock -p '.$ip.':53:53/udp tonistiigi/dnsdock');
54
    }
55
56 View Code Duplication
    private function getDockerIp()
0 ignored issues
show
Duplication introduced by
This method 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...
57
    {
58
        $output = $this->processRunner->run("ip addr show docker0 | grep 'inet ' | awk -F\\  '{print $2}' | awk '{print $1}'");
59
        $network = explode('/', trim($output));
60
61
        return $network[0];
62
    }
63
}
64