PHPDoc 和方法匿名函数

PHPDoc and Methods Anonymous functions

我正在尝试解决 PhpStorm 的代码验证中涉及匿名函数的恼人问题。它看不到传递的对象的方法。

下面的代码片段依赖于 Predis 和管道方法。

startCacheClient()

实例化和returns predis 实例。

pipeline()

正常验证,但是

$pipe-set() and $pipe->expire()

验证失败 returns "Method 'Set' Not Found in" 和 "Method 'Expire' Not Found in"

    $this->i = 0;
    $this->startCacheClient()->pipeline(function($pipe) use($values, $jsonEncode, $keepAlive){

        foreach($values as $key => $currentValue){

            if($jsonEncode) {
                $currentValue = gzcompress(json_encode($currentValue), -1);
            }

            $pipe->set($key, $currentValue);
            $pipe->expire($key, $keepAlive);

            $this->i++;
        }
    });

如何通过 PHPDoc 获取 PhpStorm 以了解这些方法实际存在并可用。代码按预期运行,但验证通知很烦人。

如果 $pipe\Predis\Pipeline\Pipeline 的实例,那么您可以在匿名函数声明中键入提示,例如:

$this->startCacheClient()->pipeline(function(\Predis\ClientContextInterface $pipe) use($values, $jsonEncode, $keepAlive){
    /* DO STUFF HERE */
});