@@ -166,8 +166,9 @@ abstract class PrettyPrinterAbstract implements PrettyPrinter {
166166 * @var array<string, array{int|string|null, string, string}>
167167 */
168168 protected array $ emptyListInsertionMap ;
169- /** @var array<string, array{string, int}> Map from "{$class}->{$subNode}" to [$printFn, $token]
170- * where $printFn is the function to print the modifiers and $token is the token before which
169+ /** @var array<string, array{string, int, int}>
170+ * Map from "{$class}->{$subNode}" to [$printFn, $skipToken, $findToken] where $printFn is the function to
171+ * print the modifiers, $skipToken is the token to skip at the start and $findToken is the token before which
171172 * the modifiers should be reprinted. */
172173 protected array $ modifierChangeMap ;
173174
@@ -677,8 +678,8 @@ protected function p(
677678 return $ this ->pFallback ($ fallbackNode , $ precedence , $ lhsPrecedence );
678679 }
679680
680- [$ printFn , $ findToken ] = $ this ->modifierChangeMap [$ key ];
681- $ skipWSPos = $ this ->origTokens ->skipRightWhitespace ($ pos );
681+ [$ printFn , $ skipToken , $ findToken ] = $ this ->modifierChangeMap [$ key ];
682+ $ skipWSPos = $ this ->origTokens ->skipRight ($ pos, $ skipToken );
682683 $ result .= $ this ->origTokens ->getTokenCode ($ pos , $ skipWSPos , $ indentAdjustment );
683684 $ result .= $ this ->$ printFn ($ subNode );
684685 $ pos = $ this ->origTokens ->findRight ($ skipWSPos , $ findToken );
@@ -1678,15 +1679,15 @@ protected function initializeModifierChangeMap(): void {
16781679 }
16791680
16801681 $ this ->modifierChangeMap = [
1681- Stmt \ClassConst::class . '->flags ' => ['pModifiers ' , \T_CONST ],
1682- Stmt \ClassMethod::class . '->flags ' => ['pModifiers ' , \T_FUNCTION ],
1683- Stmt \Class_::class . '->flags ' => ['pModifiers ' , \T_CLASS ],
1684- Stmt \Property::class . '->flags ' => ['pModifiers ' , \T_VARIABLE ],
1685- PrintableNewAnonClassNode::class . '->flags ' => ['pModifiers ' , \T_CLASS ],
1686- Param::class . '->flags ' => ['pModifiers ' , \T_VARIABLE ],
1687- PropertyHook::class . '->flags ' => ['pModifiers ' , \T_STRING ],
1688- Expr \Closure::class . '->static ' => ['pStatic ' , \T_FUNCTION ],
1689- Expr \ArrowFunction::class . '->static ' => ['pStatic ' , \T_FN ],
1682+ Stmt \ClassConst::class . '->flags ' => ['pModifiers ' , \T_WHITESPACE , \ T_CONST ],
1683+ Stmt \ClassMethod::class . '->flags ' => ['pModifiers ' , \T_WHITESPACE , \ T_FUNCTION ],
1684+ Stmt \Class_::class . '->flags ' => ['pModifiers ' , \T_WHITESPACE , \ T_CLASS ],
1685+ Stmt \Property::class . '->flags ' => ['pModifiers ' , \T_WHITESPACE , \ T_VARIABLE ],
1686+ PrintableNewAnonClassNode::class . '->flags ' => ['pModifiers ' , \T_NEW , \ T_CLASS ],
1687+ Param::class . '->flags ' => ['pModifiers ' , \T_WHITESPACE , \ T_VARIABLE ],
1688+ PropertyHook::class . '->flags ' => ['pModifiers ' , \T_WHITESPACE , \ T_STRING ],
1689+ Expr \Closure::class . '->static ' => ['pStatic ' , \T_WHITESPACE , \ T_FUNCTION ],
1690+ Expr \ArrowFunction::class . '->static ' => ['pStatic ' , \T_WHITESPACE , \ T_FN ],
16901691 //Stmt\TraitUseAdaptation\Alias::class . '->newModifier' => 0, // TODO
16911692 ];
16921693
0 commit comments