Completed
Push — master ( 22f991...68c816 )
by Samuel
37s
created

DnsDockResolver::sanitiseImageName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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
    private function stripTagNameFromImageName($imageName)
27
    {
28
        if (false !== ($position = strpos($imageName, ':'))) {
29
            $imageName = substr($imageName, 0, $position);
30
        }
31
32
        return $imageName;
33
    }
34
    
35
    private function stripSlashFromImageName($imageName)
36
    {
37
        if (false !== ($position = strrpos($imageName, '/'))) {
38
            $imageName = substr($imageName, $position+1 );
39
        }
40
41
        return $imageName;
42
    }
43
}
44