Page MenuHomePhabricator

Add sniff for checking that "else" is on same line as previous closing brace
Closed, ResolvedPublic


As per Manual:CC/PHP, an elseif or else should be on the same line as the previous closing brace. We should have a sniff that checks this.

Event Timeline

polybuildr raised the priority of this task from to Needs Triage.
polybuildr updated the task description. (Show Details)
polybuildr added a subscriber: polybuildr.

Also, Manual:CC/PHP doesn't seem to explicitly say this right now. However, a quick grep in mw-core/includes shows:

$ grep "} else" -R | wc -l
$ grep -E "^\s*else" -R | wc -l

so the page should probably say this explicitly. Editing page.

This seems to already be there in phpcs

I get
Expected "} else {\n"; found "}\nelse {\n"
Expected "} elseif (...) {\n"; found "}\nelseif (...) {\n"

It is there in PEAR.Sniffs.ControlStructures.ControlSignatureSniff

Sorry, this wasnt being run with the MW ruleset.

Change 237733 had a related patch set uploaded (by TasneemLo):
Add ControlSignatureSniff to handle else & elseif

Could you assign this to me please ?

Change 237733 merged by jenkins-bot:
Add IfElseStructureSniff to handle else structures

Legoktm added a subscriber: Legoktm.