Passed
Push — master ( 8005c7...9b803d )
by Goffy
03:14
created

ApiException::getResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
/**
5
 * All Milo\Github exceptions at one place. Whole library does not throw anything else.
6
 *
7
 * @author  Miloslav Hůla (https://github.com/milo)
8
 */
9
10
namespace XoopsModules\Wggithub\Github {
11
	/**
12
	 * Marker interface.
13
	 */
14
	interface IException
15
	{}
16
17
18
	/**
19
	 * Wrong algorithm. API is used in wrong way. Application code should be changed.
20
	 */
21
	class LogicException extends \LogicException implements IException
22
	{}
23
24
25
	/**
26
	 * Substitution is used in URL path but corresponding parameter is missing.
27
	 */
28
	class MissingParameterException extends LogicException
29
	{}
30
31
32
	/**
33
	 * Unpredictable situation occurred.
34
	 */
35
	abstract class RuntimeException extends \RuntimeException implements IException
36
	{}
37
38
39
	/**
40
	 * Github API returned a non-success HTTP code or data are somehow wrong. See all following descendants.
41
	 *
42
	 * @see Api::decode()
43
	 * @see https://developer.github.com/v3/#client-errors
44
	 */
45
	abstract class ApiException extends RuntimeException
46
	{
47
		/** @var Http\Response|NULL */
48
		private $response;
49
50
51
		/**
52
		 * @param string
53
		 * @param int
54
		 */
55
		public function __construct($message = '', $code = 0, \Exception $previous = NULL, Http\Response $response = NULL)
56
		{
57
			parent::__construct($message, $code, $previous);
58
			$this->response = clone $response;
59
		}
60
61
62
		/**
63
		 * @return Http\Response|NULL
64
		 */
65
		final public function getResponse()
66
		{
67
			return $this->response;
68
		}
69
70
	}
71
72
73
	/**
74
	 * Invalid credentials (e.g. revoked token).
75
	 */
76
	class UnauthorizedException extends ApiException
77
	{}
78
79
80
	/**
81
	 * Invalid JSON sent to Github API.
82
	 */
83
	class BadRequestException extends ApiException
84
	{}
85
86
87
	/**
88
	 * Invalid structure sent to Github API (e.g. some required fields are missing).
89
	 */
90
	class UnprocessableEntityException extends ApiException
91
	{}
92
93
94
	/**
95
	 * Access denied.
96
	 * @see https://developer.github.com/v3/#authentication
97
	 */
98
	class ForbiddenException extends ApiException
99
	{}
100
101
102
	/**
103
	 * Rate limit exceed.
104
	 * @see https://developer.github.com/v3/#rate-limiting
105
	 */
106
	class RateLimitExceedException extends ForbiddenException
107
	{}
108
109
110
	/**
111
	 * Resource not found.
112
	 * @see https://developer.github.com/v3/#authentication
113
	 */
114
	class NotFoundException extends ApiException
115
	{}
116
117
118
	/**
119
	 * Response cannot be classified.
120
	 */
121
	class UnexpectedResponseException extends ApiException
122
	{}
123
124
125
	/**
126
	 * Response from Github is somehow wrong (e.g. invalid JSON decoding).
127
	 */
128
	class InvalidResponseException extends ApiException
129
	{}
130
131
132
	/**
133
	 * JSON cannot be decoded, or value cannot be encoded to JSON.
134
	 */
135
	class JsonException extends RuntimeException
136
	{
137
	}
138
139
}
140
141
142
namespace Milo\Github\Http {
143
	use Milo\Github;
144
145
146
	/**
147
	 * HTTP response is somehow wrong and cannot be processed.
148
	 */
149
	class BadResponseException extends Github\RuntimeException
0 ignored issues
show
Bug introduced by
The type Milo\Github\RuntimeException 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...
150
	{}
151
152
}
153
154
155
namespace Milo\Github\OAuth {
156
	use Milo\Github;
157
158
	/**
159
	 * Something fails during the token obtaining.
160
	 */
161
	class LoginException extends Github\RuntimeException
162
	{}
163
164
}
165
166
167
namespace Milo\Github\Storages {
168
	use Milo\Github;
169
170
	/**
171
	 * Directory is missing and/or cannot be created.
172
	 */
173
	class MissingDirectoryException extends Github\RuntimeException
174
	{}
175
176
}
177