From 396b9781293a1988e9fb2aebe686f535bce62ffe Mon Sep 17 00:00:00 2001 From: William Raendchen Date: Fri, 14 Jul 2023 15:17:47 +0200 Subject: [PATCH 1/2] 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 From 6c3e721d277981beaa24ddc37cb2551463fb4928 Mon Sep 17 00:00:00 2001 From: William Raendchen <105014007+epic-64@users.noreply.github.com> Date: Sun, 25 Feb 2024 00:36:36 +0100 Subject: [PATCH 2/2] Update tests.yml --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 61a9d9f..2418569 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,7 @@ on: jobs: tests: - runs-on: ubuntu-18.04 + runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 @@ -35,4 +35,4 @@ jobs: - run: composer install --no-interaction - name: PHPUnit - run: phpunit --coverage-text \ No newline at end of file + run: phpunit --coverage-text