Conditions | 3 |
Paths | 3 |
Total Lines | 71 |
Code Lines | 50 |
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 |
||
38 | public function exportIndex( |
||
39 | Manager $manager, |
||
40 | $filename, |
||
41 | $types, |
||
42 | $chunkSize, |
||
43 | OutputInterface $output, |
||
44 | $maxLinesInFile = 300000 |
||
45 | ) { |
||
46 | |||
47 | $search = new Search(); |
||
48 | $search->addQuery(new MatchAllQuery()); |
||
49 | $search->setSize($chunkSize); |
||
50 | |||
51 | $queryParameters = [ |
||
52 | '_source' => true, |
||
53 | 'scroll' => '10m', |
||
54 | ]; |
||
55 | |||
56 | $searchResults = $manager->search($types, $search->toArray(), $queryParameters); |
||
57 | |||
58 | $results = new RawIterator( |
||
59 | $searchResults, |
||
|
|||
60 | $manager, |
||
61 | [ |
||
62 | 'duration' => $queryParameters['scroll'], |
||
63 | '_scroll_id' => $searchResults['_scroll_id'], |
||
64 | ] |
||
65 | ); |
||
66 | |||
67 | $progress = new ProgressBar($output, $results->count()); |
||
68 | $progress->setRedrawFrequency(100); |
||
69 | $progress->start(); |
||
70 | |||
71 | $counter = $fileCounter = 0; |
||
72 | $count = $this->getFileCount($results->count(), $maxLinesInFile, $fileCounter); |
||
73 | |||
74 | $date = date(\DateTime::ISO8601); |
||
75 | $metadata = [ |
||
76 | 'count' => $count, |
||
77 | 'date' => $date, |
||
78 | ]; |
||
79 | |||
80 | $filename = str_replace('.json', '', $filename); |
||
81 | $writer = $this->getWriter($this->getFilePath($filename.'.json'), $metadata); |
||
82 | |||
83 | $file = []; |
||
84 | foreach ($results as $data) { |
||
85 | if ($counter >= $maxLinesInFile) { |
||
86 | $writer->finalize(); |
||
87 | $writer = null; |
||
88 | $fileCounter++; |
||
89 | $count = $this->getFileCount($results->count(), $maxLinesInFile, $fileCounter); |
||
90 | $metadata = [ |
||
91 | 'count' => $count, |
||
92 | 'date' => $date, |
||
93 | ]; |
||
94 | $writer = $this->getWriter($this->getFilePath($filename."_".$fileCounter.".json"), $metadata); |
||
95 | $counter = 0; |
||
96 | } |
||
97 | |||
98 | $doc = array_intersect_key($data, array_flip(['_id', '_type', '_source'])); |
||
99 | $writer->push($doc); |
||
100 | $file[] = $doc; |
||
101 | $progress->advance(); |
||
102 | $counter++; |
||
103 | } |
||
104 | |||
105 | $writer->finalize(); |
||
106 | $progress->finish(); |
||
107 | $output->writeln(''); |
||
108 | } |
||
109 | |||
158 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: