Completed
Push — master ( 9c5afe...e73e2f )
by Samuel
03:01
created

DnsDockResolver   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 41.03 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
c 5
b 0
f 0
lcom 0
cbo 0
dl 16
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDnsByContainerNameAndImage() 0 10 1
A stripTagNameFromImageName() 8 8 2
A stripSlashFromImageName() 8 8 2

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\Docker\Dns;
4
5
class DnsDockResolver implements ContainerAddressResolver
6
{
7
    /**
8
     * {@inheritdoc}
9
     */
10
    public function getDnsByContainerNameAndImage($containerName, $imageName)
11
    {
12
        $imageName = $this->stripTagNameFromImageName($imageName);
13
        $imageName = $this->stripSlashFromImageName($imageName);
14
15
        return [
16
            $imageName.'.docker',
17
            $containerName.'.'.$imageName.'.docker',
18
        ];
19
    }
20
21
    /**
22
     * @param string $imageName
23
     *
24
     * @return string
25
     */
26 View Code Duplication
    private function stripTagNameFromImageName($imageName)
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...
27
    {
28
        if (false !== ($position = strpos($imageName, ':'))) {
29
            $imageName = substr($imageName, 0, $position);
30
        }
31
32
        return $imageName;
33
    }
34
    
35 View Code Duplication
    private function stripSlashFromImageName($imageName)
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...
36
    {
37
        if (false !== ($position = strpos($imageName, '/'))) {
38
            $imageName = substr($imageName, $position+1 );
39
        }
40
41
        return $imageName;
42
    }
43
}
44