Conditions | 3 |
Paths | 3 |
Total Lines | 86 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
38 | public function exportIndex( |
||
39 | Manager $manager, |
||
40 | $filename, |
||
41 | $types, |
||
42 | $chunkSize, |
||
|
|||
43 | OutputInterface $output, |
||
44 | $maxLinesInFile = 300000 |
||
45 | ) { |
||
46 | // $params = [ |
||
47 | //// 'search_type' => 'scroll', |
||
48 | // 'scroll' => '10m', |
||
49 | //// 'size' => $chunkSize, |
||
50 | // '_source' => true, |
||
51 | // 'body' => [ |
||
52 | // 'query' => [ |
||
53 | // 'match_all' => new \stdClass(), |
||
54 | // ], |
||
55 | // ], |
||
56 | // 'index' => $manager->getIndexName(), |
||
57 | // 'type' => $types, |
||
58 | // ]; |
||
59 | |||
60 | $search = new Search(); |
||
61 | $search->addQuery(new MatchAllQuery()); |
||
62 | $queryParameters = [ |
||
63 | '_source' => true, |
||
64 | 'scroll' => '10m', |
||
65 | ]; |
||
66 | |||
67 | $searchResults = $manager->search($types, $search->toArray(), $queryParameters); |
||
68 | |||
69 | $results = new RawIterator( |
||
70 | $searchResults, |
||
71 | $manager, |
||
72 | [ |
||
73 | 'duration' => $queryParameters['scroll'], |
||
74 | '_scroll_id' => $searchResults['_scroll_id'], |
||
75 | ] |
||
76 | ); |
||
77 | |||
78 | // $results = new SearchHitIterator( |
||
79 | // new SearchResponseIterator($manager->getClient(), $params) |
||
80 | // ); |
||
81 | |||
82 | $progress = new ProgressBar($output, $results->count()); |
||
83 | $progress->setRedrawFrequency(100); |
||
84 | $progress->start(); |
||
85 | |||
86 | $counter = $fileCounter = 0; |
||
87 | $count = $this->getFileCount($results->count(), $maxLinesInFile, $fileCounter); |
||
88 | |||
89 | $date = date(\DateTime::ISO8601); |
||
90 | $metadata = [ |
||
91 | 'count' => $count, |
||
92 | 'date' => $date, |
||
93 | ]; |
||
94 | |||
95 | $filename = str_replace('.json', '', $filename); |
||
96 | $writer = $this->getWriter($this->getFilePath($filename.'.json'), $metadata); |
||
97 | |||
98 | $file = []; |
||
99 | foreach ($results as $data) { |
||
100 | if ($counter >= $maxLinesInFile) { |
||
101 | $writer->finalize(); |
||
102 | $writer = null; |
||
103 | $fileCounter++; |
||
104 | $count = $this->getFileCount($results->count(), $maxLinesInFile, $fileCounter); |
||
105 | $metadata = [ |
||
106 | 'count' => $count, |
||
107 | 'date' => $date, |
||
108 | ]; |
||
109 | $writer = $this->getWriter($this->getFilePath($filename."_".$fileCounter.".json"), $metadata); |
||
110 | $counter = 0; |
||
111 | } |
||
112 | |||
113 | $doc = array_intersect_key($data, array_flip(['_id', '_type', '_source'])); |
||
114 | $writer->push($doc); |
||
115 | $file[] = $doc; |
||
116 | $progress->advance(); |
||
117 | $counter++; |
||
118 | } |
||
119 | |||
120 | $writer->finalize(); |
||
121 | $progress->finish(); |
||
122 | $output->writeln(''); |
||
123 | } |
||
124 | |||
173 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.