per-coding-style
per-coding-style copied to clipboard
Opening brace on new line after return type when argument list is split across multiple lines
I'm not sure if this already has been discussed, if so, please let me know.
Currently the Method and Function Parameters section defines a function argument list split across multiple lines in combination with a return type as such:
class ReturnTypeVariations
{
public function anotherFunction(
string $foo,
string $bar,
int $baz,
): string {
return 'foo';
}
}
However, when the definition get bigger with for example default values and interfaces as return types, it becomes (IMO) less readable:
class ReturnTypeVariations
{
public function anotherFunction(
string $foo,
string $bar,
int $baz='default value',
): MyVeryLongCustomInterace {
$myVar = 'inititial value';
}
}
My proposal would be to place the opening brace on a new line when a function's argument list is split across multiple lines and a return type is specified:
class ReturnTypeVariations
{
public function anotherFunction(
string $foo,
string $bar,
int $baz='default value',
): MyVeryLongCustomInterace
{
$myVar = 'inititial value';
}
}
Note that if no return type is specified, the opening brace must still be on the same line:
class ReturnTypeVariations
{
public function anotherFunction(
string $foo,
string $bar,
int $baz='default value',
) {
$myVar = 'inititial value';
}
}