Conditions | 3 |
Paths | 3 |
Total Lines | 64 |
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 |
||
28 | public function exportIndex( |
||
29 | IndexService $index, |
||
30 | $filename, |
||
31 | $chunkSize, |
||
32 | OutputInterface $output, |
||
33 | $maxLinesInFile = 300000 |
||
34 | ) { |
||
35 | $search = new Search(); |
||
36 | $search->addQuery(new MatchAllQuery()); |
||
37 | $search->setSize($chunkSize); |
||
38 | $search->setScroll('2m'); |
||
39 | |||
40 | $searchResults = $index->search($search->toArray(), $search->getUriParams()); |
||
41 | |||
42 | $results = new RawIterator( |
||
43 | $searchResults, |
||
44 | $index, |
||
45 | null, |
||
46 | [ |
||
47 | 'duration' => '2m', |
||
48 | '_scroll_id' => $searchResults['_scroll_id'], |
||
49 | ] |
||
50 | ); |
||
51 | |||
52 | $progress = new ProgressBar($output, $results->count()); |
||
53 | $progress->setRedrawFrequency(100); |
||
54 | $progress->start(); |
||
55 | |||
56 | $counter = $fileCounter = 0; |
||
57 | $count = $this->getFileCount($results->count(), $maxLinesInFile, $fileCounter); |
||
58 | |||
59 | $date = date(\DateTime::ISO8601); |
||
60 | $metadata = [ |
||
61 | 'count' => $count, |
||
62 | 'date' => $date, |
||
63 | ]; |
||
64 | |||
65 | $filename = str_replace('.json', '', $filename); |
||
66 | $writer = $this->getWriter($this->getFilePath($filename.'.json'), $metadata['count']); |
||
67 | |||
68 | foreach ($results as $data) { |
||
69 | if ($counter >= $maxLinesInFile) { |
||
70 | $writer->finalize(); |
||
71 | $writer = null; |
||
|
|||
72 | $fileCounter++; |
||
73 | $count = $this->getFileCount($results->count(), $maxLinesInFile, $fileCounter); |
||
74 | $metadata = [ |
||
75 | 'count' => $count, |
||
76 | 'date' => $date, |
||
77 | ]; |
||
78 | $writer = $this->getWriter($this->getFilePath($filename."_".$fileCounter.".json"), $metadata['count']); |
||
79 | $counter = 0; |
||
80 | } |
||
81 | |||
82 | $doc = array_intersect_key($data, array_flip(['_id', '_source'])); |
||
83 | $writer->push($doc); |
||
84 | $progress->advance(); |
||
85 | $counter++; |
||
86 | } |
||
87 | |||
88 | $writer->finalize(); |
||
89 | $progress->finish(); |
||
90 | $output->writeln(''); |
||
91 | } |
||
92 | |||
133 |
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.