1010use Http \Discovery \MessageFactoryDiscovery ;
1111use Http \Message \ResponseFactory ;
1212use Psr \Http \Message \RequestInterface ;
13+ use Psr \Http \Message \ResponseInterface ;
14+ use Throwable ;
1315
1416/**
1517 * Client compatible with PSR7 and Httplug interfaces, using a CakePHP client.
1618 */
1719class Client implements HttpClient
1820{
19- /** @var CakeClient */
21+ /**
22+ * @var \Cake\Http\Client
23+ */
2024 private $ client ;
2125
22- /** @var ResponseFactory */
26+ /**
27+ * @var \Http\Message\ResponseFactory
28+ */
2329 private $ responseFactory ;
2430
2531 /**
26- * @param CakeClient $client
27- * @param ResponseFactory $responseFactory
32+ * @param \Cake\Http\Client|null $client
33+ * @param \Http\Message\ ResponseFactory|null $responseFactory
2834 */
2935 public function __construct (CakeClient $ client = null , ResponseFactory $ responseFactory = null )
3036 {
@@ -33,9 +39,9 @@ public function __construct(CakeClient $client = null, ResponseFactory $response
3339 }
3440
3541 /**
36- * { @inheritdoc}
42+ * @inheritdoc
3743 */
38- public function sendRequest (RequestInterface $ request )
44+ public function sendRequest (RequestInterface $ request ): ResponseInterface
3945 {
4046 $ cakeRequest = new Request (
4147 (string ) $ request ->getUri (),
@@ -47,13 +53,13 @@ public function sendRequest(RequestInterface $request)
4753 ->withProtocolVersion ($ request ->getProtocolVersion ())
4854 ->withBody ($ request ->getBody ());
4955
50- if (null === $ cakeRequest ->header ('Content-Type ' )) {
51- $ cakeRequest-> header ('Content-Type ' , 'application/x-www-form-urlencoded ' );
56+ if (null === $ cakeRequest ->getHeader ('Content-Type ' )) {
57+ $ cakeRequest = $ cakeRequest -> withHeader ('Content-Type ' , 'application/x-www-form-urlencoded ' );
5258 }
5359
5460 try {
55- $ response = $ this ->client ->send ($ cakeRequest , $ this ->client ->config ());
56- } catch (Exception $ exception ) {
61+ $ response = $ this ->client ->send ($ cakeRequest , $ this ->client ->getConfig ());
62+ } catch (Throwable $ exception ) {
5763 throw new NetworkException ('Failed to send request ' , $ request , $ exception );
5864 }
5965
0 commit comments