Requests_Exception_HTTP   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getReason() 0 3 1
A get_class() 0 12 3
1
<?php
2
/**
3
 * Exception based on HTTP response
4
 *
5
 * @package Requests
6
 */
7
8
/**
9
 * Exception based on HTTP response
10
 *
11
 * @package Requests
12
 */
13
class Requests_Exception_HTTP extends Requests_Exception {
0 ignored issues
show
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...
14
	/**
15
	 * HTTP status code
16
	 *
17
	 * @var integer
18
	 */
19
	protected $code = 0;
20
21
	/**
22
	 * Reason phrase
23
	 *
24
	 * @var string
25
	 */
26
	protected $reason = 'Unknown';
27
28
	/**
29
	 * Create a new exception
30
	 *
31
	 * There is no mechanism to pass in the status code, as this is set by the
32
	 * subclass used. Reason phrases can vary, however.
33
	 *
34
	 * @param string|null $reason Reason phrase
35
	 * @param mixed $data Associated data
36
	 */
37
	public function __construct($reason = null, $data = null) {
38
		if ($reason !== null) {
39
			$this->reason = $reason;
40
		}
41
42
		$message = sprintf('%d %s', $this->code, $this->reason);
43
		parent::__construct($message, 'httpresponse', $data, $this->code);
44
	}
45
46
	/**
47
	 * Get the status message
48
	 */
49
	public function getReason() {
50
		return $this->reason;
51
	}
52
53
	/**
54
	 * Get the correct exception class for a given error code
55
	 *
56
	 * @param int|bool $code HTTP status code, or false if unavailable
57
	 * @return string Exception class name to use
58
	 */
59
	public static function get_class($code) {
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...
60
		if (!$code) {
61
			return 'Requests_Exception_HTTP_Unknown';
62
		}
63
64
		$class = sprintf('Requests_Exception_HTTP_%d', $code);
65
		if (class_exists($class)) {
66
			return $class;
67
		}
68
69
		return 'Requests_Exception_HTTP_Unknown';
70
	}
71
}