Conditions | 10 |
Paths | 145 |
Total Lines | 58 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
15 | protected function requestGoogle(string $url) |
||
16 | { |
||
17 | $cache = $this->getCache($url); |
||
18 | if (false !== $cache) { |
||
19 | return $cache; |
||
20 | } |
||
21 | |||
22 | $curl = new CurlRequest($url); |
||
23 | $curl->setDefaultGetOptions()->setReturnHeader()->setEncodingGzip(); |
||
24 | |||
25 | if (isset($this->language)) { |
||
26 | $curl->setOpt(CURLOPT_HTTPHEADER, ['Accept-Language: '.$this->language]); |
||
27 | } |
||
28 | if (isset($this->userAgent)) { |
||
29 | $curl->setUserAgent($this->userAgent); |
||
30 | } else { |
||
31 | if ($this->mobile) { |
||
32 | $curl->setDestkopUserAgent(); |
||
33 | } else { |
||
34 | $curl->setMobileUserAgent(); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | if (isset($this->proxy)) { |
||
39 | $curl->setProxy($this->proxy); |
||
40 | } |
||
41 | if (isset($this->referrer)) { |
||
42 | $curl->setReferrer($this->referrer); |
||
43 | } |
||
44 | if (isset($this->cookie)) { |
||
45 | $curl->setCookie($this->cookie); |
||
46 | } |
||
47 | |||
48 | $output = $curl->execute(); |
||
49 | |||
50 | /* Erreur lors de l'éxecution du cURL **/ |
||
51 | if ($curl->hasError()) { |
||
52 | $this->cErrors = $curl->getErrors(); |
||
53 | $this->error = 1; |
||
54 | |||
55 | return false; |
||
56 | } |
||
57 | |||
58 | $amIKicked = $this->amIKickedByGoogleThePowerful($output); |
||
59 | if (false !== $amIKicked) { |
||
|
|||
60 | $this->error = $amIKicked; |
||
61 | |||
62 | return false; |
||
63 | } |
||
64 | |||
65 | /* Tout est Ok, on enregistre et on renvoit le html **/ |
||
66 | $this->setCache($url, $output); |
||
67 | |||
68 | $this->cookie = $curl->getCookies(); |
||
69 | $this->referrer = $curl->getEffectiveUrl(); |
||
70 | $this->execSleep(); |
||
71 | |||
72 | return $output; |
||
73 | } |
||
75 |