diff --git a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php index 4ce6e4366..50a9ae1cb 100644 --- a/src/StaticAnalysis/ExecutableLinesFindingVisitor.php +++ b/src/StaticAnalysis/ExecutableLinesFindingVisitor.php @@ -128,6 +128,15 @@ public function enterNode(Node $node): void $node instanceof Node\Stmt\ClassMethod || $node instanceof Node\Expr\Closure || $node instanceof Node\Stmt\Trait_) { + if ($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassMethod) { + foreach ($node->getParams() as $param) { + foreach (range($param->getStartLine(), $param->getEndLine()) as $line) { + $this->unsets[$line] = true; + } + } + unset($this->unsets[$node->getEndLine()]); + } + $isConcreteClassLike = $node instanceof Node\Stmt\Enum_ || $node instanceof Node\Stmt\Class_ || $node instanceof Node\Stmt\Trait_; if (null !== $node->stmts) { diff --git a/tests/_files/source_for_branched_exec_lines_php81.php b/tests/_files/source_for_branched_exec_lines_php81.php index d372f5a19..97f446751 100644 --- a/tests/_files/source_for_branched_exec_lines_php81.php +++ b/tests/_files/source_for_branched_exec_lines_php81.php @@ -32,3 +32,54 @@ interface MyIntersection public function check(MyIntOne&MyIntTwo $intersection); public function neverReturn(): never; } + +// New in initializers +class NewInInit_NoInit +{ + public function __construct(private DateTimeInterface $dateTime) { + } // +1 + public function noinit(DateTimeInterface $dateTime) { + } // +1 +} +class NewInInit_OneLineNewLine +{ + public function __construct(private DateTimeInterface $dateTime = new DateTime()) { + } // +1 + public function onelinenewline(DateTimeInterface $dateTime = new DateTime()) { + } // +2 +} +class NewInInit_OneLineSameLine +{ + public function __construct(private DateTimeInterface $dateTime = new DateTime()) {} // +2 + public function onelinesameline(DateTimeInterface $dateTime = new DateTime()) {} // +1 +} +class NewInInit_MultiLine +{ + public function __construct( + private + DateTimeInterface + $dateTime + = + new + DateTime() + , + private + bool + $var + = + true + ) + { + } // +1 + public function multiline( + DateTimeInterface $dateTime = new DateTime() + ) { + } // +2 +} +function newInInit_OneLineNewLine(DateTimeInterface $dateTime = new DateTime()) { +} // +2 +function newInInit_OneLineSameLine(DateTimeInterface $dateTime = new DateTime()) {} // +2 +function newInInit_multiline( + DateTimeInterface $dateTime = new DateTime() +) { +} // +1 diff --git a/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php b/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php index 041a1fe99..95491fe92 100644 --- a/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php +++ b/tests/tests/StaticAnalysis/ExecutableLinesFindingVisitorTest.php @@ -28,13 +28,13 @@ public function testExecutableLinesAreGroupedByBranch(): void $this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines.php'); } - #[RequiresPhp('8.1.*')] + #[RequiresPhp('>=8.1')] public function testExecutableLinesAreGroupedByBranchPhp81(): void { $this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines_php81.php'); } - #[RequiresPhp('8.2.*')] + #[RequiresPhp('>=8.2')] public function testExecutableLinesAreGroupedByBranchPhp82(): void { $this->doTestSelfDescribingAsset(TEST_FILES_PATH . 'source_for_branched_exec_lines_php82.php');