| Conditions | 10 |
| Paths | 8 |
| Total Lines | 48 |
| Code Lines | 23 |
| 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 |
||
| 39 | public function setupCrawler($crawler_id) |
||
| 40 | { |
||
| 41 | $this->setCrawlerId($crawler_id); |
||
| 42 | $times = config('laravel-job-handler.run_times', 10); |
||
| 43 | |||
| 44 | for ($x = 0; $x <= $times; $x++) { |
||
| 45 | //fetch the last data |
||
| 46 | $this->getCrawler(); |
||
| 47 | |||
| 48 | if (!$this->crawler->enabled) { |
||
| 49 | throw new CrawlerException('Crawler (#' . $this->crawler_id . ') - crawler isnt enabled in database'); |
||
| 50 | } |
||
| 51 | |||
| 52 | |||
| 53 | $checkIfCrawlerCanBeRunned = $this->canCrawlerRunAfterPeriod(); |
||
| 54 | |||
| 55 | if($checkIfCrawlerCanBeRunned['status']) { |
||
| 56 | if (is_null($this->crawler->latest_status)) { |
||
| 57 | //first time it runs... |
||
| 58 | break; |
||
| 59 | } |
||
| 60 | if ($this->crawler->latest_status == 2) { |
||
| 61 | //Done running... |
||
| 62 | break; |
||
| 63 | } |
||
| 64 | |||
| 65 | |||
| 66 | if ($this->crawler->latest_status == 3) { |
||
| 67 | throw new CrawlerException('Crawler (#' . $this->crawler_id . ') - last run had an error'); |
||
| 68 | } |
||
| 69 | } else { |
||
| 70 | throw new CrawlerNotReachedTimeBetweenJobsException('Has to wait '.$checkIfCrawlerCanBeRunned['retry_in'].' more seconds to run'); |
||
| 71 | } |
||
| 72 | |||
| 73 | if ($x == $times) { |
||
| 74 | $this->failCrawler('Crawler (#'.$this->crawler_id.') - max execution time'); |
||
| 75 | } |
||
| 76 | |||
| 77 | if ($this->crawler->status == 1) { |
||
| 78 | if ($this->crawler->multiple_crawlers) { |
||
| 79 | break; |
||
| 80 | } |
||
| 81 | |||
| 82 | sleep(config('laravel-job-handler.retry_in_seconds', 3)); //retry in 3 seconds |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | $this->startCrawler(); |
||
| 87 | } |
||
| 187 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.