Skip to content

Commit 17d8707

Browse files
authored
Merge pull request #1 from Allemweich/add-t-match-to-nesting-increments
add T_MATCH to nestingIncrements
2 parents 620a161 + 396b978 commit 17d8707

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/CognitiveComplexity/Analyzer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ final class Analyzer
7171
T_WHILE => T_WHILE,
7272
T_DO => T_DO,
7373
T_CATCH => T_CATCH,
74+
T_MATCH => T_MATCH,
7475
];
7576

7677
/**

tests/AnalyzerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function provideTokensAndExpectedCognitiveComplexity(): Iterator
5858
yield [__DIR__ . '/Data/function9.php.inc', 5];
5959
yield [__DIR__ . '/Data/function10.php.inc', 19];
6060
yield [__DIR__ . '/Data/function11.php.inc', 1];
61+
yield [__DIR__ . '/Data/function12.php.inc', 6];
6162
}
6263

6364
/**

tests/Data/function12.php.inc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
function matchIncrementsNesting($number) {
4+
$a = true;
5+
$b = true;
6+
7+
if ($a) { // +1 if
8+
match ($number) { // +1 match +1 nesting
9+
1 => $b ? "one" : "uno", // +1 ternary +2 nesting
10+
2 => "a couple",
11+
3 => "a few",
12+
default => "lots",
13+
};
14+
}
15+
}
16+
17+
// Cognitive Complexity 6

0 commit comments

Comments
 (0)