@@ -24,29 +24,24 @@ class Client implements HttpClient
2424 use RequestWriter;
2525 use ResponseReader;
2626
27- private $ config = [
28- 'remote_socket ' => null ,
29- 'timeout ' => null ,
30- 'stream_context_options ' => [],
31- 'stream_context_param ' => [],
32- 'ssl ' => null ,
33- 'write_buffer_size ' => 8192 ,
34- 'ssl_method ' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
35- ];
27+ /**
28+ * @var array{remote_socket: string|null, timeout: int, stream_context: resource, stream_context_options: array<string, mixed>, stream_context_param: array<string, mixed>, ssl: ?boolean, write_buffer_size: int, ssl_method: int}
29+ */
30+ private $ config ;
3631
3732 /**
3833 * Constructor.
3934 *
40- * @param array $config {
35+ * @param array{remote_socket?: string|null, timeout?: int, stream_context?: resource, stream_context_options?: array<string, mixed>, stream_context_param?: array<string, mixed>, ssl?: ?boolean, write_buffer_size?: int, ssl_method?: int} $config
4136 *
42- * @var string $ remote_socket Remote entrypoint (can be a tcp or unix domain address)
43- * @var int $ timeout Timeout before canceling request
44- * @var array $stream_context_options Context options as defined in the PHP documentation
45- * @var array $stream_context_param Context params as defined in the PHP documentation
46- * @var bool $ssl Use ssl, default to scheme from request, false if not present
47- * @var int $write_buffer_size Buffer when writing the request body, defaults to 8192
48- * @var int $ssl_method Crypto method for ssl/tls, see PHP doc , defaults to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
49- * }
37+ * string|null remote_socket Remote entrypoint (can be a tcp or unix domain address)
38+ * int timeout Timeout before canceling request
39+ * stream resource The initialized stream context, if not set the context is created from the options and param.
40+ * array<string, mixed> stream_context_options Context options as defined in the PHP documentation
41+ * array<string, mixed> stream_context_param Context params as defined in the PHP documentation
42+ * boolean ssl Use ssl, default to scheme from request, false if not present
43+ * int write_buffer_size Buffer when writing the request body , defaults to 8192
44+ * int ssl_method Crypto method for ssl/tls, see PHP doc, defaults to STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT
5045 */
5146 public function __construct ($ config1 = [], $ config2 = null , array $ config = [])
5247 {
@@ -120,10 +115,10 @@ protected function createSocket(RequestInterface $request, string $remote, bool
120115 throw new ConnectionException ($ errMsg , $ request );
121116 }
122117
123- stream_set_timeout ($ socket , floor ($ this ->config ['timeout ' ] / 1000 ), $ this ->config ['timeout ' ] % 1000 );
118+ stream_set_timeout ($ socket , ( int ) floor ($ this ->config ['timeout ' ] / 1000 ), $ this ->config ['timeout ' ] % 1000 );
124119
125120 if ($ useSsl && false === @stream_socket_enable_crypto ($ socket , true , $ this ->config ['ssl_method ' ])) {
126- throw new SSLConnectionException (sprintf ('Cannot enable tls: %s ' , error_get_last ()['message ' ]), $ request );
121+ throw new SSLConnectionException (sprintf ('Cannot enable tls: %s ' , error_get_last ()['message ' ] ?? ' no error reported ' ), $ request );
127122 }
128123
129124 return $ socket ;
@@ -133,6 +128,8 @@ protected function createSocket(RequestInterface $request, string $remote, bool
133128 * Close the socket, used when having an error.
134129 *
135130 * @param resource $socket
131+ *
132+ * @return void
136133 */
137134 protected function closeSocket ($ socket )
138135 {
@@ -142,19 +139,26 @@ protected function closeSocket($socket)
142139 /**
143140 * Return configuration for the socket client.
144141 *
145- * @param array $config Configuration from user
142+ * @param array{remote_socket?: string|null, timeout?: int, stream_context?: resource, stream_context_options?: array<string, mixed>, stream_context_param?: array<string, mixed>, ssl?: ?boolean, write_buffer_size?: int, ssl_method?: int} $config
146143 *
147- * @return array Configuration resolved
144+ * @return array{remote_socket: string|null, timeout: int, stream_context: resource, stream_context_options: array<string, mixed>, stream_context_param: array<string, mixed>, ssl: ?boolean, write_buffer_size: int, ssl_method: int}
148145 */
149146 protected function configure (array $ config = [])
150147 {
151148 $ resolver = new OptionsResolver ();
152- $ resolver ->setDefaults ($ this ->config );
149+ $ resolver ->setDefaults ([
150+ 'remote_socket ' => null ,
151+ 'timeout ' => null ,
152+ 'stream_context_options ' => [],
153+ 'stream_context_param ' => [],
154+ 'ssl ' => null ,
155+ 'write_buffer_size ' => 8192 ,
156+ 'ssl_method ' => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT,
157+ ]);
153158 $ resolver ->setDefault ('stream_context ' , function (Options $ options ) {
154159 return stream_context_create ($ options ['stream_context_options ' ], $ options ['stream_context_param ' ]);
155160 });
156-
157- $ resolver ->setDefault ('timeout ' , ini_get ('default_socket_timeout ' ) * 1000 );
161+ $ resolver ->setDefault ('timeout ' , ((int ) ini_get ('default_socket_timeout ' )) * 1000 );
158162
159163 $ resolver ->setAllowedTypes ('stream_context_options ' , 'array ' );
160164 $ resolver ->setAllowedTypes ('stream_context_param ' , 'array ' );
0 commit comments