| Conditions | 16 |
| Paths | 46 |
| Total Lines | 64 |
| 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 |
||
| 27 | public function execute(InputInterface $input, OutputInterface $output) |
||
| 28 | { |
||
| 29 | $table = new Table($output); |
||
| 30 | |||
| 31 | /** @var string|BasicDriver $driver */ |
||
| 32 | $driver = $input->getArgument('driver'); |
||
| 33 | |||
| 34 | if ($driver !== null) { |
||
|
|
|||
| 35 | if (strpos($driver, '\\') === false) { |
||
| 36 | if (class_exists('\\wapmorgan\\UnifiedArchive\\Drivers\\' . $driver)) { |
||
| 37 | $driver = '\\wapmorgan\\UnifiedArchive\\Drivers\\' . $driver; |
||
| 38 | } else if (class_exists('\\wapmorgan\\UnifiedArchive\\Drivers\\OneFile\\' . $driver)) { |
||
| 39 | $driver = '\\wapmorgan\\UnifiedArchive\\Drivers\\OneFile\\' . $driver; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | if ($driver[0] !== '\\') { |
||
| 43 | $driver = '\\'.$driver; |
||
| 44 | } |
||
| 45 | if (!class_exists($driver) || !is_a($driver, BasicDriver::class, true)) { |
||
| 46 | throw new \InvalidArgumentException('Class "' . $driver . '" not found or not in BasicDriver children'); |
||
| 47 | } |
||
| 48 | $output->writeln('Supported formats by <info>' . $driver . '</info>'); |
||
| 49 | |||
| 50 | $table->setHeaders(['format', ...array_keys(self::$abilitiesLabels)]); |
||
| 51 | foreach ($driver::getSupportedFormats() as $i => $format) { |
||
| 52 | $abilities = $driver::checkFormatSupport($format); |
||
| 53 | $row = [$format]; |
||
| 54 | |||
| 55 | foreach (self::$abilitiesLabels as $possibleAbility) { |
||
| 56 | $row[] = in_array($possibleAbility, $abilities, true) ? '+' : ''; |
||
| 57 | } |
||
| 58 | |||
| 59 | $table->setRow($i, $row); |
||
| 60 | } |
||
| 61 | $table->render(); |
||
| 62 | return 0; |
||
| 63 | } |
||
| 64 | |||
| 65 | $headers = array_map(function ($v) { return substr($v, strrpos($v, '\\') + 1);}, Formats::$drivers); |
||
| 66 | array_unshift($headers, 'format'); |
||
| 67 | |||
| 68 | $table->setHeaders($headers); |
||
| 69 | $i = 0; |
||
| 70 | foreach (Formats::getSupportedDriverFormats() as $format => $formatSupportStatus) { |
||
| 71 | $row = [$format]; |
||
| 72 | foreach (Formats::$drivers as $driverClass) { |
||
| 73 | if (isset($formatSupportStatus[$driverClass])) { |
||
| 74 | $shortcuts = null; |
||
| 75 | foreach (self::$abilitiesShortCuts as $ability => $abilitiesShortCut) { |
||
| 76 | if (in_array($ability, $formatSupportStatus[$driverClass], true)) { |
||
| 77 | $shortcuts .= $abilitiesShortCut; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | $row[] = $shortcuts; |
||
| 81 | } else { |
||
| 82 | $row[] = ''; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | |||
| 86 | $table->setRow($i++, $row); |
||
| 87 | } |
||
| 88 | $table->render(); |
||
| 89 | |||
| 90 | return 0; |
||
| 91 | } |
||
| 93 |