Conditions | 6 |
Paths | 5 |
Total Lines | 67 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 1 | Features | 1 |
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 |
||
125 | public function handle() |
||
126 | { |
||
127 | if (!$this->validate()) { |
||
128 | return; |
||
129 | } |
||
130 | |||
131 | $harvestName = $this->argument('name'); |
||
132 | $harvestConfig = \Config::get('oaipmh.harvests.' . $harvestName, null); |
||
133 | |||
134 | $this->comment(''); |
||
135 | $this->info(sprintf('[%s] Starting harvest "%s"', |
||
136 | strftime('%Y-%m-%d %H:%M:%S'), |
||
137 | $harvestName |
||
138 | )); |
||
139 | |||
140 | if ($this->option('from-dump')) { |
||
141 | $this->comment(' - From local dump'); |
||
142 | } else { |
||
143 | $this->comment(' - Repo: ' . $harvestConfig['url']); |
||
144 | $this->comment(' - Schema: ' . $harvestConfig['schema']); |
||
145 | $this->comment(' - Set: ' . $harvestConfig['set']); |
||
146 | |||
147 | foreach (['from', 'until', 'resume', 'daily'] as $key) { |
||
148 | if (!is_null($this->option($key))) { |
||
149 | $this->comment(sprintf(' - %s: %s', ucfirst($key), $this->option($key))); |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | |||
154 | // For timing |
||
155 | $this->startTime = $this->batchTime = microtime(true) - 1; |
||
156 | |||
157 | \Event::listen('Colligator\Events\OaiPmhHarvestStatus', function ($event) { |
||
158 | $this->status($event->harvested, $event->position); |
||
159 | }); |
||
160 | |||
161 | \Event::listen('Colligator\Events\OaiPmhHarvestComplete', function ($event) { |
||
162 | $this->info(sprintf('[%s] Harvest complete, got %d records in %d seconds', |
||
163 | strftime('%Y-%m-%d %H:%M:%S'), |
||
164 | $event->count, |
||
165 | microtime(true) - $this->startTime |
||
166 | )); |
||
167 | }); |
||
168 | |||
169 | \Event::listen('Colligator\Events\JobError', function ($event) { |
||
170 | \Log::error('[OaiPmhHarvest] ' . $event->msg); |
||
171 | $this->error($event->msg); |
||
172 | }); |
||
173 | |||
174 | $from = $this->option('from'); |
||
175 | $until = $this->option('until'); |
||
176 | if ($this->option('daily')) { |
||
177 | $from = Carbon::now()->subDay()->toDateString(); |
||
178 | $until = $from; |
||
179 | } |
||
180 | |||
181 | $this->dispatch( |
||
182 | new OaiPmhHarvestJob( |
||
183 | $harvestName, |
||
184 | $harvestConfig, |
||
185 | $from, |
||
186 | $until, |
||
187 | $this->option('resume'), |
||
188 | $this->option('from-dump') |
||
189 | ) |
||
190 | ); |
||
191 | } |
||
192 | |||
221 |