| Conditions | 7 |
| Paths | 20 |
| Total Lines | 55 |
| Code Lines | 31 |
| 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 namespace Nord\Lumen\Elasticsearch\Console; |
||
| 53 | public function handle() |
||
| 54 | { |
||
| 55 | $this->info(sprintf('Indexing data of type "%s" into "%s"', $this->getType(), $this->getIndex())); |
||
| 56 | |||
| 57 | $data = $this->getData(); |
||
| 58 | |||
| 59 | $bar = $this->output->createProgressBar($this->getCount()); |
||
| 60 | $bar->setRedrawFrequency($this->getProgressBarRedrawFrequency()); |
||
| 61 | |||
| 62 | $bulkQuery = new BulkQuery($this->getBulkSize()); |
||
| 63 | $responses = []; |
||
| 64 | |||
| 65 | foreach ($data as $item) { |
||
| 66 | $action = new BulkAction(); |
||
| 67 | |||
| 68 | $meta = [ |
||
| 69 | '_index' => $this->getIndex(), |
||
| 70 | '_type' => $this->getType(), |
||
| 71 | '_id' => $this->getItemId($item), |
||
| 72 | ]; |
||
| 73 | |||
| 74 | if (($parent = $this->getItemParent($item)) !== null) { |
||
| 75 | $meta['_parent'] = $parent; |
||
| 76 | } |
||
| 77 | |||
| 78 | $action->setAction(BulkAction::ACTION_INDEX, $meta) |
||
| 79 | ->setBody($this->getItemBody($item)); |
||
| 80 | |||
| 81 | $bulkQuery->addAction($action); |
||
| 82 | |||
| 83 | if ($bulkQuery->isReady()) { |
||
| 84 | $responses[] = $this->elasticsearchService->bulk($bulkQuery->toArray()); |
||
| 85 | $bulkQuery->reset(); |
||
| 86 | } |
||
| 87 | |||
| 88 | $bar->advance(); |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($bulkQuery->hasItems()) { |
||
| 92 | $responses[] = $this->elasticsearchService->bulk($bulkQuery->toArray()); |
||
| 93 | } |
||
| 94 | |||
| 95 | $bar->finish(); |
||
| 96 | |||
| 97 | $errors = $this->getErrors($responses); |
||
| 98 | if($errors) { |
||
| 99 | $this->info("\n"); |
||
| 100 | foreach($errors as $error) { |
||
| 101 | $this->error($error); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | $this->info("\nDone!"); |
||
| 106 | |||
| 107 | return 0; |
||
| 108 | } |
||
| 171 |