diff --git a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php index ae0b08ae7..c066c3848 100644 --- a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php +++ b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php @@ -10,9 +10,7 @@ namespace SebastianBergmann\CodeCoverage\StaticAnalysis; use PhpParser\Node; -use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp; use PhpParser\Node\Expr\CallLike; @@ -150,22 +148,6 @@ private function getLines(Node $node): array return [$node->dim->getStartLine()]; } - if ($node instanceof Array_) { - $startLine = $node->getStartLine(); - - if (isset($this->executableLines[$startLine])) { - return []; - } - - if ([] === $node->items) { - return [$node->getEndLine()]; - } - - if ($node->items[0] instanceof ArrayItem) { - return [$node->items[0]->getStartLine()]; - } - } - if ($node instanceof ClassMethod) { if ($node->name->name !== '__construct') { return []; @@ -235,7 +217,6 @@ private function isExecutable(Node $node): bool { return $node instanceof Assign || $node instanceof ArrayDimFetch || - $node instanceof Array_ || $node instanceof BinaryOp || $node instanceof Break_ || $node instanceof CallLike || diff --git a/tests/_files/source_with_return_and_array_with_scalars.php b/tests/_files/source_with_return_and_array_with_scalars.php index 033d04d5b..5b2f69670 100644 --- a/tests/_files/source_with_return_and_array_with_scalars.php +++ b/tests/_files/source_with_return_and_array_with_scalars.php @@ -62,4 +62,24 @@ public function eigth(): void return ; } + + /** + * Array expression must not add executable line to make uncovered + * output consistent with output from real coverage driver like Xdebug. + * + * @see https://github.com/sebastianbergmann/php-code-coverage/pull/938 + */ + public function nineNestedArray(): array + { + return [ + [], + [[]], + [[ + 'test', + 'test' => [ + [[[false]]] + ] + ]], + ]; + } } diff --git a/tests/tests/Data/RawCodeCoverageDataTest.php b/tests/tests/Data/RawCodeCoverageDataTest.php index c0aba6373..602449de0 100644 --- a/tests/tests/Data/RawCodeCoverageDataTest.php +++ b/tests/tests/Data/RawCodeCoverageDataTest.php @@ -272,7 +272,6 @@ public function testUseStatementsAreUncovered(): void [ 12, 14, - 15, 16, 18, ], @@ -300,7 +299,6 @@ public function testInterfacesAreUncovered(): void [ 7, 9, - 10, 11, 13, ], @@ -342,7 +340,6 @@ public function testHeavyIndentationIsHandledCorrectly(): void 25, 28, 31, - 36, 40, 46, 48, @@ -364,7 +361,6 @@ public function testHeavyIndentationIsHandledCorrectly(): void 117, 120, 123, - 125, // This shouldn't be marked as LoC, but it's high unlikely to happen IRL to have $var = []; on multiple lines 132, 135, 139, @@ -415,14 +411,15 @@ public function testReturnStatementWithOnlyAnArrayWithScalarReturnsTheFirstEleme $this->assertEquals( [ - 8, + 7, 15, - 24, + 22, 30, - 40, + 39, 47, 54, 63, + 74, ], array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file]) );