In PHPStorm, prompt: Return value is expected to bearray,boolReturned less… (Ctrl+F1)
1. In phpstorm, the prompt: return value is expected to bearray,boolReturned less… (Ctrl+F1), as shown in Figure 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 bearray,boolReturned Less… (Ctrl+F1) Inspection Info: Return Value Type is not compared with declared. The return value is expected to bearray,boolFewer returned…(Ctrl+F1) Verification information: The return value type is not compatible with the declaration.
3. In the case of adding or returning a boolean value at the return value type declaration, the prompt information has been canceled, as shown in Figure 2
* @return array|bool
4. Recommended solutions for the best solution to such problems, in the method, only a certain data type is returned, not a variety of relationships.

