Page MenuHomePhabricator

Don't complain about missing property documentation on typed properties
Closed, ResolvedPublic

Description

In PHP 7.4+, properties can have types specified - if a property has a type and no documentation block, it shouldn't trigger the missing documentation errors.
See similar T258925: Do not warn about missing function doc comment when parameter and return types are fully specified by type hints

This was also discussed on wikitech-l with universal support, see https://lists.wikimedia.org/hyperkitty/list/wikitech-l@lists.wikimedia.org/thread/NWXPNHRNLEVXHSWX33H473OAWQP6CDOA/.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

I agree, and I actually wonder if we should emit a different warning if a property is typed and it has a docblock that merely repeats the type. That is:

/** @var SomeType */ // <- this would be reported
private SomeType $myProp;

/** @var SomeType Some description */ // <- this wouldn't
private SomeType $myProp2;

I actually wonder if we should emit a different warning if a property is typed and it has a docblock that merely repeats the type.

While I very much agree, I think we should do this in two steps:

  1. Remove the warning about "missing documentation" when a property already has a type. Personally I wish we would have done this yesterday. 😋
  2. Create an auto-fix that removes doc blocks that don't contain anything but a redundant type, exactly as shown in your example. My suggestion would be to do this when we switched to PHP 8.0, but not earlier.

Change 865658 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/tools/codesniffer@master] Allow typed properties to omit documentation

https://gerrit.wikimedia.org/r/865658

Change 865682 had a related patch set uploaded (by Lucas Werkmeister (WMDE); author: Lucas Werkmeister (WMDE)):

[mediawiki/tools/codesniffer@master] Allow prose-only documentation for statically typed properties

https://gerrit.wikimedia.org/r/865682

Change 865658 merged by jenkins-bot:

[mediawiki/tools/codesniffer@master] Allow typed properties to omit documentation

https://gerrit.wikimedia.org/r/865658

Change 865682 merged by jenkins-bot:

[mediawiki/tools/codesniffer@master] Allow prose-only documentation for statically typed properties

https://gerrit.wikimedia.org/r/865682

I think we can close this task – the above changes should be included in the next release.