Conditions | 12 |
Paths | 108 |
Total Lines | 98 |
Code Lines | 54 |
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 |
||
32 | public function execute(InputInterface $input, OutputInterface $output) |
||
33 | { |
||
34 | $archive = $this->getArchive($input, $output); |
||
35 | $filter = $input->getArgument('filter'); |
||
36 | $human_readable_size = $input->getOption('human-readable-size'); |
||
37 | $detect_mimetype = $input->getOption('detect-mimetype'); |
||
38 | $sort = $input->getOption('sort'); |
||
39 | $sort_desc = $input->getOption('sort-desc'); |
||
40 | |||
41 | $headers = [ |
||
42 | 'Filename', |
||
43 | 'Size', |
||
44 | 'xSize', |
||
45 | 'Ratio', |
||
46 | 'Date', |
||
47 | // 'Crc', |
||
48 | 'Comment' |
||
49 | ]; |
||
50 | if ($detect_mimetype) { |
||
51 | array_splice($headers, 4, 0, ['Mimetype']); |
||
52 | } |
||
53 | |||
54 | $sort_field = array_search($sort, array_map('strtolower', $headers)); |
||
55 | |||
56 | if (!empty($filter) && strpos($filter, '*') === false) { |
||
|
|||
57 | $filter .= '*'; |
||
58 | } |
||
59 | |||
60 | $table = new Table($output); |
||
61 | $table->setHeaders($headers); |
||
62 | |||
63 | $rows = []; |
||
64 | |||
65 | foreach ($archive->getFiles($filter) as $i => $file) { |
||
66 | $details = $archive->getFileData($file); |
||
67 | |||
68 | if ($human_readable_size) { |
||
69 | $un_comp_size = implode($this->formatSize($details->uncompressedSize)); |
||
70 | $comp_size = implode($this->formatSize($details->compressedSize)); |
||
71 | } else { |
||
72 | $un_comp_size = $details->uncompressedSize; |
||
73 | $comp_size = $details->compressedSize; |
||
74 | } |
||
75 | |||
76 | $row = [ |
||
77 | $details->path, |
||
78 | $un_comp_size, |
||
79 | $comp_size, |
||
80 | $details->uncompressedSize > 0 |
||
81 | ? round($details->compressedSize / $details->uncompressedSize, 1) |
||
82 | : '-', |
||
83 | $this->formatDate($details->modificationTime), |
||
84 | // $details->crc32, |
||
85 | $details->comment, |
||
86 | ]; |
||
87 | if ($detect_mimetype) { |
||
88 | // @todo May be a bug in future. Need to review |
||
89 | array_splice($row, 4, 0, [ |
||
90 | $this->getMimeTypeByStream($archive->getFileStream($file)) |
||
91 | ]); |
||
92 | } |
||
93 | $rows[] = $row; |
||
94 | // $table->setRow($i, $row); |
||
95 | |||
96 | // $len = strlen($un_comp_size); |
||
97 | // if ($len > $uncomp_size_length) { |
||
98 | // $uncomp_size_length = $len; |
||
99 | // } |
||
100 | // $len = strlen($comp_size); |
||
101 | // if ($len > $comp_size_length) { |
||
102 | // $comp_size_length = $len; |
||
103 | // } |
||
104 | } |
||
105 | |||
106 | if ($sort !== null) { |
||
107 | usort($rows, function (array $a, array $b) use ($sort_field) { |
||
108 | if ($a[$sort_field] > $b[$sort_field]) { |
||
109 | return 1; |
||
110 | } |
||
111 | if ($a[$sort_field] < $b[$sort_field]) { |
||
112 | return -1; |
||
113 | } |
||
114 | return 0; |
||
115 | }); |
||
116 | if ($sort_desc) { |
||
117 | $rows = array_reverse($rows); |
||
118 | } |
||
119 | } |
||
120 | |||
121 | $table->setRows($rows); |
||
122 | |||
123 | // $table->setColumnWidth(0, 0); |
||
124 | // $table->setColumnWidth(1, $uncomp_size_length); |
||
125 | // $table->setColumnWidth(2, $comp_size_length); |
||
126 | // $table->setColumnWidth(3, 18); |
||
127 | $table->render(); |
||
128 | |||
129 | return 0; |
||
130 | } |
||
132 |