Conversation
There was a problem hiding this comment.
Pull request overview
Adds PSR-12 support to the formatter and Sublime Text integration, along with new PSR-12-focused formatting passes and golden tests.
Changes:
- Introduces a
--psr12CLI option and a PSR-12 decorator/profile enabling a set of new PSR-12 passes. - Updates the Sublime plugin/settings/commands to support toggling PSR-12 (mutually exclusive with PSR-2).
- Adds PSR-12 golden tests covering imports/top-of-file layout, control structures, multiline calls/ternaries, traits, anonymous classes, and declare syntax.
Reviewed changes
Copilot reviewed 25 out of 25 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
fmt.stub.php |
Adds PSR-12 profile wiring, CLI flag handling, and implements new PSR-12 formatting passes. |
phpfmt.py |
Adds psr12 setting support and ensures PSR-12/PSR-2 are mutually exclusive in command construction and toggles. |
phpfmt.sublime-settings |
Adds a default psr12 setting flag. |
Default.sublime-commands |
Adds a command palette entry to toggle PSR-12. |
README.md |
Documents PSR-12 support, configuration examples, and lists new passes. |
tests/PSR/057-066-*.in/.out |
Adds PSR-12 regression/golden tests for the new behaviors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| case ST_CURLY_OPEN: | ||
| ++$curlyDepth; | ||
| if ($awaitingClassCurly) { | ||
| $classCurlyDepthStack[] = $curlyDepth; | ||
| $awaitingClassCurly = false; | ||
| } | ||
| $this->appendCode($text); | ||
| break; | ||
| case ST_CURLY_CLOSE: | ||
| if (! empty($classCurlyDepthStack) && end($classCurlyDepthStack) === $curlyDepth) { | ||
| array_pop($classCurlyDepthStack); | ||
| } | ||
| $curlyDepth = max(0, $curlyDepth - 1); | ||
| $this->appendCode($text); |
There was a problem hiding this comment.
In PSR1ClassConstants, $curlyDepth is incremented only for ST_CURLY_OPEN, but decremented for every ST_CURLY_CLOSE. This can desync the depth when a class contains interpolated strings that emit T_CURLY_OPEN/T_DOLLAR_OPEN_CURLY_BRACES (their closing brace is still }), causing the class-scope stack to pop early and class constants to stop being uppercased. Consider incrementing $curlyDepth for T_CURLY_OPEN and T_DOLLAR_OPEN_CURLY_BRACES as well (and only pushing to $classCurlyDepthStack for the actual class-body {).
No description provided.