Page MenuHomePhabricator

Psalm/PHPStan array shapes triggers MediaWiki.Commenting.PropertyDocumentation.NotPunctuationVarType
Open, Needs TriagePublic

Description

PHP does not have a tuple type, but you can emulate it for static analysis and IDE support with an array type annotation (array shapes) that lists the fixed number of elements and type of each element:

class Foo {
  /**
    * A tuple with exactly 2 typed elements
    * @var arrray{string, int}
    */
   private array $bar;
}

The above code triggers MediaWiki.Commenting.PropertyDocumentation.NotPunctuationVarType

Maybe the code inside that rule (and similar rules for @param and @return definitions) could be extended to allow commas inside angled and curly brackets

Event Timeline

The problem is not the curly brackets, the problem is the space inside the brackets.

Works without space:

class Foo {
  /**
    * A tuple with exactly 2 typed elements
    * @var array{string,int}
    */
   private array $bar;
}

Not sure if the space should be supported

We had a very similar problem a while ago with the syntax array<int, string>:

Personally I think we should support the curly bracket syntax discussed here as well. I mean, why not?

As the rest of the coding style encourages spaces in many places, it would be consistent to allow them in docblock type annotations and help with the readability.