Skip to content

Commit

Permalink
Merge branch '9.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Feb 23, 2022
2 parents 864bd21 + 2ea6f33 commit 971bee3
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/StaticAnalysis/ExecutableLinesFindingVisitor.php
Expand Up @@ -10,10 +10,13 @@
namespace SebastianBergmann\CodeCoverage\StaticAnalysis;

use PhpParser\Node;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\NullsafePropertyFetch;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
Expand Down Expand Up @@ -79,6 +82,8 @@ public function enterNode(Node $node): void
*/
public function executableLines(): array
{
sort($this->executableLines);

return $this->executableLines;
}

Expand All @@ -98,12 +103,25 @@ private function savePropertyLines(Node $node): void
*/
private function getLines(Node $node): array
{
if ($node instanceof PropertyFetch ||
if ($node instanceof Cast ||
$node instanceof PropertyFetch ||
$node instanceof NullsafePropertyFetch ||
$node instanceof StaticPropertyFetch) {
return [$node->getEndLine()];
}

if ($node instanceof ArrayDimFetch) {
if (null === $node->dim) {
return [];
}

return [$node->dim->getStartLine()];
}

if ($node instanceof MethodCall) {
return [$node->name->getStartLine()];
}

if ($node instanceof Ternary) {
$lines = [$node->cond->getStartLine()];

Expand All @@ -122,10 +140,12 @@ private function getLines(Node $node): array
private function isExecutable(Node $node): bool
{
return $node instanceof Assign ||
$node instanceof ArrayDimFetch ||
$node instanceof BinaryOp ||
$node instanceof Break_ ||
$node instanceof CallLike ||
$node instanceof Case_ ||
$node instanceof Cast ||
$node instanceof Catch_ ||
$node instanceof Closure ||
$node instanceof Continue_ ||
Expand All @@ -140,6 +160,7 @@ private function isExecutable(Node $node): bool
$node instanceof Foreach_ ||
$node instanceof Goto_ ||
$node instanceof If_ ||
$node instanceof MethodCall ||
$node instanceof NullsafePropertyFetch ||
$node instanceof PropertyFetch ||
$node instanceof Return_ ||
Expand Down
63 changes: 63 additions & 0 deletions tests/_files/source_with_heavy_indentation.php
Expand Up @@ -101,3 +101,66 @@ function () {}
"${b}"
;
}
final class BarS
{
public
function
foo
(
int
$var
=
1
)
{
if (
!
$var
&&
[]
===
(
$columnCollection
=
[]
)
&&
isset
(
$columnCollection
[
$key
]
[
$key
]
)
) {
$dataType
=
$columnCollection
[
$key
]
;

$obj
->
method1
(
)
->
method2
(
)
;

$var[]
;

(string)
$var
;
}
}
}
16 changes: 16 additions & 0 deletions tests/tests/Data/RawCodeCoverageDataTest.php
Expand Up @@ -289,6 +289,7 @@ public function testHeavyIndentationIsHandledCorrectly(): void
$this->assertEquals(
[
9,
12,
15,
16,
18,
Expand All @@ -302,6 +303,7 @@ public function testHeavyIndentationIsHandledCorrectly(): void
48,
54,
60,
64,
71,
83,
85,
Expand All @@ -313,6 +315,20 @@ public function testHeavyIndentationIsHandledCorrectly(): void
97,
99,
101,
116,
117,
120,
123,
132,
135,
139,
143,
147,
149,
153,
158,
161,
162,
],
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file])
);
Expand Down

0 comments on commit 971bee3

Please sign in to comment.