Skip to content

Commit ea7bbe0

Browse files
committed
ExecutableLinesFindingVisitor: mirror xDebug/PCOV behavior
1 parent 5b5898f commit ea7bbe0

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
use function array_unique;
1313
use function sort;
1414
use PhpParser\Node;
15+
use PhpParser\Node\Expr\BinaryOp;
16+
use PhpParser\Node\Expr\CallLike;
1517
use PhpParser\Node\Stmt\Break_;
1618
use PhpParser\Node\Stmt\Case_;
1719
use PhpParser\Node\Stmt\Catch_;
@@ -67,7 +69,9 @@ public function executableLines(): array
6769

6870
private function isExecutable(Node $node): bool
6971
{
70-
return $node instanceof Break_ ||
72+
return $node instanceof BinaryOp ||
73+
$node instanceof Break_ ||
74+
$node instanceof CallLike ||
7175
$node instanceof Case_ ||
7276
$node instanceof Catch_ ||
7377
$node instanceof Continue_ ||
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
class Foo
4+
{
5+
public function isOne(): bool
6+
{
7+
return
8+
AType::A === $this->state
9+
or (
10+
$this->isBar()
11+
and \in_array($this->state, [
12+
AType::A,
13+
AType::B,
14+
], true)
15+
)
16+
or (\in_array($this->type, [BType::X, BType::Y], true)
17+
and \in_array($this->state, [
18+
AType::C,
19+
AType::D,
20+
AType::toOutput($this->state),
21+
], true))
22+
;
23+
}
24+
25+
public function isTwo(): bool
26+
{
27+
return \in_array($this->state, [
28+
AType::A,
29+
AType::B,
30+
], true);
31+
}
32+
}

tests/tests/RawCodeCoverageDataTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,25 @@ public function testInlineCommentsKeepTheLine(): void
321321
);
322322
}
323323

324+
public function testHeavyIndentationIsHandledCorrectly(): void
325+
{
326+
$file = TEST_FILES_PATH . 'source_with_heavy_indentation.php';
327+
328+
$this->assertEquals(
329+
[
330+
7,
331+
8,
332+
10,
333+
11,
334+
16,
335+
17,
336+
20,
337+
27,
338+
],
339+
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingUncoveredFileAnalyser)->lineCoverage()[$file])
340+
);
341+
}
342+
324343
public function testCoverageForFileWithInlineAnnotations(): void
325344
{
326345
$filename = TEST_FILES_PATH . 'source_with_oneline_annotations.php';

0 commit comments

Comments
 (0)