| Conditions | 18 |
| Paths | 8 |
| Total Lines | 46 |
| Code Lines | 32 |
| 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 ($driver[0] !== '\\') { |
||
| 36 | $driver = '\\'.$driver; |
||
| 37 | } |
||
| 38 | if (!class_exists($driver) || !is_a($driver, BasicDriver::class, true)) { |
||
| 39 | throw new \InvalidArgumentException('Class "' . $driver . '" not found or not in BasicDriver children'); |
||
| 40 | } |
||
| 41 | $output->writeln('Supported format by <info>' . $driver . '</info>'); |
||
| 42 | |||
| 43 | $table->setHeaders(['format', 'stream', 'create', 'append', 'update', 'encrypt']); |
||
| 44 | foreach ($driver::getSupportedFormats() as $i => $format) { |
||
| 45 | $table->setRow($i, [ |
||
| 46 | $format, |
||
| 47 | $driver::canStream($format) ? '+' : '', |
||
| 48 | $driver::canCreateArchive($format) ? '+' : '', |
||
| 49 | $driver::canAddFiles($format) ? '+' : '', |
||
| 50 | $driver::canDeleteFiles($format) ? '+' : '', |
||
| 51 | $driver::canEncrypt($format) ? '+' : '', |
||
| 52 | ]); |
||
| 53 | } |
||
| 54 | $table->render(); |
||
| 55 | return 0; |
||
| 56 | } |
||
| 57 | |||
| 58 | $table->setHeaders(['format', 'open', 'stream', 'create', 'append', 'update', 'encrypt', 'drivers']); |
||
| 59 | $i = 0; |
||
| 60 | foreach (Formats::getFormatsReport() as $format => $config) { |
||
| 61 | $table->setRow($i++, [ |
||
| 62 | $format, |
||
| 63 | $config['open'] ? '+' : '', |
||
| 64 | $config['stream'] ? '+' : '', |
||
| 65 | $config['create'] ? '+' : '', |
||
| 66 | $config['append'] ? '+' : '', |
||
| 67 | $config['update'] ? '+' : '', |
||
| 68 | $config['encrypt'] ? '+' : '', |
||
| 69 | new TableCell(implode("\n", $config['drivers']), ['rowspan' => count($config['drivers'])]) |
||
| 70 | ]); |
||
| 71 | } |
||
| 72 | $table->render(); |
||
| 73 | } |
||
| 75 |