Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correctly indent multiline constants and properties #7875

Conversation

julienfalque
Copy link
Member

Fixes #7866 and #6509.

@coveralls
Copy link

coveralls commented Mar 10, 2024

Coverage Status

coverage: 96.029% (+0.001%) from 96.028%
when pulling 9d1376a on julienfalque:fix-multiline-const-and-properties-indent
into 18d9e42 on PHP-CS-Fixer:master.

Copy link
Member

@Wirone Wirone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some optional cosmetic changes, if you agree with them. Can be also merged as-is, you decide 🙂.

tests/Fixer/Whitespace/StatementIndentationFixerTest.php Outdated Show resolved Hide resolved
tests/Fixer/Whitespace/StatementIndentationFixerTest.php Outdated Show resolved Hide resolved
tests/Fixer/Whitespace/StatementIndentationFixerTest.php Outdated Show resolved Hide resolved
* Returns whether the token at given index is the last token in a property
* declaration before the type or the name of that property.
*/
private function isPropertyStart(Tokens $tokens, int $index): bool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be more helpful as a commonly-accessible helper method. I believe we have similar thing somewhere else already, and it's getting out of hand 😅. But it's good enough, I don't expect you finding better place for it at this point. I just think, in general, we need more reusable code for token traversing, manipulating etc.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree but in this case the method is quite specific: we want the last token before the type or the property name. This is due to how the fixer is currently implemented and it wouldn't be surprising to see that changed in the future, so I'd keep it here for now.

@julienfalque julienfalque force-pushed the fix-multiline-const-and-properties-indent branch from b2ea810 to d340ae5 Compare March 11, 2024 16:49
@julienfalque julienfalque force-pushed the fix-multiline-const-and-properties-indent branch from d340ae5 to 9d1376a Compare March 11, 2024 16:50
@julienfalque julienfalque enabled auto-merge (squash) March 11, 2024 16:57
@julienfalque julienfalque merged commit ac2bbea into PHP-CS-Fixer:master Mar 11, 2024
25 checks passed
@julienfalque julienfalque deleted the fix-multiline-const-and-properties-indent branch March 11, 2024 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

statement_indentation doesn't like multiline const
3 participants