1 | <?php |
||
14 | class HttpRequest |
||
15 | { |
||
16 | /** |
||
17 | * HTTP GET/POST request with curl. |
||
18 | * @access public |
||
19 | * @param String $url The Request URL |
||
20 | * @param Array $postData Optional: POST data array to be send. |
||
21 | * @return Mixed On success, returns the response string. |
||
22 | * Else, the the HTTP status code received |
||
23 | * in reponse to the request. |
||
24 | */ |
||
25 | 7 | public static function sendRequest($url, $postData = false, $postJson = false) |
|
26 | { |
||
27 | 7 | $ua = sprintf('SEOstats %s https://github.com/eyecatchup/SEOstats', |
|
28 | 7 | \SEOstats\SEOstats::BUILD_NO); |
|
29 | |||
30 | 7 | $ch = curl_init($url); |
|
31 | 7 | curl_setopt_array($ch, array( |
|
32 | 7 | CURLOPT_USERAGENT => $ua, |
|
33 | 7 | CURLOPT_RETURNTRANSFER => 1, |
|
34 | 7 | CURLOPT_CONNECTTIMEOUT => 30, |
|
35 | 7 | CURLOPT_FOLLOWLOCATION => 1, |
|
36 | 7 | CURLOPT_MAXREDIRS => 2, |
|
37 | 7 | CURLOPT_SSL_VERIFYPEER => 0, |
|
38 | 7 | )); |
|
39 | |||
40 | 7 | if (false !== $postData) { |
|
41 | 4 | if (false !== $postJson) { |
|
42 | 2 | curl_setopt($ch, CURLOPT_HTTPHEADER, |
|
43 | 2 | array('Content-type: application/json')); |
|
44 | 2 | $data = json_encode($postData); |
|
45 | 2 | } else { |
|
46 | 2 | $data = http_build_query($postData); |
|
47 | } |
||
48 | 4 | curl_setopt($ch, CURLOPT_POST, 1); |
|
49 | 4 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
|
50 | 4 | } |
|
51 | |||
52 | 7 | $response = curl_exec($ch); |
|
53 | 7 | $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
54 | 7 | curl_close($ch); |
|
55 | 7 | if (429 == (int)$httpCode) { |
|
56 | throw new TooManyRequestsException("To many requests"); |
||
57 | } |
||
58 | 7 | return (200 == (int)$httpCode) ? $response : false; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * HTTP HEAD request with curl. |
||
63 | * |
||
64 | * @access private |
||
65 | * @param String $a The request URL |
||
|
|||
66 | * @return Integer Returns the HTTP status code received in |
||
67 | * response to a GET request of the input URL. |
||
68 | */ |
||
69 | 1 | public static function getHttpCode($url) |
|
91 | |||
92 | 2 | public function getFile($url, $file) |
|
117 | } |
||
118 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.