Port   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 0
loc 50
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A address() 0 4 1
A number() 0 4 1
A protocol() 0 4 1
A __toString() 0 4 1
A build() 0 9 1
1
<?php
2
3
namespace TH\Docker;
4
5
class Port
6
{
7
    const TCP = "TCP";
8
    const UDP = "UDP";
9
10
    private $address;
11
    private $number;
12
    private $protocol;
13
14
    public function __construct($address, $number, $protocol)
15
    {
16
        $this->address  = $address;
17
        $this->number   = (int)$number;
18
        $this->protocol = strtoupper($protocol);
19
    }
20
21
    public function address()
22
    {
23
        return $this->address;
24
    }
25
26
    public function number()
27
    {
28
        return $this->number;
29
    }
30
31
    public function protocol()
32
    {
33
        return $this->protocol;
34
    }
35
    
36
    public function __toString()
37
    {
38
        return strtolower($this->protocol)."://".$this->address.":".$this->number;
39
    }
40
41
    /**
42
     * @param  int    $port
43
     * @param  string $protocol
44
     */
45
    public static function build(array $env, $port, $protocol)
46
    {
47
        $prefix = "PORT_{$port}_{$protocol}";
48
        return new Port(
49
            $env["{$prefix}_ADDR"],
50
            $env["{$prefix}_PORT"],
51
            $env["{$prefix}_PROTO"]
52
        );
53
    }
54
}
55