From 396b9781293a1988e9fb2aebe686f535bce62ffe Mon Sep 17 00:00:00 2001 From: William Raendchen Date: Fri, 14 Jul 2023 15:17:47 +0200 Subject: [PATCH] add T_MATCH to nestingIncrements --- src/CognitiveComplexity/Analyzer.php | 1 + tests/AnalyzerTest.php | 1 + tests/Data/function12.php.inc | 17 +++++++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 tests/Data/function12.php.inc diff --git a/src/CognitiveComplexity/Analyzer.php b/src/CognitiveComplexity/Analyzer.php index 41ded1a..681f21f 100644 --- a/src/CognitiveComplexity/Analyzer.php +++ b/src/CognitiveComplexity/Analyzer.php @@ -71,6 +71,7 @@ final class Analyzer T_WHILE => T_WHILE, T_DO => T_DO, T_CATCH => T_CATCH, + T_MATCH => T_MATCH, ]; /** diff --git a/tests/AnalyzerTest.php b/tests/AnalyzerTest.php index d635386..6781452 100644 --- a/tests/AnalyzerTest.php +++ b/tests/AnalyzerTest.php @@ -58,6 +58,7 @@ public function provideTokensAndExpectedCognitiveComplexity(): Iterator yield [__DIR__ . '/Data/function9.php.inc', 5]; yield [__DIR__ . '/Data/function10.php.inc', 19]; yield [__DIR__ . '/Data/function11.php.inc', 1]; + yield [__DIR__ . '/Data/function12.php.inc', 6]; } /** diff --git a/tests/Data/function12.php.inc b/tests/Data/function12.php.inc new file mode 100644 index 0000000..3509ba4 --- /dev/null +++ b/tests/Data/function12.php.inc @@ -0,0 +1,17 @@ + $b ? "one" : "uno", // +1 ternary +2 nesting + 2 => "a couple", + 3 => "a few", + default => "lots", + }; + } +} + +// Cognitive Complexity 6