*/ class StatsCommand extends Command { /** * {@inheritdoc} */ protected function configure() { $this ->setName('stats') ->setDescription('Show stats about GIST') ->setHelp(<<getSilexApplication()['gist']; $gists = $gistService->getGists(); $languages = []; $withEncryption = []; $commits = []; $total = 0; foreach ($gists as $gist) { $total++; if (!array_key_exists($gist->getType(), $languages)) { $languages[$gist->getType()] = 0; $withEncryption[$gist->getType()] = 0; $commits[$gist->getType()] = 0; } if ($gist->getCipher()) { $withEncryption[$gist->getType()]++; } $languages[$gist->getType()]++; $commits[$gist->getType()] += $gist->getCommits(); } $output->writeln(['Gists statistics', '']); $table = new Table($output); $table ->setHeaders(array('Without encryption', 'With encryption', 'Commits', 'Total')) ->setRows(array( array( $total - $v = array_sum($withEncryption), $v, array_sum($commits), $total ), )) ; $table->render(); ksort($languages); ksort($withEncryption); ksort($commits); $output->writeln(['', 'Details by type', '']); $table->setHeaders(array( 'Type', 'Without encryption', 'With encryption', 'Commits', 'Total', )); $rows = []; foreach ($languages as $lang => $total) { $totalWithoutEncyption = $total - $withEncryption[$lang]; $totalWithEncryption = $total - $totalWithoutEncyption; $rows[] = array( $lang, $totalWithoutEncyption, $totalWithEncryption, $commits[$lang], $total, ); } $table->setRows($rows); $table->render(); } }