Skip to content

Opening brace on new line after return type when argument list is split across multiple lines #94

Closed
@rhertogh

Description

@rhertogh

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';
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions