Passed
Push — master ( 0deb8f...f54565 )
by Goffy
04:13
created

Response   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getPrevious() 0 3 1
A isCode() 0 3 1
A getCode() 0 3 1
A setPrevious() 0 8 2
1
<?php
2
3
namespace XoopsModules\Wggithub\Github\Http;
4
5
use XoopsModules\Wggithub\Github;
6
7
8
/**
9
 * HTTP response envelope.
10
 *
11
 * @author  Miloslav Hůla (https://github.com/milo)
12
 */
13
class Response extends Message
14
{
15
	/** HTTP 1.1 code */
16
	const
17
		S200_OK = 200,
18
		S301_MOVED_PERMANENTLY = 301,
19
		S302_FOUND = 302,
20
		S304_NOT_MODIFIED = 304,
21
		S307_TEMPORARY_REDIRECT = 307,
22
		S400_BAD_REQUEST = 400,
23
		S401_UNAUTHORIZED = 401,
24
		S403_FORBIDDEN = 403,
25
		S404_NOT_FOUND = 404,
26
		S422_UNPROCESSABLE_ENTITY = 422;
27
28
	/** @var int */
29
	private $code;
30
31
	/** @var Response */
32
	private $previous;
33
34
35
	/**
36
	 * @param  int
37
	 * @param  array
38
	 * @param  string
39
	 */
40
	public function __construct($code, array $headers, $content)
41
	{
42
		$this->code = (int) $code;
43
		parent::__construct($headers, $content);
44
	}
45
46
47
	/**
48
	 * HTTP code.
49
	 * @return int
50
	 */
51
	public function getCode()
52
	{
53
		return $this->code;
54
	}
55
56
57
	/**
58
	 * @param  int
59
	 * @return bool
60
	 */
61
	public function isCode($code)
62
	{
63
		return $this->code === (int) $code;
64
	}
65
66
67
	/**
68
	 * @return Response|NULL
69
	 */
70
	public function getPrevious()
71
	{
72
		return $this->previous;
73
	}
74
75
76
	/**
77
	 * @return self
78
	 *
79
	 * @throws Github\LogicException
80
	 */
81
	public function setPrevious(Response $previous = NULL)
82
	{
83
		if ($this->previous) {
84
			throw new Github\LogicException('Previous response is already set.');
0 ignored issues
show
Bug introduced by
The type XoopsModules\Wggithub\Github\LogicException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
85
		}
86
		$this->previous = $previous;
87
88
		return $this;
89
	}
90
91
}
92