1 | <?php |
||
9 | class DefaultStream implements StreamInterface |
||
10 | { |
||
11 | |||
12 | /** |
||
13 | * The remote socket url. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | private $nodeUrl; |
||
18 | |||
19 | /** |
||
20 | * @var LoggerInterface |
||
21 | */ |
||
22 | private $log; |
||
23 | |||
24 | /** |
||
25 | * @var resource |
||
26 | */ |
||
27 | private $stream; |
||
28 | |||
29 | |||
30 | 33 | public function __construct($nodeUrl, LoggerInterface $log = null) |
|
39 | |||
40 | |||
41 | /** |
||
42 | * Connect the stream. |
||
43 | * |
||
44 | * @return boolean True if connection could be established. |
||
45 | * |
||
46 | * @throws ConnectException |
||
47 | */ |
||
48 | 30 | public function connect() |
|
65 | |||
66 | |||
67 | 27 | public function close() |
|
76 | |||
77 | |||
78 | /** |
||
79 | * Read a line from the stream. |
||
80 | * |
||
81 | * @return string |
||
82 | * @throws StreamException If an error occurs while reading from the stream. |
||
83 | */ |
||
84 | 24 | public function readLine() |
|
99 | |||
100 | |||
101 | /** |
||
102 | * Read bytes off from the stream. |
||
103 | * |
||
104 | * @param int|null $maxlen |
||
105 | * |
||
106 | * @return string |
||
107 | * @throws StreamException If an error occurs while reading from the stream. |
||
108 | */ |
||
109 | 14 | public function readBytes($maxlen = null) |
|
123 | |||
124 | |||
125 | /** |
||
126 | * Write bytes to the stream. |
||
127 | * |
||
128 | * @param string $msg |
||
129 | * @param int|null $len |
||
130 | * |
||
131 | * @return DefaultStream this instance. |
||
132 | * @throws StreamException |
||
133 | */ |
||
134 | 24 | public function write($msg, $len = null) |
|
149 | |||
150 | |||
151 | /** |
||
152 | * Check if the stream is connected. |
||
153 | * |
||
154 | * @return boolean True if the stream is connected. |
||
155 | */ |
||
156 | 3 | public function isConnected() |
|
160 | |||
161 | |||
162 | /** |
||
163 | * return the internal node url. |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | 2 | public function getNodeUrl() |
|
171 | |||
172 | |||
173 | /** |
||
174 | * Internal wrapper method, mainly for testing. |
||
175 | * |
||
176 | * @param resource $stream |
||
177 | * @param string $msg |
||
178 | * |
||
179 | * @return int |
||
180 | */ |
||
181 | 23 | protected function streamWrite($stream, $msg) |
|
185 | |||
186 | |||
187 | /** |
||
188 | * Internal wrapper method, mainly for testing. |
||
189 | * |
||
190 | * @param resource $stream |
||
191 | * @param $len |
||
192 | * |
||
193 | * @return string |
||
194 | */ |
||
195 | 13 | protected function streamReadBytes($stream, $len) |
|
199 | |||
200 | |||
201 | /** |
||
202 | * Internal wrapper method, mainly for testing. |
||
203 | * |
||
204 | * @param resource $stream |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | 23 | protected function streamReadLine($stream) |
|
212 | |||
213 | |||
214 | /** |
||
215 | * Internal wrapper method, mainly for testing. |
||
216 | * |
||
217 | * @param $stream |
||
218 | * |
||
219 | * @return array |
||
220 | */ |
||
221 | protected function streamMeta($stream) |
||
225 | } |
||
226 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.