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).
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 :)
Most helpful comment
Ah perfect!
Apologies that one is documented – must have just missed it. My bad!