Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.1

Request #18086 False positive. In ZEND standard, opening brace is not always on a new line
Submitted: 2010-11-29 14:02 UTC
From: sandermarechal Assigned: squiz
Status: Wont fix Package: PHP_CodeSniffer (version 1.2.2)
PHP Version: 5.3.3 OS: Windows Server 2003
Roadmaps: (Not assigned)    

 [2010-11-29 14:02 UTC] sandermarechal (Sander Marechal)
Description: ------------ According to the ZEND Coding Style, if a function has a long declaration, it can be broken over several lines. In that case, the closing parenthesis goes on a newline, followed by a space, followed by the opening bracket. See section "Function and Method Declaration", second example. PHP_CodeSniffer uses Generic_Sniffs_Functions_OpeningFunctionBraceBsdAllmanSniff for the ZEND standard. This incorrectly triggers an error on such long declarations: "Opening brace should be on a new line". This is incorrect. It should not generate an error. Test script: --------------- Example from the Zend Framework Coding Style linked above: /** * Documentation Block Here */ class Foo { /** * Documentation Block Here */ public function bar($arg1, $arg2, $arg3, $arg4, $arg5, $arg6 ) { // all contents of function // must be indented four spaces } }


 [2010-11-29 14:59 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Bogus -Assigned To: +Assigned To: squiz
The Zend standard is NOT the Zend Framework coding standard. It is simply a collection of sniffs contributed by people working at/with Zend over the last few years. I've been asking if someone wants to create a ZF standard for quite a while, but nobody has contributed anything. Please do not use PHP_CodeSniffer to check ZF code unless you've managed to get a ZF standard from someone.
 [2010-11-30 13:32 UTC] sandermarechal (Sander Marechal)
Perhaps the standard should be renamed in PHP_CodeSniffer then?
 [2010-11-30 15:50 UTC] squiz (Greg Sherwood)
I actually want to merge the standard into the Generic standard, but it's a big BC break and needs to be handled carefully with other merges. So I'm not planning a name change, although the standard has a ruleset.xml file in SVN already that says that it is out of date, so it is at least documented in 1.3.0.
 [2010-12-01 00:55 UTC] sandermarechal (Sander Marechal)
Okay, thanks. In the mean time I have scratched my own itch and wrote a sniff that correctly handles the test script I posted above. Perhaps this is something you'd want to have too? If so, where shall I post it? Here or in a new bug?
 [2010-12-06 03:56 UTC] squiz (Greg Sherwood)
Sorry it took me so long to reply. I got side-tracked with other work. If you'd like to contribute a sniff, please attach it to this report and I'll test and commit it as soon as possible.
 [2010-12-06 19:48 UTC] sandermarechal (Sander Marechal)
 [2010-12-06 19:49 UTC] sandermarechal (Sander Marechal)
Patch added. I hope it's okay like this. I've never made a PEAR patch before.
 [2010-12-15 09:19 UTC] squiz (Greg Sherwood)
-Status: Bogus +Status: Feedback -Type: Bug +Type: Feature/Change Request
Is this actually the same standard as PEAR? if so, you can just include the PEAR/Functions/FunctionDeclarationSniff into a ZF standard instead of writing new code. Coincidently, found out about this last night: Maybe worth talking to this developer and helping out. He is using the PEAR standard for most sniffs.
 [2010-12-16 04:16 UTC] sandermarechal (Sander Marechal)
You're right. It's the same as PEAR. Perhaps the ZEND standard should use the PEAR function declaration sniff then instead of the Generic BsdAllman sniff? And thanks for the github link. That's going to be very useful!
 [2011-01-14 08:53 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: Wont fix