diff --git a/src/Command/Presentation/CognitiveMetricTextRenderer.php b/src/Command/Presentation/CognitiveMetricTextRenderer.php index cad9d80..cd2737d 100644 --- a/src/Command/Presentation/CognitiveMetricTextRenderer.php +++ b/src/Command/Presentation/CognitiveMetricTextRenderer.php @@ -38,25 +38,27 @@ public function render(CognitiveMetricsCollection $metricsCollection, array $bas $table->setRows($rows); $table->render(); - $output->writeln(""); } } - protected function renderTable(OutputInterface $output, CognitiveMetricsCollection $metricsCollection): void + /** + * @return string[] + */ + protected function getTableHeaders(): array { - $table = new Table($output); - $table->setStyle('box'); - $table->setHeaders($this->tableHeaders); - - $rows = []; - foreach ($metricsCollection as $metric) { - $rows[] = $this->prepareTableRow($metric); - ; - } - - $table->setRows($rows); - $table->render(); + return [ + "Method Name", + "Lines", + "Arguments", + "Returns", + "Variables", + "Property\nAccesses", + "If", + "If Nesting\nLevel", + "Else", + "Cognitive\nComplexity" + ]; } /** @@ -76,20 +78,21 @@ protected function prepareTableRow(CognitiveMetrics $metrics, array $baseline): 'ifCount' => $metrics->getIfCount(), 'ifNestingLevel' => $metrics->getIfNestingLevel(), 'elseCount' => $metrics->getElseCount(), - 'score' => $metrics->getScore() > $this->scoreThreshold ? '' . $metrics->getScore() . '' : '' . $metrics->getScore() . '', + 'score' => $metrics->getScore() > 0.5 ? '' . $metrics->getScore() . '' : '' . $metrics->getScore() . '', ]; - return $this->formatValues($row, $metrics); - } + $keys = [ + 'lineCount', + 'argCount', + 'returnCount', + 'variableCount', + 'propertyCallCount', + 'ifCount', + 'ifNestingLevel', + 'elseCount', + ]; - /** - * @param array $row - * @param CognitiveMetrics $metrics - * @return array - */ - protected function formatValues(array $row, CognitiveMetrics $metrics): array - { - foreach ($this->keys as $key) { + foreach ($keys as $key) { $getMethod = 'get' . $key; $getMethodWeight = 'get' . $key . 'Weight'; $weight = $metrics->{$getMethodWeight}();