Completed
Push — master ( ab1063...454cba )
by smiley
05:29
created

MultiResponseHandlerTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 0 Features 1
Metric Value
wmc 2
c 5
b 0
f 1
lcom 1
cbo 1
dl 0
loc 31
rs 10
1
<?php
2
/**
3
 * Class MultiResponseHandlerTest
4
 *
5
 * @filesource   MultiResponseHandlerTest.php
6
 * @created      15.02.2016
7
 * @package      chillerlan\TinyCurl
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2016 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\TinyCurlTest;
14
15
use chillerlan\TinyCurl\MultiRequest;
16
use chillerlan\TinyCurl\Response\MultiResponseHandlerInterface;
17
use chillerlan\TinyCurl\Response\ResponseInterface;
18
use stdClass;
19
20
/**
21
 *
22
 */
23
class MultiResponseHandlerTest implements MultiResponseHandlerInterface{
24
25
	/**
26
	 * @var \chillerlan\TinyCurl\MultiRequest
27
	 */
28
	protected $request;
29
30
	public function __construct(MultiRequest $request){
31
		$this->request = $request;
32
	}
33
34
	/**
35
	 * @param \chillerlan\TinyCurl\Response\ResponseInterface $response
36
	 *
37
	 * @return mixed
38
	 */
39
	public function handleResponse(ResponseInterface $response){
40
		$data = new stdClass;
41
		$data->errorcode             = $response->error->code;
42
		$data->statuscode            = $response->info->http_code;
43
		$data->content_length_header = $response->headers->{'content-length'};
44
		$data->content_length_body   = $response->body->length;
45
		$data->content_type          = $response->body->content_type;
46
		$data->ids                   = array_column($response->json, 'id');
47
48
		sort($data->ids);
49
50
		$this->request->addResponse($data);
51
	}
52
53
}
54