| Conditions | 10 |
| Paths | 8 |
| Total Lines | 42 |
| Code Lines | 21 |
| 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 |
||
| 28 | public function setupCrawler($crawler_id) |
||
| 29 | { |
||
| 30 | $this->crawler_id = $crawler_id; |
||
| 31 | $times = config('laravel-job-handler.run_times', 10); |
||
| 32 | |||
| 33 | for ($x = 0; $x <= $times; $x++) { |
||
| 34 | //fetch the last data |
||
| 35 | $this->getCrawler(); |
||
| 36 | |||
| 37 | if (!$this->crawler->enabled) { |
||
| 38 | throw new \Exception('Crawler (#'.$this->crawler_id.') - crawler isnt enabled in database'); |
||
| 39 | } |
||
| 40 | if ($this->crawler->latest_status == 4) { |
||
|
|
|||
| 41 | throw new \Exception('Crawler (#'.$this->crawler_id.') - last run had an error and the developer needs to reenable this crawler'); |
||
| 42 | } |
||
| 43 | if ($this->crawler->latest_status == 3) { |
||
| 44 | throw new \Exception('Crawler (#'.$this->crawler_id.') - last run had an error'); |
||
| 45 | } |
||
| 46 | if ($this->crawler->latest_status == 2) { |
||
| 47 | //Done running... |
||
| 48 | break; |
||
| 49 | } |
||
| 50 | |||
| 51 | if (is_null($this->crawler->latest_status)) { |
||
| 52 | //first time it runs... |
||
| 53 | break; |
||
| 54 | } |
||
| 55 | |||
| 56 | if ($x == $times) { |
||
| 57 | $this->failCrawler('Crawler (#'.$this->crawler_id.') - max execution time'); |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($this->crawler->status == 1) { |
||
| 61 | if ($this->crawler->multiple) { |
||
| 62 | break; |
||
| 63 | } |
||
| 64 | |||
| 65 | sleep(config('laravel-job-handler.retry_in_seconds', 3)); //retry in 3 seconds |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | $this->startCrawler(); |
||
| 70 | } |
||
| 137 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.