Passed
Push — main ( f2efe3...53dc0a )
by smiley
10:15
created

CurlMultiHandle::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Class CurlMultiHandle
4
 *
5
 * @filesource   CurlMultiHandle.php
6
 * @created      03.11.2020
7
 * @package      chillerlan\HTTP\CurlUtils
8
 * @author       smiley <[email protected]>
9
 * @copyright    2020 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\HTTP\CurlUtils;
14
15
use chillerlan\Settings\SettingsContainerInterface;
16
use Psr\Http\Message\{RequestInterface, ResponseInterface};
17
18
final class CurlMultiHandle extends CurlHandle{
19
20
	private MultiResponseHandlerInterface $multiResponseHandler;
21
22
	public function __construct(
23
		MultiResponseHandlerInterface $multiResponseHandler,
24
		RequestInterface $request,
25
		ResponseInterface $response,
26
		SettingsContainerInterface $options
27
	){
28
		parent::__construct($request, $response, $options);
29
30
		$this->multiResponseHandler = $multiResponseHandler;
31
	}
32
33
	/**
34
	 * a handle ID (counter), used in CurlMultiClient
35
	 */
36
	private ?int $id = null;
37
38
	/**
39
	 * a retry counter, used in CurlMultiClient
40
	 */
41
	private int $retries = 0;
42
43
	/**
44
	 *
45
	 */
46
	public function getID():?int{
47
		return $this->id;
48
	}
49
50
	/**
51
	 *
52
	 */
53
	public function setID(int $id):CurlMultiHandle{
54
		$this->id = $id;
55
56
		return $this;
57
	}
58
59
	/**
60
	 *
61
	 */
62
	public function getRetries():int{
63
		return $this->retries;
64
	}
65
66
	/**
67
	 *
68
	 */
69
	public function setRetries(int $retries):CurlMultiHandle{
70
		$this->retries = $retries;
71
72
		return $this;
73
	}
74
75
	/**
76
	 *
77
	 */
78
	public function addRetry():int{
79
		return ++$this->retries;
80
	}
81
82
	/**
83
	 *
84
	 */
85
	public function handleResponse():?RequestInterface{
86
		$info = curl_getinfo($this->curl);
87
88
		return $this->multiResponseHandler->handleResponse(
89
			$this->response,
90
			$this->request,
91
			$this->id,
0 ignored issues
show
Bug introduced by
It seems like $this->id can also be of type null; however, parameter $id of chillerlan\HTTP\CurlUtil...rface::handleResponse() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

91
			/** @scrutinizer ignore-type */ $this->id,
Loading history...
92
			(is_array($info) ? $info : [])
93
		);
94
	}
95
}
96