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.
Description
Description
Details
Details
Subject | Repo | Branch | Lines +/- | |
---|---|---|---|---|
Add IfElseStructureSniff to handle else structures | mediawiki/tools/codesniffer | master | +69 -0 |
Related Objects
Related Objects
Event Timeline
Comment Actions
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 5186 $ grep -E "^\s*else" -R | wc -l 60
so the page should probably say this explicitly. Editing page.
Comment Actions
This seems to already be there in phpcs
I get
Expected "} else {\n"; found "}\nelse {\n"
and
Expected "} elseif (...) {\n"; found "}\nelseif (...) {\n"
It is there in PEAR.Sniffs.ControlStructures.ControlSignatureSniff
EDIT :
Sorry, this wasnt being run with the MW ruleset.
Comment Actions
Change 237733 had a related patch set uploaded (by TasneemLo):
Add ControlSignatureSniff to handle else & elseif
Comment Actions
Change 237733 merged by jenkins-bot:
Add IfElseStructureSniff to handle else structures