Format Code
Edit ▸ Format Code (⌥⇧⌘F) formats the current PHP tab in the coding style you choose: PER, PSR-12, or Laravel. It uses the Mago formatter, which is bundled with Runlet, so it works without PHP on your Mac. Formatting never runs your code and never connects to the tab's target.
// Before
$users=User::where('active',true)->get()->map(fn($u)=>[ 'name'=>$u->name,'email'=>$u->email ]);
// After, in the Laravel style
$users = User::where('active', true)->get()->map(fn ($u) => ['name' => $u->name, 'email' => $u->email]);Formatting a Tab
Choose Edit ▸ Format Code, press ⌥⇧⌘F, or run Format Code from the command palette.
- The whole tab. Mago formats whole files, so a selection doesn't limit it.
- One undo step (Undo Format Code). Only the changed part of the text is replaced, so the caret stays on the same code and the scroll position stays.
- Snippets without
<?phpwork, and a last expression without a semicolon keeps it that way. - Magic comments (
//?,/*?*/,/*?->…*/,/*?.*/) stay after the same code. When formatting would change what one of them shows, the code is left as it is, and the tab says which comment and line. - A syntax error leaves the code unchanged and shows the formatter's message above the editor, such as "Expected one of
RightBracket, foundSemicolon". It goes away with your next edit, or Dismiss. - SQL tabs aren't formatted: the command is disabled there, with the reason in the palette and the menu item's tooltip.
- It's an edit, like typing, except that it never starts the sandbox's auto-run.
NOTE
Mago removes parentheses it considers redundant. So $a + ($b /*?*/) would become $a + $b /*?*/ and show $a + $b instead of $b. Runlet leaves such code as it is.
Settings
Choose the style in Settings ▸ Editor ▸ Formatting:
| Setting | Default | What it does |
|---|---|---|
| Style | PER Coding Style | PER Coding Style, PSR-12, or Laravel (Pint), which writes fn ($x), ! $a, and new Foo. |
| Quotes | Single | Plain strings get single or double quotes. Strings that need theirs (escapes, interpolation, or the other quote inside) keep them. |
| Format before run | Off | Run and Profile Run format a PHP tab first, as one undo step, and then run the formatted code. See below. |
Indentation follows Settings ▸ Editor ▸ Indentation (tab width, and spaces or tabs). The PHP version of the tab's target decides where trailing commas may go: in parameter lists only from PHP 8.0. For a target whose version Runlet doesn't know yet, formatting assumes PHP 7.4, whose output works on later versions.
Format before run never applies to Run Selection, the sandbox's auto-runs, SQL tabs, or code you open, import, or restore. If the code can't be formatted, it runs as written, and a syntax error is left for the run to report.
A project's mago.toml, pint.json, or .php-cs-fixer.php isn't used: snippets aren't project files, and running a project's own formatter would need PHP on the target.