Test Failed
Branch master (0f2f24)
by smiley
02:23
created

TinyCurlClient   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getResponse() 0 9 1
1
<?php
2
/**
3
 * Class TinyCurlClient
4
 *
5
 * @filesource   TinyCurlClient.php
6
 * @created      10.06.2017
7
 * @package      chillerlan\Threema\HTTP
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Threema\HTTP;
14
15
use chillerlan\Threema\GatewayResponse;
16
use chillerlan\TinyCurl\{Request, URL};
17
18
class TinyCurlClient extends HTTPClientAbstract{
19
20
	/**
21
	 * @var \chillerlan\TinyCurl\Request
22
	 */
23
	protected $client;
24
25
	/**
26
	 * TinyCurlClient constructor.
27
	 *
28
	 * @param \chillerlan\TinyCurl\Request $client
29
	 */
30
	public function __construct(Request $client){
31
		parent::__construct($client);
32
	}
33
34
	/**
35
	 * @param string $endpoint
36
	 * @param array  $params
37
	 * @param string $method
38
	 * @param null   $body
39
	 * @param array  $headers
40
	 *
41
	 * @return \chillerlan\Threema\GatewayResponse
42
	 */
43
	public function getResponse(string $endpoint, array $params = [], $method = 'GET', $body = null, $headers = []):GatewayResponse{
44
		$r = $this->client->fetch(new URL($endpoint, $params, $method, $body, $headers));
45
46
		$re = new GatewayResponse;
47
		$re->code = $r->info->http_code;
48
		$re->body = $r->body->content;
49
50
		return $re;
51
	}
52
53
}
54