Victor
Victor

Reputation: 14632

Allow lack of space after function parenthesis if there is a return type hint in PHP (CodeSniffer)

I am using the MediaWiki coding standard for php_codesniffer. Thing is, that is created for PHP version <7.0.0. Let's take the following not-formatted code snippet:

function test(){}

The sniffer will report an error, that is needs space between ) and { (the rule is Generic.Functions.OpeningFunctionBraceKernighanRitchie.SpaceAfterBracket) Now that's ok, it is normal (for me at least) to write

function test() {}

But when it comes to PHP 7 and the function has a return type hint, I want it formatted like this

function test(): string {}

So no space between ) and :, but spaces between string and other tokens there. What is the rule I have to write to achieve this?

Upvotes: 2

Views: 621

Answers (1)

Tomas Votruba
Tomas Votruba

Reputation: 24298

There is already sniff for that in Slevomat/CodingStandard: https://github.com/slevomat/coding-standard/blob/master/README.md#slevomatcodingstandardtypehintstypehintdeclaration-

It is high quality package I use for over a year. They also have a branch for 3.0 ready. Also check also sniffs, they're awesome and helps with refactoring to PHP 7.0 and 7.1.

Upvotes: 1

Related Questions