| Conditions | 12 |
| Paths | 38 |
| Total Lines | 51 |
| Code Lines | 40 |
| 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 |
||
| 91 | private function printTrashbinSize(InputInterface $input, OutputInterface $output, ?string $user) { |
||
| 92 | $globalSize = (int)$this->config->getAppValue('files_trashbin', 'trashbin_size', '-1'); |
||
| 93 | if ($globalSize < 0) { |
||
| 94 | $globalHumanSize = "default (50% of available space)"; |
||
| 95 | } else { |
||
| 96 | $globalHumanSize = \OC_Helper::humanFileSize($globalSize); |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($user) { |
||
| 100 | $userSize = (int)$this->config->getUserValue($user, 'files_trashbin', 'trashbin_size', '-1'); |
||
| 101 | |||
| 102 | if ($userSize < 0) { |
||
| 103 | $userHumanSize = ($globalSize < 0) ? $globalHumanSize : "default($globalHumanSize)"; |
||
| 104 | } else { |
||
| 105 | $userHumanSize = \OC_Helper::humanFileSize($userSize); |
||
| 106 | } |
||
| 107 | |||
| 108 | if ($input->getOption('output') == self::OUTPUT_FORMAT_PLAIN) { |
||
| 109 | $output->writeln($userHumanSize); |
||
| 110 | } else { |
||
| 111 | $userValue = ($userSize < 0) ? 'default' : $userSize; |
||
| 112 | $globalValue = ($globalSize < 0) ? 'default' : $globalSize; |
||
| 113 | $this->writeArrayInOutputFormat($input, $output, [ |
||
| 114 | 'user_size' => $userValue, |
||
| 115 | 'global_size' => $globalValue, |
||
| 116 | 'effective_size' => ($userSize < 0) ? $globalValue : $userValue, |
||
| 117 | ]); |
||
| 118 | } |
||
| 119 | } else { |
||
| 120 | $users = []; |
||
| 121 | $this->userManager->callForSeenUsers(function (IUser $user) use (&$users) { |
||
| 122 | $users[] = $user->getUID(); |
||
| 123 | }); |
||
| 124 | $userValues = $this->config->getUserValueForUsers('files_trashbin', 'trashbin_size', $users); |
||
| 125 | |||
| 126 | if ($input->getOption('output') == self::OUTPUT_FORMAT_PLAIN) { |
||
| 127 | $output->writeln("Default size: $globalHumanSize"); |
||
| 128 | $output->writeln(""); |
||
| 129 | if (count($userValues)) { |
||
| 130 | $output->writeln("Per-user sizes:"); |
||
| 131 | $this->writeArrayInOutputFormat($input, $output, array_map(function ($size) { |
||
| 132 | return \OC_Helper::humanFileSize($size); |
||
| 133 | }, $userValues)); |
||
| 134 | } else { |
||
| 135 | $output->writeln("No per-user sizes configured"); |
||
| 136 | } |
||
| 137 | } else { |
||
| 138 | $globalValue = ($globalSize < 0) ? 'default' : $globalSize; |
||
| 139 | $this->writeArrayInOutputFormat($input, $output, [ |
||
| 140 | 'global_size' => $globalValue, |
||
| 141 | 'user_sizes' => $userValues, |
||
| 142 | ]); |
||
| 147 |