| Conditions | 12 |
| Paths | 18 |
| Total Lines | 53 |
| Code Lines | 27 |
| 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 |
||
| 68 | public function setupCrawler($crawler_id = null) |
||
| 69 | { |
||
| 70 | if(!is_null($crawler_id)) { |
||
| 71 | $this->setCrawlerId($crawler_id); |
||
| 72 | } |
||
| 73 | |||
| 74 | if($this->controllerIsSetup()) { |
||
| 75 | $times = config('laravel-job-handler.run_times', 10); |
||
| 76 | |||
| 77 | for ($x = 0; $x <= $times; $x++) { |
||
| 78 | //fetch the last data |
||
| 79 | $this->getCrawler(); |
||
| 80 | |||
| 81 | if (!$this->crawler->enabled) { |
||
| 82 | throw new CrawlerException('Crawler (#' . $this->crawler_id . ') - crawler isnt enabled in database'); |
||
| 83 | } |
||
| 84 | |||
| 85 | $checkIfCrawlerCanBeRunned = $this->canCrawlerRunAfterPeriod(); |
||
| 86 | |||
| 87 | if ($checkIfCrawlerCanBeRunned['status']) { |
||
| 88 | if (is_null($this->crawler->latest_status)) { |
||
| 89 | //first time it runs... |
||
| 90 | break; |
||
| 91 | } |
||
| 92 | if ($this->crawler->latest_status == 2) { |
||
| 93 | //Done running... |
||
| 94 | break; |
||
| 95 | } |
||
| 96 | |||
| 97 | |||
| 98 | if ($this->crawler->latest_status == 3) { |
||
| 99 | throw new CrawlerException('Crawler (#' . $this->crawler_id . ') - last run had an error'); |
||
| 100 | } |
||
| 101 | } else { |
||
| 102 | throw new CrawlerNotReachedTimeBetweenJobsException('Has to wait ' . $checkIfCrawlerCanBeRunned['retry_in'] . ' more seconds to run'); |
||
| 103 | } |
||
| 104 | |||
| 105 | if ($x == $times) { |
||
| 106 | $this->failCrawler('Crawler (#' . $this->crawler_id . ') - max execution time'); |
||
| 107 | } |
||
| 108 | |||
| 109 | if ($this->crawler->status == 1) { |
||
| 110 | if ($this->crawler->multiple_crawlers) { |
||
| 111 | break; |
||
| 112 | } |
||
| 113 | |||
| 114 | sleep(config('laravel-job-handler.retry_in_seconds', 3)); //retry in 3 seconds |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | $this->startCrawler(); |
||
| 119 | } else { |
||
| 120 | throw new CrawlerException('CrawlController is not setup correctly.'); |
||
| 121 | } |
||
| 239 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.