Endpoint   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 0
dl 0
loc 61
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAddress() 0 4 1
A getPort() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of the PHP Generics package.
5
 *
6
 * @package Generics
7
 */
8
namespace Generics\Socket;
9
10
/**
11
 * This class provides a data holder for a socket endpoint
12
 *
13
 * @author Maik Greubel <[email protected]>
14
 */
15
class Endpoint
16
{
17
18
    /**
19
     * The address for the socket
20
     *
21
     * @var string
22
     */
23
    private $address;
24
25
    /**
26
     * The port for the socket
27
     *
28
     * @var int
29
     */
30
    private $port;
31
32
    /**
33
     * Create a new endpoint
34
     *
35
     * @param string $address
36
     *            The address for the socket
37
     * @param int $port
38
     *            The port for the socket
39
     */
40 38
    public function __construct($address, $port)
41
    {
42 38
        $this->address = strval($address);
43 38
        $this->port = intval($port);
44 38
    }
45
46
    /**
47
     * Retrieve the address of the endpoint
48
     *
49
     * @return string The address
50
     */
51 33
    public function getAddress(): string
52
    {
53 33
        return $this->address;
54
    }
55
56
    /**
57
     * Retrieve the port of the endpoint
58
     *
59
     * @return int The port
60
     */
61 34
    public function getPort(): int
62
    {
63 34
        return $this->port;
64
    }
65
66
    /**
67
     * Retrieve the endpoint as string
68
     *
69
     * @return string
70
     */
71
    public function __toString(): string
72
    {
73
        return sprintf("%s:%d", $this->address, $this->port);
74
    }
75
}
76