Passed
Push — main ( f5e4ab...1e3ad4 )
by smiley
01:55
created

CurlClient::createHandle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class HTTPClient
4
 *
5
 * @created      27.08.2018
6
 * @author       smiley <[email protected]>
7
 * @copyright    2018 smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\HTTP\Psr18;
12
13
use chillerlan\HTTP\CurlUtils\CurlHandle;
14
use Psr\Http\Message\{RequestInterface, ResponseInterface};
15
16
use function chillerlan\HTTP\Utils\message_to_string;
17
use function in_array, sprintf;
18
19
use const CURLE_OK;
20
21
class CurlClient extends HTTPClientAbstract{
22
23
	protected CurlHandle $handle;
24
25
	/**
26
	 * @inheritDoc
27
	 */
28
	public function sendRequest(RequestInterface $request):ResponseInterface{
29
		$this->logger->debug(sprintf("\n----HTTP-REQUEST----\n%s", message_to_string($request)));
0 ignored issues
show
Bug introduced by
The method debug() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
		$this->logger->/** @scrutinizer ignore-call */ 
30
                 debug(sprintf("\n----HTTP-REQUEST----\n%s", message_to_string($request)));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
31
		$this->handle = new CurlHandle($request, $this->responseFactory->createResponse(), $this->options);
32
		$errno        = $this->handle->exec();
33
34
		if($errno !== CURLE_OK){
35
			$error = $this->handle->getError();
36
37
			$this->logger->error(sprintf('cURL error #%s: %s', $errno, $error));
38
39
			if(in_array($errno, $this->handle::CURL_NETWORK_ERRORS, true)){
40
				throw new NetworkException($error, $request);
41
			}
42
43
			throw new RequestException($error, $request);
44
		}
45
46
		$this->handle->close();
47
		$response = $this->handle->getResponse();
48
		$this->logger->debug(sprintf("\n----HTTP-RESPONSE---\n%s", message_to_string($response)));
49
50
		return $response;
51
	}
52
53
}
54