Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
423 changes: 423 additions & 0 deletions src/Business/Cognitive/Exporter/MarkdownExporter.php

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/Business/MetricsFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter\CsvExporter;
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter\HtmlExporter;
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter\JsonExporter;
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\Exporter\MarkdownExporter;
use Phauthentic\CognitiveCodeAnalysis\Business\Cognitive\ScoreCalculator;
use Phauthentic\CognitiveCodeAnalysis\CognitiveAnalysisException;
use Phauthentic\CognitiveCodeAnalysis\Config\CognitiveConfig;
Expand Down Expand Up @@ -170,10 +171,13 @@ public function exportMetricsReport(
string $reportType,
string $filename
): void {
$config = $this->configService->getConfig();

match ($reportType) {
'json' => (new JsonExporter())->export($metricsCollection, $filename),
'csv' => (new CsvExporter())->export($metricsCollection, $filename),
'html' => (new HtmlExporter())->export($metricsCollection, $filename),
'markdown' => (new MarkdownExporter($config))->export($metricsCollection, $filename),
default => null,
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Handler/CognitiveMetricsReportHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private function hasIncompleteReportOptions(?string $reportType, ?string $report

private function isValidReportType(?string $reportType): bool
{
return in_array($reportType, ['json', 'csv', 'html']);
return in_array($reportType, ['json', 'csv', 'html', 'markdown']);
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Cognitive Metrics Report

**Generated:** 2023-10-01 12:00:00

**Total Classes:** 2

---

* **Class:** TestClass
* **File:** TestClass.php

| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
| 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) |
| 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) |

---

* **Class:** AnotherClass
* **File:** AnotherClass.php

| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
| 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) |

---

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Cognitive Metrics Report

**Generated:** 2023-10-01 12:00:00

**Total Classes:** 2

---

* **Class:** TestClass
* **File:** TestClass.php

| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Cyclomatic Complexity |
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
| 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) |
| 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) |

---

* **Class:** AnotherClass
* **File:** AnotherClass.php

| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Cyclomatic Complexity |
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
| 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) |

---

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Cognitive Metrics Report

**Generated:** 2023-10-01 12:00:00

**Total Classes:** 2

---

* **Class:** TestClass
* **File:** TestClass.php

| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort |
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
| 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 |
| 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 |

---

* **Class:** AnotherClass
* **File:** AnotherClass.php

| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort |
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
| 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 |

---

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Cognitive Metrics Report

**Generated:** 2023-10-01 12:00:00

**Total Classes:** 2

---

* **Class:** TestClass
* **File:** TestClass.php

| Method | Cognitive Complexity |
|--------|--------|
| testMethod | 0.300 |
| anotherMethod | 0.050 |

---

* **Class:** AnotherClass
* **File:** AnotherClass.php

| Method | Cognitive Complexity |
|--------|--------|
| complexMethod | 0.800 |

---

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Cognitive Metrics Report

**Generated:** 2023-10-01 12:00:00

**Total Classes:** 2

---

* **Class:** TestClass
* **File:** TestClass.php

| Method | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
|--------|--------|--------|--------|--------|--------|
| testMethod | 0.300 | 573.211 | 12.500 | 7,165.138 | 5 (low) |
| anotherMethod | 0.050 | 185.470 | 6.250 | 1,159.188 | 2 (low) |

---

* **Class:** AnotherClass
* **File:** AnotherClass.php

| Method | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
|--------|--------|--------|--------|--------|--------|
| complexMethod | 0.800 | 1,357.824 | 25.000 | 33,945.600 | 12 (medium) |

---

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Cognitive Metrics Report

**Generated:** 2023-10-01 12:00:00

## All Methods (3 total)

| Class | Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
| 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) |
| 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) |
| 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) |
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Cognitive Metrics Report

**Generated:** 2023-10-01 12:00:00

**Total Classes:** 2

**Note:** Only showing methods exceeding threshold of 0.100

---

* **Class:** TestClass
* **File:** TestClass.php

| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
| 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) |

---

* **Class:** AnotherClass
* **File:** AnotherClass.php

| Method | Lines | Args | Returns | Variables | Property Calls | If | If Nesting | Else | Cognitive Complexity | Halstead Volume | Halstead Difficulty | Halstead Effort | Cyclomatic Complexity |
|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|--------|
| 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) |

---

Loading