Intelephense 来自抱怨具体接口实现上未定义的方法

问题描述 投票:0回答:1

在我的 Symfony 7.0.3 项目中,我有一个自定义 OAuth2 身份验证器,它通过

League\Oauth2
使用
knpuniversity/oauth-client-bundle

在我的社交验证器课程中,我打电话给

$oauthUser = $client->fetchUserFromToken($accessToken)
。该方法的返回类型是
ResourceOwnerInterface
,它由
GoogleUser
实现 - 返回对象的类。

我现在遇到的烦恼是,当我写

$oauthUser->getEmail()
时,intelephense 抱怨
getEmail
是一个未定义的方法。当然,事实并非如此,代码运行得很好。

我可以在代码或编辑器配置(我使用的是 Visual Studio Code)中做些什么来防止出现那些红色波浪线吗?

我在调用

$this->getUser()
的控制器中遇到了同样的问题,我通过使用具体返回类型重载
getUser()
解决了这个问题。但我不确定这里是否可以重载。

谢谢。

php symfony visual-studio-code intelephense
1个回答
0
投票

如果你非常确定你的代码是好的,你可以忽略这样的验证。

/**
* @disregard P1009 Undefined type
*/
$oauthUser->getEmail()

Intelliphense 不会再抱怨了

© www.soinside.com 2019 - 2024. All rights reserved.