Completed
Push — master ( 988ea9...868c80 )
by smiley
07:26
created

URLExtractor   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4
1
<?php
2
/**
3
 * Class URLExtractor
4
 *
5
 * @filesource   URLExtractor.php
6
 * @created      15.08.2019
7
 * @package      chillerlan\HTTP\Psr18
8
 * @author       smiley <[email protected]>
9
 * @copyright    2019 smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\HTTP\Psr18;
14
15
use chillerlan\HTTP\Psr7\Request;
16
use Psr\Http\Message\{RequestInterface, ResponseInterface};
17
18
use function in_array;
19
20
class URLExtractor extends CurlClient{
21
22
	/**
23
	 * @var \Psr\Http\Message\ResponseInterface[]
24
	 */
25
	protected array $responses = [];
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_ARRAY, expecting T_FUNCTION or T_CONST
Loading history...
26
27
	/**
28
	 * @inheritDoc
29
	 */
30
	public function sendRequest(RequestInterface $request):ResponseInterface{
31
32
		do{
33
			$response = parent::sendRequest($request);
34
			$request  = new Request($request->getMethod(), $response->getHeaderLine('location'));
35
			$this->responses[] = $response;
36
		}
37
		while(in_array($response->getStatusCode(), [301, 302, 303, 307, 308], true));
38
39
		return $response;
40
	}
41
42
	/**
43
	 * @return \Psr\Http\Message\ResponseInterface[]
44
	 */
45
	public function getResponses():array{
46
		return $this->responses;
47
	}
48
49
}
50