| Conditions | 3 |
| Paths | 3 |
| Total Lines | 66 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 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 |
||
| 35 | public function exportIndex( |
||
| 36 | Manager $manager, |
||
| 37 | $filename, |
||
| 38 | $types, |
||
| 39 | $chunkSize, |
||
| 40 | OutputInterface $output, |
||
| 41 | $maxLinesInFile = 300000 |
||
| 42 | ) { |
||
| 43 | $params = [ |
||
| 44 | 'search_type' => 'scan', |
||
| 45 | 'scroll' => '10m', |
||
| 46 | 'size' => $chunkSize, |
||
| 47 | 'source' => true, |
||
| 48 | 'body' => [ |
||
| 49 | 'query' => [ |
||
| 50 | 'match_all' => [], |
||
| 51 | ], |
||
| 52 | ], |
||
| 53 | 'index' => $manager->getIndexName(), |
||
| 54 | 'type' => $types, |
||
| 55 | ]; |
||
| 56 | |||
| 57 | $results = new SearchHitIterator( |
||
| 58 | new SearchResponseIterator($manager->getClient(), $params) |
||
| 59 | ); |
||
| 60 | |||
| 61 | $progress = new ProgressBar($output, $results->count()); |
||
| 62 | $progress->setRedrawFrequency(100); |
||
| 63 | $progress->start(); |
||
| 64 | |||
| 65 | $counter = $fileCounter = 0; |
||
| 66 | $count = $this->getFileCount($results->count(), $maxLinesInFile, $fileCounter); |
||
| 67 | |||
| 68 | $date = date(\DateTime::ISO8601); |
||
| 69 | $metadata = [ |
||
| 70 | 'count' => $count, |
||
| 71 | 'date' => $date, |
||
| 72 | ]; |
||
| 73 | |||
| 74 | $filename = str_replace('.json', '', $filename); |
||
| 75 | $writer = $this->getWriter($this->getFilePath($filename.'.json'), $metadata); |
||
| 76 | |||
| 77 | foreach ($results as $data) { |
||
| 78 | if ($counter >= $maxLinesInFile) { |
||
| 79 | $writer->finalize(); |
||
| 80 | $writer = null; |
||
|
|
|||
| 81 | $fileCounter++; |
||
| 82 | $count = $this->getFileCount($results->count(), $maxLinesInFile, $fileCounter); |
||
| 83 | $metadata = [ |
||
| 84 | 'count' => $count, |
||
| 85 | 'date' => $date, |
||
| 86 | ]; |
||
| 87 | $writer = $this->getWriter($this->getFilePath($filename."_".$fileCounter.".json"), $metadata); |
||
| 88 | $counter = 0; |
||
| 89 | } |
||
| 90 | |||
| 91 | $doc = array_intersect_key($data, array_flip(['_id', '_type', '_source', 'fields'])); |
||
| 92 | $writer->push($doc); |
||
| 93 | $progress->advance(); |
||
| 94 | $counter++; |
||
| 95 | } |
||
| 96 | |||
| 97 | $writer->finalize(); |
||
| 98 | $progress->finish(); |
||
| 99 | $output->writeln(''); |
||
| 100 | } |
||
| 101 | |||
| 150 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.