| Conditions | 10 |
| Paths | 145 |
| Total Lines | 58 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 16 | protected function requestGoogle(string $url) |
||
| 17 | { |
||
| 18 | $cache = $this->getCache($url); |
||
| 19 | if ('' !== $cache) { |
||
| 20 | return $cache; |
||
| 21 | } |
||
| 22 | |||
| 23 | $curl = new CurlRequest($url); |
||
| 24 | $curl->setDefaultGetOptions()->setReturnHeader()->setEncodingGzip(); |
||
| 25 | |||
| 26 | if (isset($this->language)) { |
||
| 27 | $curl->setOpt(\CURLOPT_HTTPHEADER, ['Accept-Language: '.$this->language]); |
||
| 28 | } |
||
| 29 | if (isset($this->userAgent)) { |
||
| 30 | $curl->setUserAgent($this->userAgent); |
||
| 31 | } else { |
||
| 32 | if ($this->mobile) { |
||
| 33 | $curl->setDestkopUserAgent(); |
||
| 34 | } else { |
||
| 35 | $curl->setMobileUserAgent(); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | if (isset($this->proxy)) { |
||
| 40 | $curl->setProxy($this->proxy); |
||
| 41 | } |
||
| 42 | if (isset($this->referrer)) { |
||
| 43 | $curl->setReferrer($this->referrer); |
||
| 44 | } |
||
| 45 | if (isset($this->cookie)) { |
||
| 46 | $curl->setCookie($this->cookie); |
||
| 47 | } |
||
| 48 | |||
| 49 | $output = $curl->execute(); |
||
| 50 | |||
| 51 | /* Erreur lors de l'éxecution du cURL **/ |
||
| 52 | if ($curl->hasError()) { |
||
| 53 | $this->cErrors = $curl->getErrors(); |
||
| 54 | $this->error = 1; |
||
| 55 | |||
| 56 | return false; |
||
| 57 | } |
||
| 58 | |||
| 59 | $amIKicked = $this->amIKickedByGoogleThePowerful($output); |
||
| 60 | if (false !== $amIKicked) { |
||
|
|
|||
| 61 | $this->error = $amIKicked; |
||
| 62 | |||
| 63 | return false; |
||
| 64 | } |
||
| 65 | |||
| 66 | /* Tout est Ok, on enregistre et on renvoit le html **/ |
||
| 67 | $this->setCache($url, $output); |
||
| 68 | |||
| 69 | $this->cookie = $curl->getCookies(); |
||
| 70 | $this->referrer = $curl->getEffectiveUrl(); |
||
| 71 | $this->execSleep(); |
||
| 72 | |||
| 73 | return $output; |
||
| 74 | } |
||
| 76 |