Skip to content

Commit 9a4afdb

Browse files
Adding a markdown report generator (#50)
1 parent 7681785 commit 9a4afdb

11 files changed

Lines changed: 864 additions & 2 deletions

src/Business/Cognitive/Exporter/MarkdownExporter.php

Lines changed: 423 additions & 0 deletions
Large diffs are not rendered by default.

src/Business/MetricsFacade.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter\CsvExporter;
1414
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter\HtmlExporter;
1515
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter\JsonExporter;
16+
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter\MarkdownExporter;
1617
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\ScoreCalculator;
1718
use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException;
1819
use Phauthentic\CognitiveCodeAnalysis\Config\CognitiveConfig;
@@ -171,10 +172,13 @@ public function exportMetricsReport(
171172
string $reportType,
172173
string $filename
173174
): void {
175+
$config = $this->configService->getConfig();
176+
174177
match ($reportType) {
175178
'json' => (new JsonExporter())->export($metricsCollection, $filename),
176179
'csv' => (new CsvExporter())->export($metricsCollection, $filename),
177180
'html' => (new HtmlExporter())->export($metricsCollection, $filename),
181+
'markdown' => (new MarkdownExporter($config))->export($metricsCollection, $filename),
178182
default => null,
179183
};
180184
}

src/Command/Handler/CognitiveMetricsReportHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ private function hasIncompleteReportOptions(?string $reportType, ?string $report
5656

5757
private function isValidReportType(?string $reportType): bool
5858
{
59-
return in_array($reportType, ['json', 'csv', 'html']);
59+
return in_array($reportType, ['json', 'csv', 'html', 'markdown']);
6060
}
6161

6262
/**
@@ -80,7 +80,7 @@ private function handleExceptions(Exception $exception): int
8080
public function handleInvalidReporType(?string $reportType): int
8181
{
8282
$this->output->writeln(sprintf(
83-
'<error>Invalid report type `%s` provided. Only `json`, `csv`, and `html` are accepted.</error>',
83+
'<error>Invalid report type `%s` provided. Only `json`, `csv`, `html`, and `markdown` are accepted.</error>',
8484
$reportType
8585
));
8686

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Cognitive Metrics Report
2+
3+
**Generated:** 2023-10-01 12:00:00
4+
5+
**Total Classes:** 2
6+
7+
---
8+
9+
* **Class:** TestClass
10+
* **File:** TestClass.php
11+
12+
| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
13+
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
14+
| testMethod | 10 (0.500) | 2 (0.300) | 1 (0.200) | 5 (0.400) | 3 (0.300) | 4 (0.600) | 2 (0.500) | 1 (0.200) | 0.300 | 573.211 | 12.500 | 7,165.138 | 5 (low) |
15+
| anotherMethod | 5 (0.200) | 1 (0.100) | 1 (0.100) | 2 (0.100) | 1 (0.100) | 1 (0.200) | 1 (0.100) | 0 (0.000) | 0.050 | 185.470 | 6.250 | 1,159.188 | 2 (low) |
16+
17+
---
18+
19+
* **Class:** AnotherClass
20+
* **File:** AnotherClass.php
21+
22+
| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
23+
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
24+
| complexMethod | 20 (1.000) | 4 (0.600) | 3 (0.500) | 10 (0.800) | 5 (0.500) | 8 (1.200) | 3 (1.000) | 4 (0.600) | 0.800 | 1,357.824 | 25.000 | 33,945.600 | 12 (medium) |
25+
26+
---
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Cognitive Metrics Report
2+
3+
**Generated:** 2023-10-01 12:00:00
4+
5+
**Total Classes:** 2
6+
7+
---
8+
9+
* **Class:** TestClass
10+
* **File:** TestClass.php
11+
12+
| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Cyclomatic Complexity |
13+
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
14+
| testMethod | 10 (0.500) | 2 (0.300) | 1 (0.200) | 5 (0.400) | 3 (0.300) | 4 (0.600) | 2 (0.500) | 1 (0.200) | 0.300 | 5 (low) |
15+
| anotherMethod | 5 (0.200) | 1 (0.100) | 1 (0.100) | 2 (0.100) | 1 (0.100) | 1 (0.200) | 1 (0.100) | 0 (0.000) | 0.050 | 2 (low) |
16+
17+
---
18+
19+
* **Class:** AnotherClass
20+
* **File:** AnotherClass.php
21+
22+
| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Cyclomatic Complexity |
23+
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
24+
| complexMethod | 20 (1.000) | 4 (0.600) | 3 (0.500) | 10 (0.800) | 5 (0.500) | 8 (1.200) | 3 (1.000) | 4 (0.600) | 0.800 | 12 (medium) |
25+
26+
---
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Cognitive Metrics Report
2+
3+
**Generated:** 2023-10-01 12:00:00
4+
5+
**Total Classes:** 2
6+
7+
---
8+
9+
* **Class:** TestClass
10+
* **File:** TestClass.php
11+
12+
| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort |
13+
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
14+
| testMethod | 10 (0.500) | 2 (0.300) | 1 (0.200) | 5 (0.400) | 3 (0.300) | 4 (0.600) | 2 (0.500) | 1 (0.200) | 0.300 | 573.211 | 12.500 | 7,165.138 |
15+
| anotherMethod | 5 (0.200) | 1 (0.100) | 1 (0.100) | 2 (0.100) | 1 (0.100) | 1 (0.200) | 1 (0.100) | 0 (0.000) | 0.050 | 185.470 | 6.250 | 1,159.188 |
16+
17+
---
18+
19+
* **Class:** AnotherClass
20+
* **File:** AnotherClass.php
21+
22+
| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort |
23+
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
24+
| complexMethod | 20 (1.000) | 4 (0.600) | 3 (0.500) | 10 (0.800) | 5 (0.500) | 8 (1.200) | 3 (1.000) | 4 (0.600) | 0.800 | 1,357.824 | 25.000 | 33,945.600 |
25+
26+
---
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Cognitive Metrics Report
2+
3+
**Generated:** 2023-10-01 12:00:00
4+
5+
**Total Classes:** 2
6+
7+
---
8+
9+
* **Class:** TestClass
10+
* **File:** TestClass.php
11+
12+
| Method | Cognitive Complexity |
13+
|--------|--------|
14+
| testMethod | 0.300 |
15+
| anotherMethod | 0.050 |
16+
17+
---
18+
19+
* **Class:** AnotherClass
20+
* **File:** AnotherClass.php
21+
22+
| Method | Cognitive Complexity |
23+
|--------|--------|
24+
| complexMethod | 0.800 |
25+
26+
---
27+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Cognitive Metrics Report
2+
3+
**Generated:** 2023-10-01 12:00:00
4+
5+
**Total Classes:** 2
6+
7+
---
8+
9+
* **Class:** TestClass
10+
* **File:** TestClass.php
11+
12+
| Method | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
13+
|--------|--------|--------|--------|--------|--------|
14+
| testMethod | 0.300 | 573.211 | 12.500 | 7,165.138 | 5 (low) |
15+
| anotherMethod | 0.050 | 185.470 | 6.250 | 1,159.188 | 2 (low) |
16+
17+
---
18+
19+
* **Class:** AnotherClass
20+
* **File:** AnotherClass.php
21+
22+
| Method | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
23+
|--------|--------|--------|--------|--------|--------|
24+
| complexMethod | 0.800 | 1,357.824 | 25.000 | 33,945.600 | 12 (medium) |
25+
26+
---
27+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Cognitive Metrics Report
2+
3+
**Generated:** 2023-10-01 12:00:00
4+
5+
## All Methods (3 total)
6+
7+
| Class | Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
8+
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
9+
| TestClass | testMethod | 10 (0.500) | 2 (0.300) | 1 (0.200) | 5 (0.400) | 3 (0.300) | 4 (0.600) | 2 (0.500) | 1 (0.200) | 0.300 | 573.211 | 12.500 | 7,165.138 | 5 (low) |
10+
| TestClass | anotherMethod | 5 (0.200) | 1 (0.100) | 1 (0.100) | 2 (0.100) | 1 (0.100) | 1 (0.200) | 1 (0.100) | 0 (0.000) | 0.050 | 185.470 | 6.250 | 1,159.188 | 2 (low) |
11+
| AnotherClass | complexMethod | 20 (1.000) | 4 (0.600) | 3 (0.500) | 10 (0.800) | 5 (0.500) | 8 (1.200) | 3 (1.000) | 4 (0.600) | 0.800 | 1,357.824 | 25.000 | 33,945.600 | 12 (medium) |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Cognitive Metrics Report
2+
3+
**Generated:** 2023-10-01 12:00:00
4+
5+
**Total Classes:** 2
6+
7+
**Note:** Only showing methods exceeding threshold of 0.100
8+
9+
---
10+
11+
* **Class:** TestClass
12+
* **File:** TestClass.php
13+
14+
| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
15+
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
16+
| testMethod | 10 (0.500) | 2 (0.300) | 1 (0.200) | 5 (0.400) | 3 (0.300) | 4 (0.600) | 2 (0.500) | 1 (0.200) | 0.300 | 573.211 | 12.500 | 7,165.138 | 5 (low) |
17+
18+
---
19+
20+
* **Class:** AnotherClass
21+
* **File:** AnotherClass.php
22+
23+
| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
24+
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
25+
| complexMethod | 20 (1.000) | 4 (0.600) | 3 (0.500) | 10 (0.800) | 5 (0.500) | 8 (1.200) | 3 (1.000) | 4 (0.600) | 0.800 | 1,357.824 | 25.000 | 33,945.600 | 12 (medium) |
26+
27+
---
28+

0 commit comments

Comments
 (0)