1 | <?php |
||
18 | class RandomOrgAPI { |
||
19 | |||
20 | /** |
||
21 | * The default Random.org endpoint template. |
||
22 | * |
||
23 | * @var string; |
||
24 | */ |
||
25 | protected $endpoint = 'https://api.random.org/json-rpc/%s/invoke'; |
||
26 | |||
27 | /** |
||
28 | * The Random.org api key. |
||
29 | * |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $apiKey = ''; |
||
33 | |||
34 | /** |
||
35 | * The HTTP client. |
||
36 | * |
||
37 | * @var Client |
||
38 | */ |
||
39 | protected $httpClient; |
||
40 | |||
41 | /** |
||
42 | * The logger. |
||
43 | * |
||
44 | * @var \Psr\Log\LoggerInterface |
||
45 | */ |
||
46 | protected $logger; |
||
47 | |||
48 | /** |
||
49 | * The Method plugin manager. |
||
50 | * |
||
51 | * @var MethodPluginManager |
||
52 | */ |
||
53 | protected $methodPluginManager; |
||
54 | |||
55 | /** |
||
56 | * The Random.org API version. |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | protected $apiVersion = 1; |
||
61 | |||
62 | /** |
||
63 | * The response if any. |
||
64 | * |
||
65 | * @var bool|ResponseInterface |
||
66 | */ |
||
67 | protected $response = FALSE; |
||
68 | |||
69 | /** |
||
70 | * @var MethodPluginInterface |
||
71 | */ |
||
72 | protected $methodPlugin = FALSE; |
||
73 | |||
74 | /** |
||
75 | * RandomOrgAPI constructor. |
||
76 | * |
||
77 | * @param null|\Http\Client\HttpClient $httpClient |
||
78 | * @param null|\Psr\Log\LoggerInterface $logger |
||
79 | */ |
||
80 | 16 | public function __construct(HttpClient $httpClient = NULL, LoggerInterface $logger = NULL) { |
|
87 | |||
88 | /** |
||
89 | * Set the Random.org endpoint template. |
||
90 | * |
||
91 | * @param string $uri |
||
92 | */ |
||
93 | 1 | public function setEndpoint($uri) { |
|
96 | |||
97 | /** |
||
98 | * Get the Random.org endpoint. |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | 16 | public function getEndpoint() { |
|
105 | |||
106 | /** |
||
107 | * Set the Method plugin manager. |
||
108 | * |
||
109 | * @param MethodPluginManager $methodPluginManager |
||
110 | */ |
||
111 | 16 | public function setMethodPluginManager(MethodPluginManager $methodPluginManager) { |
|
114 | |||
115 | /** |
||
116 | * Return the Method plugin manager. |
||
117 | * |
||
118 | * @return \drupol\Yaroc\Plugin\MethodPluginManager |
||
119 | */ |
||
120 | 13 | public function getMethodPluginManager() { |
|
123 | |||
124 | /** |
||
125 | * Get the logger. |
||
126 | * |
||
127 | * @return \Psr\Log\LoggerInterface |
||
128 | */ |
||
129 | 15 | public function getLogger() { |
|
132 | |||
133 | /** |
||
134 | * Set the logger. |
||
135 | * |
||
136 | * @param null|\Psr\Log\LoggerInterface $logger |
||
137 | */ |
||
138 | 15 | public function setLogger(LoggerInterface $logger = NULL) { |
|
141 | |||
142 | /** |
||
143 | * Set the client request. |
||
144 | * |
||
145 | * @param null|HttpClient $httpClient |
||
146 | * The client request. |
||
147 | */ |
||
148 | 16 | public function setHttpClient(HttpClient $httpClient = NULL) { |
|
151 | |||
152 | /** |
||
153 | * Get the Http client. |
||
154 | * |
||
155 | * @return Client |
||
156 | */ |
||
157 | 16 | public function getHttpClient() { |
|
160 | |||
161 | /** |
||
162 | * Set the Random.org API Key. |
||
163 | * |
||
164 | * @param string $key |
||
165 | * The API Key. |
||
166 | */ |
||
167 | 16 | public function setApiKey($key) { |
|
170 | |||
171 | /** |
||
172 | * Get the Random.org API Key. |
||
173 | * |
||
174 | * @return string |
||
175 | * The API Key. |
||
176 | */ |
||
177 | 13 | public function getApiKey() { |
|
180 | |||
181 | /** |
||
182 | * Set the API version. |
||
183 | * |
||
184 | * @param int |
||
185 | * The API version. |
||
186 | */ |
||
187 | 16 | public function setApiVersion($version) { |
|
191 | |||
192 | /** |
||
193 | * Get the API version. |
||
194 | * |
||
195 | * @return int |
||
196 | */ |
||
197 | 16 | public function getApiVersion() { |
|
200 | |||
201 | |||
202 | /** |
||
203 | * Set the method plugin. |
||
204 | * |
||
205 | * @param \drupol\Yaroc\Plugin\MethodPluginInterface|NULL $methodPlugin |
||
206 | */ |
||
207 | 13 | public function setMethodPlugin(MethodPluginInterface $methodPlugin = NULL) { |
|
210 | |||
211 | /** |
||
212 | * Get the method plugin. |
||
213 | * |
||
214 | * @return \drupol\Yaroc\Plugin\MethodPluginInterface |
||
215 | */ |
||
216 | 12 | private function getMethodPlugin() { |
|
219 | |||
220 | /** |
||
221 | * Set the response. |
||
222 | * |
||
223 | * @param \Psr\Http\Message\ResponseInterface|NULL $response |
||
224 | */ |
||
225 | 13 | private function setResponse(ResponseInterface $response = NULL) { |
|
228 | |||
229 | /** |
||
230 | * Get the response. |
||
231 | * |
||
232 | * @return bool|\Psr\Http\Message\ResponseInterface |
||
233 | */ |
||
234 | 13 | public function getResponse() { |
|
237 | |||
238 | /** |
||
239 | * @param \drupol\Yaroc\Plugin\MethodPluginInterface $methodPlugin |
||
240 | * |
||
241 | * @return ResponseInterface|\Exception |
||
242 | */ |
||
243 | 12 | private function request(MethodPluginInterface $methodPlugin) { |
|
246 | |||
247 | /** |
||
248 | * Call Random.org API. |
||
249 | * |
||
250 | * @param string $method |
||
251 | * The method to call. |
||
252 | * @param array $parameters |
||
253 | * The associative array of parameters as defined in the Random.org API. |
||
254 | * |
||
255 | * @return self |
||
256 | * Returns itself. |
||
257 | */ |
||
258 | 15 | public function call($method, array $parameters = array()) { |
|
275 | |||
276 | /** |
||
277 | * Get the result array from the response. |
||
278 | * |
||
279 | * @return array|bool |
||
280 | * The result array, FALSE otherwise. |
||
281 | */ |
||
282 | 13 | public function getResult() { |
|
289 | |||
290 | |||
291 | } |
||
292 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.