Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer authored Sep 21, 2024
2 parents 276b848 + 9bc428c commit d600b28
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
53 changes: 25 additions & 28 deletions src/Command/Presentation/CognitiveMetricTextRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,25 @@ public function render(CognitiveMetricsCollection $metricsCollection, array $bas

$table->setRows($rows);
$table->render();

$output->writeln("");
}
}

/**
* @return string[]
*/
protected function getTableHeaders(): array
protected function renderTable(OutputInterface $output, CognitiveMetricsCollection $metricsCollection): void
{
return [
"Method Name",
"Lines",
"Arguments",
"Returns",
"Variables",
"Property\nAccesses",
"If",
"If Nesting\nLevel",
"Else",
"Cognitive\nComplexity"
];
$table = new Table($output);
$table->setStyle('box');
$table->setHeaders($this->tableHeaders);

Check failure on line 50 in src/Command/Presentation/CognitiveMetricTextRenderer.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Access to an undefined property Phauthentic\CodeQualityMetrics\Command\Presentation\CognitiveMetricTextRenderer::$tableHeaders.

Check failure on line 50 in src/Command/Presentation/CognitiveMetricTextRenderer.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Access to an undefined property Phauthentic\CodeQualityMetrics\Command\Presentation\CognitiveMetricTextRenderer::$tableHeaders.

$rows = [];
foreach ($metricsCollection as $metric) {
$rows[] = $this->prepareTableRow($metric);

Check failure on line 54 in src/Command/Presentation/CognitiveMetricTextRenderer.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Method Phauthentic\CodeQualityMetrics\Command\Presentation\CognitiveMetricTextRenderer::prepareTableRow() invoked with 1 parameter, 2 required.

Check failure on line 54 in src/Command/Presentation/CognitiveMetricTextRenderer.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Method Phauthentic\CodeQualityMetrics\Command\Presentation\CognitiveMetricTextRenderer::prepareTableRow() invoked with 1 parameter, 2 required.
;
}

$table->setRows($rows);
$table->render();
}

/**
Expand All @@ -78,21 +76,20 @@ protected function prepareTableRow(CognitiveMetrics $metrics, array $baseline):
'ifCount' => $metrics->getIfCount(),
'ifNestingLevel' => $metrics->getIfNestingLevel(),
'elseCount' => $metrics->getElseCount(),
'score' => $metrics->getScore() > 0.5 ? '<error>' . $metrics->getScore() . '</error>' : '<info>' . $metrics->getScore() . '</info>',
'score' => $metrics->getScore() > $this->scoreThreshold ? '<error>' . $metrics->getScore() . '</error>' : '<info>' . $metrics->getScore() . '</info>',

Check failure on line 79 in src/Command/Presentation/CognitiveMetricTextRenderer.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Access to an undefined property Phauthentic\CodeQualityMetrics\Command\Presentation\CognitiveMetricTextRenderer::$scoreThreshold.

Check failure on line 79 in src/Command/Presentation/CognitiveMetricTextRenderer.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Access to an undefined property Phauthentic\CodeQualityMetrics\Command\Presentation\CognitiveMetricTextRenderer::$scoreThreshold.
];

$keys = [
'lineCount',
'argCount',
'returnCount',
'variableCount',
'propertyCallCount',
'ifCount',
'ifNestingLevel',
'elseCount',
];
return $this->formatValues($row, $metrics);
}

foreach ($keys as $key) {
/**
* @param array<string, mixed> $row
* @param CognitiveMetrics $metrics
* @return array<string, mixed>
*/
protected function formatValues(array $row, CognitiveMetrics $metrics): array
{
foreach ($this->keys as $key) {

Check failure on line 92 in src/Command/Presentation/CognitiveMetricTextRenderer.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Access to an undefined property Phauthentic\CodeQualityMetrics\Command\Presentation\CognitiveMetricTextRenderer::$keys.

Check failure on line 92 in src/Command/Presentation/CognitiveMetricTextRenderer.php

View workflow job for this annotation

GitHub Actions / Coding Standard & Static Analysis

Access to an undefined property Phauthentic\CodeQualityMetrics\Command\Presentation\CognitiveMetricTextRenderer::$keys.
$getMethod = 'get' . $key;
$getMethodWeight = 'get' . $key . 'Weight';
$weight = $metrics->{$getMethodWeight}();
Expand Down
3 changes: 3 additions & 0 deletions src/PhpParser/CognitiveMetricsVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ private function setCurrentClassOnEnterNode(Node $node): bool
if ($node->name === null) {
return false;
}

$this->currentClassName = $this->currentNamespace . '\\' . $node->name->toString();
}

Expand Down Expand Up @@ -263,6 +264,8 @@ private function writeMetricsOnLeaveNode(Node $node): void
$this->methodMetrics[$method]['if_count'] = $this->ifCount;
$this->methodMetrics[$method]['if_nesting_level'] = $this->maxIfNestingLevel;
$this->methodMetrics[$method]['else_count'] = $this->elseCount;
$this->methodMetrics[$method]['line_count'] = $node->getEndLine() - $node->getStartLine() + 1;
$this->methodMetrics[$method]['arg_count'] = count($node->getParams());
$this->currentMethod = '';
}
}
Expand Down

0 comments on commit d600b28

Please sign in to comment.