Generic/LowerCaseKeyword: remove unnecessary use of prepareForOutput()#1379
Merged
jrfnl merged 1 commit intoPHPCSStandards:4.xfrom Mar 5, 2026
Conversation
Common::prepareForOutput() replaces spaces with a middle dot character to make whitespace visible in error messages. It was added to this sniff in commit 6ef2856 ("Better support for showing spaces and newlines"), probably as a follow-up to the multi-line `yield from` support added in squizlabs/PHP_CodeSniffer 1337 (commits ce60083 and d1a9163) as all three commits are by the same author on the same day. For most PHP keywords prepareForOutput() has no effect since they don't contain whitespace. The one exception is `yield from` (T_YIELD_FROM), which, in some cases, is tokenized as a single token containing a space. In that case, prepareForOutput() would display `yield·from`, but I would argue that showing the keyword as-is is preferable even in this case. This changes the error output for `yield from` from: ``` expected "yield·from" but found "Yield·From" ``` To: ``` expected "yield from" but found "Yield From" ``` Suggested in: squizlabs/PHP_CodeSniffer 2652
jrfnl
approved these changes
Mar 5, 2026
Member
jrfnl
left a comment
There was a problem hiding this comment.
but I would argue that showing the keyword as-is is preferable even in this case.
Agreed. Thanks for making this change. LGTM!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
As suggested in squizlabs/PHP_CodeSniffer#2652 (comment), this PR removes an unnecessary use of
Common::prepareForOutput()in theGeneric.PHP.LowerCaseKeywordsniff.Common::prepareForOutput()replaces spaces with a middle dot character to make whitespace visible in error messages. It was added to this sniff in commit 6ef2856 ("Better support for showing spaces and newlines"), probably as a follow-up to the multi-lineyield fromsupport added in squizlabs/PHP_CodeSniffer#1337 (commits ce60083 and d1a9163) as all three commits are by the same author on the same day.For most PHP keywords,
Common::prepareForOutput()has no effect since they don't contain whitespace. The one exception isyield from(T_YIELD_FROM), which, in some cases, is tokenized as a single token containing a space. In that case,Common::prepareForOutput()would displayyield·from, but I would argue that showing the keyword as-is is preferable even in this case.This changes the error output for
Yield Fromfrom:To:
Suggested changelog entry
Changed:
Generic.PHP.LowerCaseKeywordno longer embeds UTF-8 middle dot characters in error messages for theyield fromkeyword.Related issues/external references
Related squizlabs/PHP_CodeSniffer#2652 (comment)
Types of changes
PR checklist