Completed
Pull Request — master (#123)
by Kieren
02:46
created

DnsDockResolver::getDnsByContainerNameAndImage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 2
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
        $imageName = $this->sanitiseImageName($imageName);
15
16
        return [
17
            $imageName.'.docker',
18
            $containerName.'.'.$imageName.'.docker',
19
        ];
20
    }
21
22
    /**
23
     * @param string $imageName
24
     *
25
     * @return string
26
     */
27 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...
28
    {
29
        if (false !== ($position = strpos($imageName, ':'))) {
30
            $imageName = substr($imageName, 0, $position);
31
        }
32
33
        return $imageName;
34
    }
35
    
36 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...
37
    {
38
        if (false !== ($position = strpos($imageName, '/'))) {
39
            $imageName = substr($imageName, $position+1 );
40
        }
41
42
        return $imageName;
43
    }
44
45
    private function sanitiseImageName($imageName)
46
    {
47
        return preg_replace('#/#', '_', $imageName);
48
    }
49
}
50