Conditions | 13 |
Paths | 17 |
Total Lines | 71 |
Code Lines | 45 |
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 | $driver = $this->resolveDriverName($driver); |
||
36 | if (!class_exists($driver) || !is_a($driver, BasicDriver::class, true)) { |
||
37 | throw new \InvalidArgumentException('Class "' . $driver . '" not found or not in BasicDriver children'); |
||
38 | } |
||
39 | $output->writeln('Supported formats by <info>' . $driver . '</info>'); |
||
40 | |||
41 | $headers = array_keys(Abilities::$abilitiesLabels); |
||
42 | array_unshift($headers, 'format'); |
||
43 | $table->setHeaders($headers); |
||
44 | foreach ($driver::getFormats() as $i => $format) { |
||
45 | $abilities = $driver::getFormatAbilities($format); |
||
46 | $row = [$format]; |
||
47 | |||
48 | foreach (Abilities::$abilitiesLabels as $possibleAbility) { |
||
49 | $row[] = in_array($possibleAbility, $abilities, true) ? '+' : ''; |
||
50 | } |
||
51 | |||
52 | $table->setRow($i, $row); |
||
53 | } |
||
54 | $table->render(); |
||
55 | return 0; |
||
56 | } |
||
57 | |||
58 | $formats = Formats::getSupportedDriverFormats(); |
||
59 | $headers = array_keys($formats); |
||
60 | array_unshift($headers, 'driver type'); |
||
61 | array_unshift($headers, 'driver / format'); |
||
62 | $table->setHeaders($headers); |
||
63 | $rows = []; |
||
64 | |||
65 | /** @var \wapmorgan\UnifiedArchive\Drivers\Basic\BasicDriver $driverClass */ |
||
66 | foreach (Formats::$drivers as $driverClass) { |
||
67 | $row = [ |
||
68 | substr($driverClass, strrpos($driverClass, '\\') + 1), |
||
69 | BasicDriver::$typeLabels[$driverClass::TYPE], |
||
70 | ]; |
||
71 | foreach ($formats as $format => $formatSupportStatus) { |
||
72 | if (isset($formatSupportStatus[$driverClass])) { |
||
73 | $shortcuts = null; |
||
74 | foreach (Abilities::$abilitiesShortCuts as $ability => $abilitiesShortCut) { |
||
75 | if (in_array($ability, $formatSupportStatus[$driverClass], true)) { |
||
76 | $shortcuts .= $abilitiesShortCut; |
||
77 | } |
||
78 | } |
||
79 | $row[] = $shortcuts; |
||
80 | } else { |
||
81 | $row[] = ''; |
||
82 | } |
||
83 | } |
||
84 | $rows[] = $row; |
||
85 | } |
||
86 | |||
87 | $table->setRows($rows); |
||
88 | //$table->setRow($i++, $row); |
||
89 | $table->render(); |
||
90 | |||
91 | foreach (array_combine(array_values(Abilities::$abilitiesShortCuts), array_keys( |
||
92 | Abilities::$abilitiesLabels |
||
93 | )) as $shortCut => $label) { |
||
94 | $output->writeln('<info>' . $shortCut . '</info> - ' . $label); |
||
95 | } |
||
96 | |||
97 | return 0; |
||
98 | } |
||
100 |