Environment
Description
At Infection, we do a lot of nodes replacements during the Mutation Testing process.
For example, we replace public function ... with protected function ... class method visibility modifier.
When mutating the method visibility, the format-preserving printer incorrectly removes the newline between the last attribute and the method declaration.
Expected Behavior
The format-preserving printer should maintain the newline between attributes and the method signature:
#[SomeAttribute1]
#[SomeAttribute2]
public function &foo(int $param, $test = 1): bool
Actual Behavior
The newline is lost, causing the last attribute and method declaration to be on the same line:
#[SomeAttribute1]
#[SomeAttribute2]protected function &foo(int $param, $test = 1): bool
^ missing newline here
Mutation
$stmts[0]->stmts[0]->flags = ($stmts[0]->stmts[0]->flags & ~\PhpParser\Modifiers::PUBLIC) | \PhpParser\Modifiers::PROTECTED;
Related to