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