From 56d61bd80651d629826a488dc2cf7bb0e4e0d609 Mon Sep 17 00:00:00 2001 From: Aleksa Nikolic Date: Sun, 31 Dec 2023 15:50:02 +0100 Subject: [PATCH] feat: Added method and class method average cyclomatic complexity insights --- docs/insights/complexity.md | 38 ++++++- src/Domain/Collector.php | 12 +- ...ethodAverageCyclomaticComplexityIsHigh.php | 104 ++++++++++++++++++ .../Insights/CyclomaticComplexityIsHigh.php | 15 ++- .../MethodCyclomaticComplexityIsHigh.php | 88 +++++++++++++++ src/Domain/Metrics/Complexity/Complexity.php | 4 + src/Domain/Results.php | 35 ++++-- ...dAverageCyclomaticComplexityIsHighTest.php | 88 +++++++++++++++ .../Fixtures/ClassWithComplexMethod.php | 34 ++++++ .../ClassWithHighMethodAverageComplexity.php | 76 +++++++++++++ .../MethodCyclomaticComplexityIsHighTest.php | 90 +++++++++++++++ 11 files changed, 567 insertions(+), 17 deletions(-) create mode 100644 src/Domain/Insights/ClassMethodAverageCyclomaticComplexityIsHigh.php create mode 100644 src/Domain/Insights/MethodCyclomaticComplexityIsHigh.php create mode 100644 tests/Domain/Insights/ClassMethodAverageCyclomaticComplexityIsHighTest.php create mode 100644 tests/Domain/Insights/Fixtures/ClassWithComplexMethod.php create mode 100644 tests/Domain/Insights/Fixtures/ClassWithHighMethodAverageComplexity.php create mode 100644 tests/Domain/Insights/MethodCyclomaticComplexityIsHighTest.php diff --git a/docs/insights/complexity.md b/docs/insights/complexity.md index c6268c4a..e53925d8 100644 --- a/docs/insights/complexity.md +++ b/docs/insights/complexity.md @@ -1,12 +1,12 @@ # Complexity -For now the Complexity section is only one Insight in one Metric: +For now the Complexity section is only one Metric consisting of multiple insights: * `NunoMaduro\PhpInsights\Domain\Metrics\Complexity\Complexity` -## Cyclomatic Complexity is high +## Class Cyclomatic Complexity is high -This insight checks complexity cyclomatic on your classes, the lower the score the easier your code is to understand. It raises an issue if complexity is over `5`. +This insight checks total method cyclomatic complexity of each class, the lower the score the easier your code is to understand. It raises an issue if complexity is over `5`. **Insight Class**: `NunoMaduro\PhpInsights\Domain\Insights\CyclomaticComplexityIsHigh` @@ -20,6 +20,38 @@ This insight checks complexity cyclomatic on your classes, the lower the score t ``` +## Average Class Method Cyclomatic Complexity is high + +This insight checks average class method cyclomatic complexity, the lower the score the easier your code is to understand. It raises an issue if complexity is over `5.0`. + +**Insight Class**: `NunoMaduro\PhpInsights\Domain\Insights\ClassMethodAverageCyclomaticComplexityIsHigh` + +
+ Configuration + +```php +\NunoMaduro\PhpInsights\Domain\Insights\ClassMethodAverageCyclomaticComplexityIsHigh::class => [ + 'maxClassMethodAverageComplexity' => 5.0, +] +``` +
+ +## Method Cyclomatic Complexity is high + +This insight checks cyclomatic complexity of your methods, the lower the score the easier your code is to understand. It raises an issue if complexity is over `5`. + +**Insight Class**: `NunoMaduro\PhpInsights\Domain\Insights\MethodCyclomaticComplexityIsHigh` + +
+ Configuration + +```php +\NunoMaduro\PhpInsights\Domain\Insights\MethodCyclomaticComplexityIsHigh::class => [ + 'maxMethodComplexity' => 5, +] +``` +
+