Conditions | 5 |
Paths | 9 |
Total Lines | 74 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | 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 = 0; |
||
66 | $fileCounter = 1; |
||
67 | |||
68 | if ($results->count() <= $maxLinesInFile) { |
||
69 | $count = $results->count(); |
||
70 | } elseif (($results->count() - ($fileCounter * $maxLinesInFile)) > $maxLinesInFile) { |
||
71 | $count = $results->count() - ($fileCounter * $maxLinesInFile); |
||
72 | } else { |
||
73 | $count = $maxLinesInFile; |
||
74 | } |
||
75 | |||
76 | $date = date(\DateTime::ISO8601); |
||
77 | $metadata = [ |
||
78 | 'count' => $count, |
||
79 | 'date' => $date, |
||
80 | ]; |
||
81 | |||
82 | $filename = str_replace('.json', '', $filename); |
||
83 | $writer = $this->getWriter($this->getFilePath($filename.'.json'), $metadata); |
||
84 | |||
85 | foreach ($results as $data) { |
||
86 | if ($counter >= $maxLinesInFile) { |
||
87 | $writer->finalize(); |
||
88 | $writer = null; |
||
|
|||
89 | $fileCounter++; |
||
90 | $counter = 0; |
||
91 | |||
92 | $metadata = [ |
||
93 | 'count' => $count, |
||
94 | 'date' => $date, |
||
95 | ]; |
||
96 | $writer = $this->getWriter($this->getFilePath($filename."_".$fileCounter.".json"), $metadata); |
||
97 | } |
||
98 | |||
99 | $doc = array_intersect_key($data, array_flip(['_id', '_type', '_source', 'fields'])); |
||
100 | $writer->push($doc); |
||
101 | $progress->advance(); |
||
102 | $counter++; |
||
103 | } |
||
104 | |||
105 | $writer->finalize(); |
||
106 | $progress->finish(); |
||
107 | $output->writeln(''); |
||
108 | } |
||
109 | |||
139 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.