1、在 PhpStorm 中,提示:Return value is expected to be ‘array’, ‘bool’ returned less… (Ctrl+F1),如图1
/** * 返回用户详情 * * @param string $loginId 用户标识 * @param string $loginTid 登录标识 * * @return array * * 格式如下: * * 框架服务控制台的用户详情 * [ * 'message' => '', //说明 * 'data' => [], //数据 * ] * * 失败(将错误保存在 [[yii/base/Model::errors]] 属性中) * false * * @throws ServerErrorHttpException 如果响应状态码不等于20x * @throws HttpException 如果登录超时 */ public function getUser($loginId, $loginTid) { $requestParams = [ 'login_id' => $loginId, 'login_tid' => $loginTid, 'url' => 'interface/get-user-info', ]; $apiRequestParams = self::getApiRequestParams($requestParams); $response = Yii::$app->cmcConsoleHttp->createRequest() ->setMethod('get') ->setUrl($requestParams['url']) ->setData($apiRequestParams) ->send(); // 检查响应状态码是否等于20x if ($response->isOk) { // 检查业务逻辑是否成功 if ($response->data['code'] === 10000) { $cmcConsoleData = ['message' => $response->data['message'], 'data' => $response->data['data']]; return $cmcConsoleData; } elseif ($response->data['code'] === 99998) { // 登录超时 throw new HttpException(302, Yii::t('error', Yii::t('error', Yii::t('error', '201003'), ['message' => $response->data['message']])), 201003); } else { $this->addError('login_id', $response->data['message']); return false; } } else { throw new ServerErrorHttpException(Yii::t('error', Yii::t('error', Yii::t('error', '201001'), ['status_code' => $response->statusCode])), 201001); } }
2、Return value is expected to be ‘array’, ‘bool’ returned less… (Ctrl+F1) Inspection info: Return value type is not compatible with declared. 返回值预计为 ‘array’,’bool’ 返回的较少…(Ctrl + F1)检验信息:返回值类型与声明不兼容。
3、在返回值类型声明处,加上或者返回布尔值的情况,提示信息已取消,如图2
* @return array|bool
4、此类问题的最佳解决方案的建议,在方法中,仅返回某一种数据类型,而不是以或者的关系返回多种
原创文章,作者:kepupublish,如若转载,请注明出处:https://blog.ytso.com/181325.html