I just re-applied change
https://gerrit.wikimedia.org/r/c/mediawiki/core/+/1163470, which
allows documenting the type of the value contained inside a Status or
StatusValue object when it is returned from a function or accepted as
a parameter.

This allows IDEs like PhpStorm to provide better autocompletion, and
allows Phan to better analyze the code using the value. For example:

    /** @return StatusValue<Foo> */
    function doStuff(): StatusValue { ... }
    doStuff()->getValue()->bar();

Phan will now validate that the class 'Foo' has a method called 'bar',
and PhpStorm will autocomplete its methods after `...->getValue()->`.

This is achieved using '@template' annotations to document Status and
StatusValue as generic classes. This is supported by most PHP static
analyzers these days, but fairly new in MediaWiki core. You can find
an introduction to this concept here:
https://stitcher.io/blog/generics-in-php-1

It is still okay to use the Status or StatusValue classes without
specifying the type of their value, although if you subclass one of
them, you'll need to add some annotations for Phan to accept them.
We've made the necessary updates to all extensions with known
problems, but if you encounter any more issues, please ask here or on
task https://phabricator.wikimedia.org/T397781.

Thanks to Daimona, Umherirrender and Lucas Werkmeister for their help
with the changes to MediaWiki and extensions.

Thanks also to Phan maintainers, including once again Daimona and
Rasmus Lerdorf, who reviewed many of my patches for Phan, improving
its generic support to the point that this change became possible.

-- 
Bartosz Dziewoński
_______________________________________________
Wikitech-l mailing list -- wikitech-l@lists.wikimedia.org
To unsubscribe send an email to wikitech-l-le...@lists.wikimedia.org
https://lists.wikimedia.org/postorius/lists/wikitech-l.lists.wikimedia.org/

Reply via email to