PHP-FIG accepted PSR-1 and PSR-2 in August, and the useful thing about them is not that any particular choice is correct. Several are plainly arbitrary. It is that the choice has been made by somebody else, in public, so brace placement stops being a matter of taste that surfaces in every review and becomes a property of the file that a tool can check.
<?php
namespace AppCatalogue;
use AppSupportMoney;
class ProductPricer implements Pricer
{
const VAT_RATE = 18;
protected $rates;
public function priceFor(Product $product, $quantity = 1)
{
// class and method braces on their own line;
// control structure braces on the same line
if ($quantity > 1) {
return $this->bulk($product, $quantity);
} elseif ($product->isClearance()) {
return $product->clearancePrice();
}
return $product->price();
}
}
The whole standard is about that much: four spaces and never tabs, one class per file, namespace and use followed by a blank line, visibility declared on every property and method, elseif rather than else if, and a soft line limit of 120 with 80 as the target. It deliberately says nothing about naming, structure or design, which are the things review time is actually worth spending on. Two costs are real and neither is a reason not to do it. Reformatting an existing tree rewrites every line, so git blame on those files stops being useful — which argues for converting a file when you are already changing it rather than in one sweep. And elseif versus else if is the rule that gets quietly ignored by everyone who has been writing PHP since 5.0, so it needs a tool rather than good intentions.