Questions about enforcing new CS in PHP_CS
| From: | Greg Sherwood | Date: | Mon, 24 Nov 2008 02:46:40 +0000 |
| Subject: | Questions about enforcing new CS in PHP_CS | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-51125@lists.php.net to get a copy of this message | ||
I sent this email to the PEAR group as well, but I'm not sure if it actually went through. My apologies if it did and I'm just sending this again, but it's worth mass-discussion anyway.
------------------
I'm writing sniffs for PHP_CodeSniffer to enforce the new standards listed here: http://pear.php.net/pepr/pepr-proposal-show.php?id=538
I have some preliminary questions I hope you can help with.
Thanks
Greg
** Split function definitions onto several lines **
When your function declaration just sits over 80 chars, you get something that looks like this (from a PHPCS file):
public static function getInstalledStandards($includeGeneric=false,
$standardsDir=''
) {
$installedStandards = array();
if ($standardsDir === '') {
$standardsDir = dirname(__FILE__).'/CodeSniffer/Standards';} ... That's not the easiest code to read. In fact, it was easier just having those two params on one line, even if it went slightly over 80 chars. A couple of other options are also valid under the new standard: public static function getInstalledStandards( $includeGeneric=false, $standardsDir='' ) { and public static function getInstalledStandards( $includeGeneric=false, $standardsDir='' ) { Do you have anything against developers using those methods? Also just a note that there are 3 different ways developers can write their code, all with varying degrees of readability. Do you want strict enforcement to one of these methods or should each developer choose their own? ** Split function call on several lines ** Easy question; is this valid or is only one object operator allowed per line if you are using multiple lines: $someObject->someFunction("some", "parameter")->someOtherFunc(23, 42) ->andAThirdFunction(); And what happens in the unlikely scenario where you are multi-line function calls mixed in; you get this (valid by the standard): $someObject->someFunction( "some", "parameter", "and", "another long parameter", array(true) ) ->someOtherFunc(
23, 42) ->andAThirdFunction(); Two problems with the above; multi-line function calls inside concatenated function calls look wrong and using multiline function calls when you don't need to looks wrong. Do you want any additional checks for this sort of code? ** Alignment of function parameters ** Do you want any checking for this standard? I assume it is not a requirement that you indent in this way (MAY be aligned, not MUST be aligned). ** Alignment of assignments ** PHPCS currently throws warnings when you don't align. Considering the standard has changed to "the equal signs MAY be aligned", do you want any enforcement, or was the intention just to stop warnings when it requires excessive indentation? ** Array formatting ** Are any of these standards to be enforced? The language of the standard suggests these array formatting standards are optional.