Skip to content

Commit 8723866

Browse files
committed
added more testcases
1 parent 82ffd0a commit 8723866

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

lib/BaselineAnalyzer.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ public function analyze():AnalyzerResult {
1818
}
1919

2020
preg_match('/Class cognitive complexity is (?P<value>\d+), keep it under (?P<limit>\d+)/', $errorMessage, $matches);
21-
22-
$result->overallComplexity += $matches['value'];
21+
if ($matches) {
22+
$result->overallComplexity += $matches['value'];
23+
}
2324
}
2425

2526
return $result;

tests/BaselineAnalyzerTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88

99
class BaselineAnalyzerTest extends TestCase
1010
{
11+
function testAllInComplexity()
12+
{
13+
$analyzer = new BaselineAnalyzer(Baseline::forFile(__DIR__ . '/fixtures/all-in.neon'));
14+
$result = $analyzer->analyze();
15+
16+
$this->assertSame(70, $result->overallComplexity);
17+
}
18+
1119
function testClassComplexity()
1220
{
1321
$analyzer = new BaselineAnalyzer(Baseline::forFile(__DIR__ . '/fixtures/class-complexity.neon'));
@@ -16,4 +24,12 @@ function testClassComplexity()
1624
$this->assertSame(26, $result->overallComplexity);
1725
}
1826

27+
function testMethodComplexityIgnored()
28+
{
29+
$analyzer = new BaselineAnalyzer(Baseline::forFile(__DIR__ . '/fixtures/method-complexity.neon'));
30+
$result = $analyzer->analyze();
31+
32+
$this->assertSame(0, $result->overallComplexity);
33+
}
34+
1935
}

tests/fixtures/all-in.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ parameters:
2020
count: 1
2121
path: controllers/ApplicationController.php
2222

23+
-
24+
message: "#^Class cognitive complexity is 22, keep it under 30$#"
25+
count: 1
26+
path: controllers/ApplicationController.php
27+
2328
-
2429
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
2530
count: 10

tests/fixtures/method-complexity.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ parameters:
99
message: "#^Cognitive complexity for \"ApplicationController\\:\\:app_init\\(\\)\" is 12, keep it under 10$#"
1010
count: 1
1111
path: controllers/ApplicationController.php
12+
13+
-
14+
message: "#^Cognitive complexity for \"ApplicationController\\:\\:app_init\\(\\)\" is 22, keep it under 10$#"
15+
count: 1
16+
path: controllers/ApplicationController.php

0 commit comments

Comments
 (0)