Skip to content

Commit 2bc4f7c

Browse files
Slamdunksebastianbergmann
authored andcommitted
Fix one-line method for anonymous classes
1 parent 84838ee commit 2bc4f7c

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/StaticAnalysis/ExecutableLinesFindingVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public function enterNode(Node $node): void
175175
);
176176

177177
if ($hasEmptyBody) {
178-
if ($node->getEndLine() === $node->getStartLine()) {
178+
if ($node->getEndLine() === $node->getStartLine() && isset($this->executableLinesGroupedByBranch[$node->getStartLine()])) {
179179
return;
180180
}
181181

tests/_files/source_for_branched_exec_lines.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,18 @@ public function myMethod()
460460
{
461461
return; // +3
462462
}
463-
} // -3
463+
464+
public function m1(): void {} // +1
465+
public function m2(): void {
466+
} // +1
467+
public function m3(): void
468+
{} // +1
469+
} // -6
464470
; // 0
465471
}
466472
public function withComments()
467473
{
468-
$var = 1; // +4
474+
$var = 1; // +7
469475
/** @var int $var */
470476
$var = 2; // +1
471477
// C3
@@ -582,7 +588,7 @@ public function multilineVoid(
582588
trait MyTrait
583589
{
584590
public function myTrait()
585-
{} // +5
591+
{} // +6
586592
}
587593

588594
abstract class MyAbstractClass implements MyInterface
@@ -597,4 +603,4 @@ final class MyFinalClass extends MyAbstractClass
597603
public function myMethod(): void
598604
{
599605
} // +4
600-
}
606+
}

0 commit comments

Comments
 (0)