wowstack /
php-dbc-parser
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Wowstack\Dbc\Command; |
||
| 6 | |||
| 7 | use Symfony\Component\Console\Command\Command; |
||
| 8 | use Symfony\Component\Console\Input\InputArgument; |
||
| 9 | use Symfony\Component\Console\Input\InputInterface; |
||
| 10 | use Symfony\Component\Console\Input\InputOption; |
||
| 11 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 12 | use Symfony\Component\Console\Style\SymfonyStyle; |
||
| 13 | use Wowstack\Dbc\DBC; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @codeCoverageIgnore |
||
| 17 | */ |
||
| 18 | class InspectCommand extends Command |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * {@inheritdoc} |
||
| 22 | */ |
||
| 23 | protected function configure() |
||
| 24 | { |
||
| 25 | $this |
||
| 26 | ->setName('dbc:inspect') |
||
| 27 | ->setDescription('Inspect a DBC file.') |
||
| 28 | ->setHelp('This command allows you to inspect any DBC file and receive basic information about it.') |
||
| 29 | ; |
||
| 30 | |||
| 31 | $this |
||
| 32 | ->addArgument('file', InputArgument::REQUIRED, 'Path to the DBC file') |
||
| 33 | ; |
||
| 34 | |||
| 35 | $this |
||
| 36 | ->addOption( |
||
| 37 | 'string-samples', |
||
| 38 | null, |
||
| 39 | InputOption::VALUE_REQUIRED, |
||
| 40 | 'Print selected number of string samples', |
||
| 41 | 10 |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 49 | { |
||
| 50 | $DBC = new DBC($input->getArgument('file')); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 51 | |||
| 52 | $io = new SymfonyStyle($input, $output); |
||
| 53 | $io->title('DBC Inspect'); |
||
| 54 | $io->section('Stats'); |
||
| 55 | $io->text([ |
||
| 56 | sprintf( |
||
| 57 | 'The %s file contains %u rows at %u bytes per column, split into %u fields.', |
||
| 58 | $DBC->getName(), |
||
| 59 | $DBC->getRecordCount(), |
||
| 60 | $DBC->getRecordSize(), |
||
| 61 | $DBC->getFieldCount() |
||
| 62 | ), |
||
| 63 | '', |
||
| 64 | ]); |
||
| 65 | |||
| 66 | if ($DBC->hasStrings()) { |
||
| 67 | $string_block = $DBC->getStringBlock(); |
||
|
0 ignored issues
–
show
|
|||
| 68 | $io->section('Strings'); |
||
| 69 | $io->text([ |
||
| 70 | sprintf( |
||
| 71 | 'The %s file contains %u strings.', |
||
| 72 | $DBC->getName(), |
||
| 73 | count($string_block) |
||
|
0 ignored issues
–
show
|
|||
| 74 | ), |
||
| 75 | '', |
||
| 76 | ]); |
||
| 77 | |||
| 78 | $string_samples = $input->getOption('string-samples'); |
||
|
0 ignored issues
–
show
|
|||
| 79 | |||
| 80 | foreach ($string_block as $index => $string) { |
||
|
0 ignored issues
–
show
|
|||
| 81 | $io->text([$index.': '.$string]); |
||
|
0 ignored issues
–
show
|
|||
| 82 | --$string_samples; |
||
|
0 ignored issues
–
show
|
|||
| 83 | if (0 === $string_samples) { |
||
|
0 ignored issues
–
show
|
|||
| 84 | break; |
||
| 85 | } |
||
| 86 | } |
||
| 87 | } |
||
| 88 | $io->newLine(); |
||
| 89 | } |
||
| 90 | } |
||
| 91 |