Php-cs-fixer: Return type hint colon spacing

Created on 17 May 2017  Â·  3Comments  Â·  Source: FriendsOfPHP/PHP-CS-Fixer

Hi,

While working on a couple of PRs around brace placement, I noticed that return type hints are not fully styled.

What does this mean you ask?!

Neither

function foo() : bar

nor

function foo(): bar

are preferred when running php-cs-fixer (and I can't find a config option to enable it). Having a mix of these stylings isn't ideal whichever is preferred.

(proposed) PSR12 dictates a rule for this

When you have a return type declaration present there MUST be one space after the colon followed by the type declaration. The colon and declaration MUST be on the same line as the argument list closing parentheses with no spaces between the two characters. The declaration keyword (e.g. string) MUST be lowercase.

So I suppose the default would be the second of the two examples (though I'm a fan of whitespace and I prefer the first personally, so IMHO there should be a config to choose either 😉).

php-cs-fixer could perhaps have a no-change preference by default until PSR 12 is finalised (but having the option to choose would be a plus in the mean time).

kinquestion

Most helpful comment

Ah perfect!

Apologies that one is documented – must have just missed it. My bad!

All 3 comments

What you are looking for already exists: return_type_declaration, with option space_before set to one to match your preferences :)

Ah perfect!

Apologies that one is documented – must have just missed it. My bad!

No worries :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vitek-rostislav picture vitek-rostislav  Â·  3Comments

UksusoFF picture UksusoFF  Â·  3Comments

carusogabriel picture carusogabriel  Â·  3Comments

Bilge picture Bilge  Â·  3Comments

ro0NL picture ro0NL  Â·  3Comments