Conditions | 3 |
Paths | 3 |
Total Lines | 16 |
Code Lines | 8 |
Lines | 0 |
Ratio | 0 % |
Tests | 7 |
CRAP Score | 3.0987 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
25 | 5 | public function open(string $url, int $connectionTimeoutUs, int $requestTimeoutUs): SocketConnection |
|
26 | { |
||
27 | 5 | $errorCode = null; |
|
28 | 5 | $errorDescription = null; |
|
29 | |||
30 | 5 | $stream = @stream_socket_client($url, $errorCode, $errorDescription, (float) $connectionTimeoutUs / 1000000); |
|
31 | |||
32 | 5 | if (!is_resource($stream)) { |
|
33 | throw new ConnectionFailedException($url, sprintf('%d: %s', $errorCode, $errorDescription)); |
||
34 | } |
||
35 | |||
36 | 5 | if (false === stream_set_timeout($stream, 0, $requestTimeoutUs)) { |
|
37 | throw new ConnectionFailedException($url, 'failed to set request timeout'); |
||
38 | } |
||
39 | |||
40 | 5 | return new SocketConnection($stream, $url, $requestTimeoutUs); |
|
41 | } |
||
48 |