1 | <?php |
||
23 | class SocketRelay implements RelayInterface |
||
24 | { |
||
25 | /** Supported socket types. */ |
||
26 | const SOCK_TPC = 0; |
||
27 | const SOCK_UNIX = 1; |
||
28 | |||
29 | /** @var string */ |
||
30 | private $address; |
||
31 | |||
32 | /** @var int|null */ |
||
33 | private $port; |
||
34 | |||
35 | /** @var int */ |
||
36 | private $type; |
||
37 | |||
38 | /** @var resource|null */ |
||
39 | private $socket; |
||
40 | |||
41 | /** |
||
42 | * Example: |
||
43 | * $relay = new SocketRelay("localhost", 7000); |
||
44 | * $relay = new SocketRelay("/tmp/rpc.sock", null, Socket::UNIX_SOCKET); |
||
45 | * |
||
46 | * @param string $address Localhost, ip address or hostname. |
||
47 | * @param int|null $port Ignored for UNIX sockets. |
||
48 | * @param int $type Default: TPC_SOCKET |
||
49 | * |
||
50 | * @throws Exceptions\InvalidArgumentException |
||
51 | */ |
||
52 | public function __construct(string $address, int $port = null, int $type = self::SOCK_TPC) |
||
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | public function send($payload, int $flags = null): self |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function receiveSync(int &$flags = null) |
||
131 | |||
132 | /** |
||
133 | * @return string |
||
134 | */ |
||
135 | public function getAddress(): string |
||
139 | |||
140 | /** |
||
141 | * @return int|null |
||
142 | */ |
||
143 | public function getPort() |
||
147 | |||
148 | /** |
||
149 | * @return int |
||
150 | */ |
||
151 | public function getType(): int |
||
155 | |||
156 | /** |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function isConnected(): bool |
||
163 | |||
164 | /** |
||
165 | * Ensure socket connection. Returns true if socket successfully connected |
||
166 | * or have already been connected. |
||
167 | * |
||
168 | * @return bool |
||
169 | * |
||
170 | * @throws RelayException |
||
171 | * @throws \Error When sockets are used in unsupported environment. |
||
172 | */ |
||
173 | public function connect(): bool |
||
190 | |||
191 | /** |
||
192 | * Close connection. |
||
193 | * |
||
194 | * @throws RelayException |
||
195 | */ |
||
196 | public function close() |
||
205 | |||
206 | /** |
||
207 | * Destruct connection and disconnect. |
||
208 | */ |
||
209 | public function __destruct() |
||
215 | |||
216 | /** |
||
217 | * @return string |
||
218 | */ |
||
219 | public function __toString(): string |
||
227 | |||
228 | /** |
||
229 | * @return array Prefix [flag, length] |
||
230 | * |
||
231 | * @throws PrefixException |
||
232 | */ |
||
233 | private function fetchPrefix(): array |
||
250 | |||
251 | /** |
||
252 | * @return resource |
||
253 | * @throws \Error |
||
254 | */ |
||
255 | private function createSocket() |
||
267 | } |
||
268 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.