| Conditions | 11 |
| Paths | 21 |
| Total Lines | 61 |
| Code Lines | 36 |
| Lines | 29 |
| Ratio | 47.54 % |
| 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 |
||
| 15 | public function run() |
||
| 16 | { |
||
| 17 | $exit = false; |
||
| 18 | $count = 0; |
||
| 19 | $numPaginator = 0; |
||
| 20 | $countProxyVirgin = rand(0, count($this->listOfVirginProxies) - 1); |
||
| 21 | $resultFinal = array(); |
||
| 22 | |||
| 23 | $countProxyFail = array(); |
||
| 24 | |||
| 25 | while ($exit == false) { |
||
|
|
|||
| 26 | if ($count != 0) { |
||
| 27 | $numPaginator = $count; |
||
| 28 | } |
||
| 29 | |||
| 30 | $urlOfSearch = 'https://yandex.ru/search/?text='.urlencode($this->commandData['dork']).'&p='.$numPaginator.'&lr=10136'; |
||
| 31 | |||
| 32 | $this->output('Page '.$count."\n"); |
||
| 33 | |||
| 34 | View Code Duplication | if ($this->commandData['virginProxies']) { |
|
| 35 | $body = Utils::getBodyByVirginProxies($urlOfSearch, $this->listOfVirginProxies[$countProxyVirgin], $this->proxy); |
||
| 36 | |||
| 37 | //Check if next group of return data or not |
||
| 38 | $arrLinks = array(); |
||
| 39 | if (!$this->checkCaptcha($body) and $body != 'repeat') { |
||
| 40 | $arrLinks = Utils::getLinks($body); |
||
| 41 | } else { |
||
| 42 | --$count; |
||
| 43 | //Count the proxys with fail and all fail proxys, finish action |
||
| 44 | $countProxyFail[$countProxyVirgin] = $this->listOfVirginProxies[$countProxyVirgin]; |
||
| 45 | $this->output("You has a problem with proxy, probaly you estress the engenier ...\n"); |
||
| 46 | } |
||
| 47 | |||
| 48 | //Check if next virgin proxy or repeat of 0 |
||
| 49 | if ($countProxyVirgin == count($this->listOfVirginProxies) - 1) { |
||
| 50 | $countProxyVirgin = 0; |
||
| 51 | } else { |
||
| 52 | ++$countProxyVirgin; |
||
| 53 | } |
||
| 54 | } else { |
||
| 55 | $body = Utils::getBody($urlOfSearch, $this->proxy); |
||
| 56 | |||
| 57 | $arrLinks = Utils::getLinks($body); |
||
| 58 | } |
||
| 59 | |||
| 60 | $this->output("\n".$urlOfSearch."\n"); |
||
| 61 | |||
| 62 | $results = Utils::sanitazeLinks($arrLinks); |
||
| 63 | |||
| 64 | View Code Duplication | if (((count($results) == 0 && $body != 'repeat') && !$this->checkCaptcha($body)) |
|
| 65 | || (count($countProxyFail) == count($this->listOfVirginProxies))) { |
||
| 66 | $exit = true; |
||
| 67 | } |
||
| 68 | |||
| 69 | $resultFinal = array_merge($resultFinal, $results); |
||
| 70 | |||
| 71 | ++$count; |
||
| 72 | } |
||
| 73 | |||
| 74 | return $resultFinal; |
||
| 75 | } |
||
| 76 | |||
| 82 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.