@@ -11317,15 +11317,49 @@ public function format($source) {
1131711317 $ this ->appendCode ($ text );
1131811318 $ this ->printUntil (ST_PARENTHESES_OPEN );
1131911319 $ this ->printBlock (ST_PARENTHESES_OPEN , ST_PARENTHESES_CLOSE );
11320- $ this ->printAndStopAt (ST_CURLY_OPEN );
11321- if ($ this ->rightTokenIs (ST_CURLY_CLOSE )) {
11320+
11321+ // Look ahead to check if function is empty before deciding how to format
11322+ $ lookAheadPtr = $ this ->ptr ;
11323+ $ isEmptyFunction = false ;
11324+
11325+ // Walk forward to find ST_CURLY_OPEN
11326+ while ($ lookAheadPtr < count ($ this ->tkns )) {
11327+ $ lookAheadPtr ++;
11328+ if (!isset ($ this ->tkns [$ lookAheadPtr ])) break ;
11329+
11330+ list ($ lookId , $ lookText ) = $ this ->getToken ($ this ->tkns [$ lookAheadPtr ]);
11331+ if ($ lookId == ST_CURLY_OPEN ) {
11332+ // Found opening brace, now check if next non-whitespace token is closing brace
11333+ $ nextPtr = $ lookAheadPtr ;
11334+ while ($ nextPtr < count ($ this ->tkns )) {
11335+ $ nextPtr ++;
11336+ if (!isset ($ this ->tkns [$ nextPtr ])) break ;
11337+
11338+ list ($ nextId , $ nextText ) = $ this ->getToken ($ this ->tkns [$ nextPtr ]);
11339+ if ($ nextId == T_WHITESPACE ) continue ; // Skip whitespace
11340+
11341+ if ($ nextId == ST_CURLY_CLOSE ) {
11342+ $ isEmptyFunction = true ;
11343+ }
11344+ break ;
11345+ }
11346+ break ;
11347+ }
11348+ }
11349+
11350+ if ($ isEmptyFunction ) {
11351+ // Format as single line for empty functions
11352+ $ this ->printAndStopAt (ST_CURLY_OPEN );
1132211353 $ this ->rtrimAndAppendCode ($ this ->getSpace () . ST_CURLY_OPEN );
11323- $ this ->printAndStopAt (ST_CURLY_CLOSE );
11354+ $ this ->walkUntil (ST_CURLY_CLOSE );
1132411355 $ this ->rtrimAndAppendCode (ST_CURLY_CLOSE );
1132511356 break ;
11357+ } else {
11358+ // For non-empty functions, preserve original formatting
11359+ $ this ->printAndStopAt (ST_CURLY_OPEN );
11360+ prev ($ this ->tkns );
11361+ break ;
1132611362 }
11327- prev ($ this ->tkns );
11328- break ;
1132911363 default :
1133011364 $ this ->appendCode ($ text );
1133111365 }
0 commit comments