SocketStreamConfig   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 86
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getAddress() 0 3 1
A getPort() 0 3 1
A getSocketAddress() 0 3 1
A getConnectionTimeout() 0 3 1
A getConnectionType() 0 3 1
A getContext() 0 3 1
1
<?php
2
3
/*
4
 * Copyright (c) 2011-2015, Celestino Diaz <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
 * THE SOFTWARE.
23
 */
24
25
namespace Brickoo\Component\IO\Stream;
26
27
use Brickoo\Component\Common\Assert;
28
29
/**
30
 * SocketStreamConfig
31
 *
32
 * Implements a socket stream configuration.
33
 * @author Celestino Diaz <[email protected]>
34
 */
35
class SocketStreamConfig {
36
37
    /** @var string */
38
    private $serverAddress;
39
40
    /** @var integer */
41
    private $serverPort;
42
43
    /** @var integer */
44
    private $connectionTimeout;
45
46
    /** @var integer */
47
    private $connectionType;
48
49
    /** @var array */
50
    private $context;
51
52
    /**
53
     * Class constructor.
54
     * @param string $address
55
     * @param integer $port
56
     * @param integer $timeout
57
     * @param integer $connectionType
58
     * @param array $context
59
     */
60 1
    public function __construct($address, $port, $timeout = 30, $connectionType = STREAM_CLIENT_CONNECT, array $context = array()) {
61 1
        Assert::isString($address);
62 1
        Assert::isInteger($timeout);
63 1
        Assert::isInteger($connectionType);
64
65 1
        $this->serverAddress = $address;
66 1
        $this->serverPort = $port;
67 1
        $this->connectionTimeout = $timeout;
68 1
        $this->connectionType = $connectionType;
69 1
        $this->context = $context;
70 1
    }
71
72
    /**
73
     * Returns the server address.
74
     * @return string the server address
75
     */
76 1
    public function getAddress() {
77 1
        return $this->serverAddress;
78
    }
79
80
    /**
81
     * Returns the server port number.
82
     * @return integer the server port number
83
     */
84 1
    public function getPort() {
85 1
        return $this->serverPort;
86
    }
87
88
    /**
89
     * Returns the complete socket address.
90
     * @return string the socket address
91
     */
92 1
    public function getSocketAddress() {
93 1
        return sprintf("%s:%d", $this->getAddress(), $this->getPort());
94
    }
95
96
    /**
97
     * Returns the connection timeout.
98
     * @return integer the connection timeout
99
     */
100 1
    public function getConnectionTimeout() {
101 1
        return $this->connectionTimeout;
102
    }
103
104
    /**
105
     * Return one of the connection type flags.
106
     * @return integer the connection type
107
     */
108 1
    public function getConnectionType() {
109 1
        return $this->connectionType;
110
    }
111
112
    /**
113
     * Returns the connection context.
114
     * @return array the connection context
115
     */
116 1
    public function getContext() {
117 1
        return $this->context;
118
    }
119
120
}
121