Requests_Response   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A is_redirect() 0 4 3
A throw_for_status() 0 11 4
1
<?php
2
/**
3
 * HTTP response class
4
 *
5
 * Contains a response from Requests::request()
6
 * @package Requests
7
 */
8
9
/**
10
 * HTTP response class
11
 *
12
 * Contains a response from Requests::request()
13
 * @package Requests
14
 */
15
class Requests_Response {
0 ignored issues
show
Coding Style introduced by
The property $status_code is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
The property $protocol_version is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
16
	/**
17
	 * Constructor
18
	 */
19
	public function __construct() {
20
		$this->headers = new Requests_Response_Headers();
21
		$this->cookies = new Requests_Cookie_Jar();
22
	}
23
24
	/**
25
	 * Response body
26
	 *
27
	 * @var string
28
	 */
29
	public $body = '';
30
31
	/**
32
	 * Raw HTTP data from the transport
33
	 *
34
	 * @var string
35
	 */
36
	public $raw = '';
37
38
	/**
39
	 * Headers, as an associative array
40
	 *
41
	 * @var Requests_Response_Headers Array-like object representing headers
42
	 */
43
	public $headers = array();
44
45
	/**
46
	 * Status code, false if non-blocking
47
	 *
48
	 * @var integer|boolean
49
	 */
50
	public $status_code = false;
51
52
	/**
53
	 * Protocol version, false if non-blocking
54
	 * @var float|boolean
55
	 */
56
	public $protocol_version = false;
57
58
	/**
59
	 * Whether the request succeeded or not
60
	 *
61
	 * @var boolean
62
	 */
63
	public $success = false;
64
65
	/**
66
	 * Number of redirects the request used
67
	 *
68
	 * @var integer
69
	 */
70
	public $redirects = 0;
71
72
	/**
73
	 * URL requested
74
	 *
75
	 * @var string
76
	 */
77
	public $url = '';
78
79
	/**
80
	 * Previous requests (from redirects)
81
	 *
82
	 * @var array Array of Requests_Response objects
83
	 */
84
	public $history = array();
85
86
	/**
87
	 * Cookies from the request
88
	 *
89
	 * @var Requests_Cookie_Jar Array-like object representing a cookie jar
90
	 */
91
	public $cookies = array();
92
93
	/**
94
	 * Is the response a redirect?
95
	 *
96
	 * @return boolean True if redirect (3xx status), false if not.
97
	 */
98
	public function is_redirect() {
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
99
		$code = $this->status_code;
100
		return in_array($code, array(300, 301, 302, 303, 307)) || $code > 307 && $code < 400;
101
	}
102
103
	/**
104
	 * Throws an exception if the request was not successful
105
	 *
106
	 * @throws Requests_Exception If `$allow_redirects` is false, and code is 3xx (`response.no_redirects`)
107
	 * @throws Requests_Exception_HTTP On non-successful status code. Exception class corresponds to code (e.g. {@see Requests_Exception_HTTP_404})
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 144 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
108
	 * @param boolean $allow_redirects Set to false to throw on a 3xx as well
109
	 */
110
	public function throw_for_status($allow_redirects = true) {
0 ignored issues
show
Coding Style Naming introduced by
The parameter $allow_redirects is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
111
		if ($this->is_redirect()) {
112
			if (!$allow_redirects) {
113
				throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this);
114
			}
115
		}
116
		elseif (!$this->success) {
117
			$exception = Requests_Exception_HTTP::get_class($this->status_code);
118
			throw new $exception(null, $this);
119
		}
120
	}
121
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
122