| Conditions | 7 |
| Paths | 24 |
| Total Lines | 59 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 51 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 52 | { |
||
| 53 | $DBC = new DBC($input->getArgument('file'), Mapping::fromYAML($input->getArgument('map'))); |
||
| 54 | $io = new SymfonyStyle($input, $output); |
||
| 55 | $table = new Table($output); |
||
| 56 | |||
| 57 | $io->title('DBC Viewer'); |
||
| 58 | $io->section('Stats'); |
||
| 59 | $io->text([ |
||
| 60 | sprintf( |
||
| 61 | 'The %s file contains %u rows at %u bytes per column, split into %u fields.', |
||
| 62 | $DBC->getName(), |
||
| 63 | $DBC->getRecordCount(), |
||
| 64 | $DBC->getRecordSize(), |
||
| 65 | $DBC->getFieldCount() |
||
| 66 | ), |
||
| 67 | '', |
||
| 68 | ]); |
||
| 69 | |||
| 70 | if ($DBC->hasStrings()) { |
||
| 71 | $string_block = $DBC->getStringBlock(); |
||
| 72 | $io->section('Strings'); |
||
| 73 | $io->text([ |
||
| 74 | sprintf( |
||
| 75 | 'The %s file contains %u strings.', |
||
| 76 | $DBC->getName(), |
||
| 77 | count($string_block) |
||
| 78 | ), |
||
| 79 | '', |
||
| 80 | ]); |
||
| 81 | } |
||
| 82 | $io->newLine(); |
||
| 83 | |||
| 84 | $rows = $input->getOption('rows'); |
||
| 85 | $table->setHeaders($DBC->getMap()->getFieldNames()); |
||
| 86 | |||
| 87 | foreach ($DBC as $index => $record) { |
||
| 88 | $table->addRow($record->read()); |
||
| 89 | |||
| 90 | if (false !== $rows) { |
||
| 91 | --$rows; |
||
| 92 | if (0 === $rows) { |
||
| 93 | break; |
||
| 94 | } |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | $table->render(); |
||
| 99 | $io->newLine(); |
||
| 100 | |||
| 101 | $errors = $DBC->getErrors(); |
||
| 102 | if (count($errors) > 0) { |
||
| 103 | $io->section('Errors'); |
||
| 104 | foreach ($DBC->getErrors() as $error) { |
||
| 105 | $io->text([ |
||
| 106 | '#'.$error['record'].' ('.$error['type'].'/'.$error['field'].'): '.$error['hint'], |
||
| 107 | ]); |
||
| 108 | } |
||
| 109 | $io->newLine(); |
||
| 110 | } |
||
| 113 |