Conditions | 9 |
Paths | 50 |
Total Lines | 60 |
Code Lines | 36 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
22 | public function execute(InputInterface $input, OutputInterface $output) |
||
23 | { |
||
24 | $archive = $this->getArchive($input, $output); |
||
25 | |||
26 | $folders = []; |
||
27 | foreach ($archive->getFileNames() as $file) { |
||
28 | $file_folder = dirname($file); |
||
29 | if (empty($file_folder)) { |
||
30 | $file_folder = '/'; |
||
31 | } |
||
32 | |||
33 | if (!isset($folders[$file_folder])) { |
||
34 | $folders[$file_folder] = [ |
||
35 | 0, // total files number |
||
36 | 0, // total uncompressed size |
||
37 | 0, // total compressed size |
||
38 | ]; |
||
39 | } |
||
40 | |||
41 | $details = $archive->getFileData($file); |
||
42 | $folders[$file_folder][0]++; |
||
43 | $folders[$file_folder][1] = $details->uncompressedSize; |
||
44 | $folders[$file_folder][2] = $details->compressedSize; |
||
45 | } |
||
46 | |||
47 | ksort($folders); |
||
48 | |||
49 | // iterate again and add sub-dirs stats to parent dirs |
||
50 | foreach ($folders as $folder => $folderStat) { |
||
51 | $parent_folder = $folder; |
||
52 | do { |
||
53 | $parent_folder = dirname($parent_folder); |
||
54 | if (in_array($parent_folder, ['.', '/'], true)) { |
||
55 | $parent_folder = null; |
||
56 | } |
||
57 | |||
58 | if (isset($folders[$parent_folder])) { |
||
59 | $folders[$parent_folder][0] += $folderStat[0]; |
||
60 | $folders[$parent_folder][1] += $folderStat[1]; |
||
61 | $folders[$parent_folder][2] += $folderStat[2]; |
||
62 | } |
||
63 | |||
64 | } while (!empty($parent_folder)); |
||
65 | } |
||
66 | |||
67 | $table = new Table($output); |
||
68 | $table->setHeaders(['Folder', 'Files', 'Size', 'xSize']); |
||
69 | $i = 0; |
||
70 | foreach ($folders as $folder => $folderStat) { |
||
71 | $table->setRow($i++, [ |
||
72 | $folder, |
||
73 | $folderStat[0], |
||
74 | implode($this->formatSize($folderStat[1])), |
||
75 | implode($this->formatSize($folderStat[2])), |
||
76 | ]); |
||
77 | } |
||
78 | $table->setStyle('compact'); |
||
79 | $table->render(); |
||
80 | |||
81 | return 0; |
||
82 | } |
||
84 |