Skip to content

Commit 7a0ff15

Browse files
committed
fix nested array analysis
1 parent db61a96 commit 7a0ff15

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private function getLines(NodeAbstract $node, bool $fromReturns): array
250250
}
251251

252252
if ($node instanceof Case_) {
253-
if (null === $node->cond) {
253+
if (null === $node->cond) { // default case
254254
return [];
255255
}
256256

@@ -290,7 +290,7 @@ private function getNodeStartLine(NodeAbstract $node): int
290290
return $node->getEndLine();
291291
}
292292

293-
return $this->getNodeStartLine($node->items[0]);
293+
return $this->getNodeStartLine($node->items[0]->value);
294294
}
295295

296296
if ($node instanceof Assign) {

tests/_files/source_with_multiline_constant_return.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,4 +509,60 @@ public function emptyMethodWithComment(): void
509509
{
510510
// empty method with comment
511511
}
512+
513+
public function simpleConstArrayEmpty(): array
514+
{
515+
return
516+
[
517+
// empty array with comment
518+
];
519+
}
520+
521+
public function nestedConstArrayEmpty(): array
522+
{
523+
return
524+
[
525+
[
526+
// empty subarray with comment
527+
]
528+
];
529+
}
530+
531+
public function nestedConstArrayOne(): array
532+
{
533+
return
534+
[
535+
[
536+
<<<'EOF'
537+
1
538+
EOF,
539+
]
540+
];
541+
}
542+
543+
public function nestedConstArrayTwo(): array
544+
{
545+
return
546+
[
547+
[
548+
<<<'EOF'
549+
1
550+
EOF,
551+
2,
552+
]
553+
];
554+
}
555+
556+
public function nestedArrayWithExecutableInKey(): array
557+
{
558+
return
559+
[
560+
[
561+
1,
562+
phpversion()
563+
=>
564+
2,
565+
]
566+
];
567+
}
512568
}

tests/tests/Data/RawCodeCoverageDataTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,11 @@ public function testReturnStatementWithConstantExprOnlyReturnTheLineOfLast(): vo
533533
492,
534534
506,
535535
511,
536+
518,
537+
527,
538+
537,
539+
549,
540+
562,
536541
],
537542
array_keys(RawCodeCoverageData::fromUncoveredFile($file, new ParsingFileAnalyser(true, true))->lineCoverage()[$file])
538543
);

0 commit comments

Comments
 (0)