Completed
Push — master ( c77917...12b0e9 )
by Jörn Friedrich
57:44
created

Response   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 57.14%
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 49
ccs 8
cts 14
cp 0.5714
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getBody() 0 5 2
A getStatusCode() 0 3 1
A getHeader() 0 3 1
A getHeaders() 0 3 1
1
<?php
2
/**
3
 * @author Lukas Reschke <[email protected]>
4
 * @author Robin Appelman <[email protected]>
5
 *
6
 * @copyright Copyright (c) 2015, ownCloud, Inc.
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
23
namespace OC\Http\Client;
24
25
use OCP\Http\Client\IResponse;
26
use GuzzleHttp\Message\Response as GuzzleResponse;
27
28
/**
29
 * Class Response
30
 *
31
 * @package OC\Http
32
 */
33
class Response implements IResponse {
34
	/** @var GuzzleResponse */
35
	private $response;
36
37
	/**
38
	 * @var bool
39
	 */
40
	private $stream;
41
42
	/**
43
	 * @param GuzzleResponse $response
44
	 * @param bool $stream
45
	 */
46 7
	public function __construct(GuzzleResponse $response, $stream = false) {
47 7
		$this->response = $response;
48 7
		$this->stream = $stream;
49 7
	}
50
51
	/**
52
	 * @return string|resource
53
	 */
54
	public function getBody() {
55
		return $this->stream ?
56
			$this->response->getBody()->detach():
57
			$this->response->getBody()->getContents();
58
	}
59
60
	/**
61
	 * @return int
62
	 */
63 6
	public function getStatusCode() {
64 6
		return $this->response->getStatusCode();
65
	}
66
67
	/**
68
	 * @param $key
69
	 * @return string
70
	 */
71 1
	public function getHeader($key) {
72 1
		return $this->response->getHeader($key);
73
	}
74
75
	/**
76
	 * @return array
77
	 */
78
	public function getHeaders() {
79
		return $this->response->getHeaders();
80
	}
81
}
82