Hi everyone,
I was searching some other similar topic, but I couldn't find anything suitable, especially from recent threads.
When the surveys about PSR-2 begun, I was too young and incompetent to have a chance to take a part of it. Now I am using in my everyday work a whole bunch of tools, with CodeSniffer ahead, which have arisen on PSR-2.
My problem is, that (maybe through pedantic affection or exhausted eyesight) PSR-2 is so unreadable for me in some cases (see below).
I wrote my own patch to CodeSniffer (thanks Greg), which allows using whitespace(s) after opening and before closing parentheses in functions (methods) declarations and calls. Also I would like to allow whitespace(s) with unary operators, especially negation. This makes code much more readable (again - see below).
But now I am forced to use PSR-2, if I want to use my favorite (and honestly only reasonable) tools, like CS, PHP spec, etc.
My question is: why it is forbidden, why cannot be allowed (for one whitespace only at least), and (most bothering) why this very matter of PSR-2 standard did not find himself in the PSR surveys? (If I am wrong, sorry, please correct me, but I could't find it).
So please someone just slant over me, read my concerns and explain the reasons. Honestly, which of those logically-equivalent fragments is most readable? And what is so wrong with whitespace?
VERY BAD EXAMPLE, BUT CORRECT FOR PSR-2:
if (!$this->getSomething($that)->putSomewhere($arrPlaces[$this->getOrigin(Foo::TYPE_PHP)->getSymbol()])->isSuitable()) {
throw new RuntimeException(sprintf('%s[%d]: %s(): not fit', __FILE__, __LINE__, __METHOD__));
}
MUCH MODE READABLE, UNFORTUNATELY INCORRECT FOR PSR-2:
if ( ! $this->getSomething( $that )->putSomewhere( $arrPlaces[$this->getOrigin( Foo::TYPE_PHP )->getSymbol()] )->isSuitable() ) {
throw new RuntimeException( sprintf( '%s[%d]: %s(): not fit', __FILE__, __LINE__, __METHOD__ ) );
}
Even if I rewrote this, still PSR-2 is not as readable as could be (and what happened if I must use editor without code highlight?):
$strSymbol = $this->getOrigin(Foo::TYPE_PHP)->getSymbol();
$objNewPlace = $arrPlaces[$strSymbol];
$objSomething = $this->getSomething($that);
$objSomething->putSomewhere($objNewPlace);
if (!$objSomething->isSuitable()) {
$strMsg = sprintf('%s[%d]: %s(): not fit', __FILE__, __LINE__, __METHOD__);
throw new RuntimeException($strMsg);
}But, hey, just few whitespace characters make a work:
$strSymbol = $this->getOrigin( Foo::TYPE_PHP )->getSymbol();
$objNewPlace = $arrPlaces[$strSymbol];
$objSomething = $this->getSomething( $that );
$objSomething->putSomewhere( $objNewPlace );
if ( ! $objSomething->isSuitable() ) {
$strMsg = sprintf( '%s[%d]: %s(): not fit', __FILE__, __LINE__, __METHOD__ );
throw new RuntimeException( $strMsg );
}