Reputation: 645
To align or not to align...
Pros and cons of the following approaches.
I like to use first case. Because I think it's optimal, but someone else thinks otherwise.
What do you think? May be there is PSR about it?
Case style 1
class A {
const AB = 1;
const PAGE = 2;
const PP_SOMETHING_VERY_LONG = 3;
public function testLoooooooooong()
{
$a = 1;
$somethingWeryLong = 2;
$c = 3;
$res = $a + $c;
$b = 1;
$n = 100;
return 0;
}
public function test2($objectttttttttttttttLooooooong)
{
$objectttttttttttttttLooooooong->callSooooooooomethingLooooooong()
->call(
$this->testLoooooooooong(),
$this->testLoooooooooong2(),
$this->testLoooooooooong3()
)
->call(
$this->testLoooooooooong(),
$this->testLoooooooooong2(),
$this->testLoooooooooong3()
);
}
}
Case style 2
class A {
const AB = 1;
const PAGE = 2;
const PP_SOMETHING_VERY_LONG = 3;
public function testLoooooooooong() {
$a = 1;
$somethingWeryLong = 2;
$c = 3;
$res = $a + $c;
$b = 1;
$n = 100;
return 0;
}
public function test2($objectttttttttttttttLooooooong) {
$objectttttttttttttttLooooooong->callSooooooooomethingLooooooong()
->call(
$this->testLoooooooooong(),
$this->testLoooooooooong2(),
$this->testLoooooooooong3()
)
->call(
$this->testLoooooooooong(),
$this->testLoooooooooong2(),
$this->testLoooooooooong3()
);
}
}
Upvotes: 1
Views: 1075
Reputation: 19406
Official answer: There is PSR-2 about styling PHP code, you can find it here: http://www.php-fig.org/psr/psr-2/
Beside of those recommendations, it is totally up to the coder how you like to style your code. This is only about conventions.
Within modern IDEs (IntelliJ, Netbeans, Eclipse, PHPStorm etc.) you can reformat code your code automatically to the way you prefer (e.g. with a shortcut like ALT+L).
The opinionated part of the answer: I would prefer the = style as well as the -> style of Case 1, because it is annoying to handle all those spaces and tabs from Case 2.
However I prefer
public function testLoooooooooong() {
}
from case 2 over
public function testLoooooooooong()
{
}
from case 1 for the same reason. I do not want to write extra tabs and I do not think that it makes the code more readable. Anyhow this is all a matter of taste and many would also prefer case 1 here.
Upvotes: 1