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