Skip to content

Commit 478cdfb

Browse files
Slamdunkmvorisek
authored andcommitted
Gather CC of empty functions too
1 parent 6f7ffe4 commit 478cdfb

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
use PhpParser\Node\Stmt\Finally_;
4040
use PhpParser\Node\Stmt\For_;
4141
use PhpParser\Node\Stmt\Foreach_;
42+
use PhpParser\Node\Stmt\Function_;
4243
use PhpParser\Node\Stmt\Goto_;
4344
use PhpParser\Node\Stmt\If_;
4445
use PhpParser\Node\Stmt\Property;
@@ -244,6 +245,14 @@ private function getLines(NodeAbstract $node, bool $fromReturns): array
244245
return [$this->getNodeStartLine($node->cond)];
245246
}
246247

248+
if ($node instanceof Function_) {
249+
if ($node->stmts === []) {
250+
return [$node->getEndLine()];
251+
}
252+
253+
return [];
254+
}
255+
247256
return [$this->getNodeStartLine($node)];
248257
}
249258

@@ -304,6 +313,7 @@ private function isExecutable(Node $node): bool
304313
$node instanceof Finally_ ||
305314
$node instanceof For_ ||
306315
$node instanceof Foreach_ ||
316+
$node instanceof Function_ ||
307317
$node instanceof Goto_ ||
308318
$node instanceof If_ ||
309319
$node instanceof Match_ ||

tests/_files/source_with_oneline_annotations.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,7 @@ function baz()
3434

3535
print '*';
3636
}
37+
38+
function xyz()
39+
{
40+
}

tests/tests/Data/RawCodeCoverageDataTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ public function testInlineCommentsKeepTheLine(): void
312312

313313
$this->assertEquals(
314314
[
315+
13,
315316
19,
316317
22,
317318
26,
@@ -320,6 +321,7 @@ public function testInlineCommentsKeepTheLine(): void
320321
32,
321322
33,
322323
35,
324+
40,
323325
],
324326
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file])
325327
);

0 commit comments

Comments
 (0)