| Conditions | 12 |
| Paths | 241 |
| Total Lines | 69 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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, bool $redir = false) |
||
| 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 | file_put_contents('debug.html', $output); |
||
| 51 | |||
| 52 | /* Erreur logs de l'éxecution du cURL **/ |
||
| 53 | if ($curl->hasError()) { |
||
| 54 | $this->cErrors = $curl->getErrors(); |
||
| 55 | $this->error = 3; |
||
| 56 | |||
| 57 | return false; |
||
| 58 | } |
||
| 59 | |||
| 60 | $amIKicked = $this->amIKickedByGoogleThePowerful($output); |
||
| 61 | if (false !== $amIKicked) { |
||
| 62 | $this->error = $amIKicked; |
||
| 63 | |||
| 64 | return false; |
||
| 65 | } |
||
| 66 | |||
| 67 | if ($redirection = $this->getRedirection($output)) { |
||
| 68 | if (true === $redir) { |
||
| 69 | $this->error = 4; |
||
| 70 | |||
| 71 | return false; |
||
| 72 | } |
||
| 73 | |||
| 74 | return $this->requestGoogle('https://www.google.'.$this->tld.$redirection, true); |
||
| 75 | } |
||
| 76 | |||
| 77 | /* Tout est Ok, on enregistre et on renvoit le html **/ |
||
| 78 | $this->setCache($url, $output); |
||
| 79 | |||
| 80 | $this->cookie = $curl->getCookies(); |
||
| 81 | $this->referrer = $curl->getEffectiveUrl(); |
||
| 82 | $this->execSleep(); |
||
| 83 | |||
| 84 | return $output; |
||
| 85 | } |
||
| 99 |