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 |
||
17 | protected function requestGoogle(string $url, bool $redir = false) |
||
18 | { |
||
19 | $cache = $this->getCache($url); |
||
20 | if (false !== $cache) { |
||
21 | return $cache; |
||
22 | } |
||
23 | |||
24 | $curl = new CurlRequest($url); |
||
25 | $curl->setDefaultGetOptions()->setReturnHeader()->setEncodingGzip(); |
||
26 | |||
27 | if (isset($this->language)) { |
||
28 | $curl->setOpt(\CURLOPT_HTTPHEADER, ['Accept-Language: '.$this->language]); |
||
29 | } |
||
30 | if (isset($this->userAgent)) { |
||
31 | $curl->setUserAgent($this->userAgent); |
||
32 | } else { |
||
33 | if ($this->mobile) { |
||
34 | $curl->setDestkopUserAgent(); |
||
35 | } else { |
||
36 | $curl->setMobileUserAgent(); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | if (isset($this->proxy)) { |
||
41 | $curl->setProxy($this->proxy); |
||
42 | } |
||
43 | if (isset($this->referrer)) { |
||
44 | $curl->setReferrer($this->referrer); |
||
45 | } |
||
46 | if (isset($this->cookie)) { |
||
47 | $curl->setCookie($this->cookie); |
||
48 | } |
||
49 | |||
50 | $output = $curl->execute(); |
||
51 | file_put_contents('debug.html', $output); |
||
52 | |||
53 | /* Erreur logs de l'éxecution du cURL **/ |
||
54 | if ($curl->hasError()) { |
||
55 | $this->cErrors = $curl->getErrors(); |
||
56 | $this->error = 3; |
||
57 | |||
58 | return false; |
||
59 | } |
||
60 | |||
61 | $amIKicked = $this->amIKickedByGoogleThePowerful($output); |
||
62 | if (false !== $amIKicked) { |
||
63 | $this->error = $amIKicked; |
||
64 | |||
65 | return false; |
||
66 | } |
||
67 | |||
68 | if ($redirection = $this->getRedirection($output)) { |
||
69 | if (true === $redir) { |
||
70 | $this->error = 4; |
||
71 | |||
72 | return false; |
||
73 | } |
||
74 | |||
75 | return $this->requestGoogle('https://www.google.'.$this->tld.$redirection, true); |
||
76 | } |
||
77 | |||
78 | /* Tout est Ok, on enregistre et on renvoit le html **/ |
||
79 | $this->setCache($url, $output); |
||
80 | |||
81 | $this->cookie = $curl->getCookies(); |
||
82 | $this->referrer = $curl->getEffectiveUrl(); |
||
83 | $this->execSleep(); |
||
84 | |||
85 | return $output; |
||
86 | } |
||
100 |