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 |
||
23 | 5 | public function open(string $url, int $connectionTimeoutUs, int $requestTimeoutUs): SocketConnection |
|
24 | { |
||
25 | 5 | $errorCode = null; |
|
26 | 5 | $errorDescription = null; |
|
27 | |||
28 | 5 | $stream = @stream_socket_client($url, $errorCode, $errorDescription, (float) $connectionTimeoutUs / 1000000); |
|
29 | |||
30 | 5 | if (!is_resource($stream)) { |
|
31 | throw new ConnectionFailedException($url, sprintf('%d: %s', $errorCode, $errorDescription)); |
||
32 | } |
||
33 | |||
34 | 5 | if (false === stream_set_timeout($stream, 0, $requestTimeoutUs)) { |
|
35 | throw new ConnectionFailedException($url, 'failed to set request timeout'); |
||
36 | } |
||
37 | |||
38 | 5 | return new SocketConnection($stream, $url, $requestTimeoutUs); |
|
39 | } |
||
46 |