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