Reply to thread

Using asVisitor destroys the return type for phpstorm static analysis, but with phpdoc templates this can be fixed:


[CODE=php]/**

 * Temporarily take an action with the given user considered to be the visitor

 *

 * @template T

 * @param User $user

 * @param callable(): T $action

 * @param bool $withLanguage If true, the action will be taken with the given user's language

 * @return T

 *

 * @throws \Exception

 */

public static function asVisitor(User $user, callable $action, bool $withLanguage = false)

[/CODE]


phpdocs syntax for setting the arguments and return type works with callables and not Closures.


There might be a few other locations which also could do with updating for return type from callables/closures.


Back
Top Bottom