csv = $csv; parent::__construct(); } /** * Get configuration. */ protected function configure(): void { $this->setName('rprt'); $this->setDescription('Generate monthly report'); // @TODO $this->addUsage(''); $this->addOption('file', 'f', InputOption::VALUE_REQUIRED, 'Specify the input csv file to generate report from.'); } protected function execute(InputInterface $input, OutputInterface $output): int { if ($file = $input->getOption('file')) { $data = $this->csv->getReportData($file); $table = $this->generateTable($output, $data); $table->render(); return Command::SUCCESS; } $this->dummyOutput($input, $output); return Command::SUCCESS; } protected function generateTable($output, $data) { // @TODO - get configuration $table = new Table($output); $table->setHeaders(['Project', 'Hours']); $rows = []; $together = 0; foreach ($data as $project => $hours) { $row = [$project, $hours/60]; $together += $hours / 60; $rows[] = $row; } $rows[] = new TableSeparator(); $rows[] = ['Zusamen', $together]; $table->setRows($rows); return $table; } /** * Dummy output for testing. */ protected function dummyOutput(InputInterface $input, OutputInterface $output): void { $output->writeln('I will output a nice table.'); $table = New Table($output); $table->setHeaders(['Project', 'Hours', 'Price']); $table->setRows([ ['LDP', 100, 2600], ['WV', 50, 1300], new TableSeparator(), ['Zusamen', 150, 3900], ]); // $table->setStyle('borderless'); $table->render(); } }