From c262be38b75b06be49e47d241ad69c0dd8008adf Mon Sep 17 00:00:00 2001 From: justmd5 Date: Mon, 14 Mar 2022 10:26:37 +0800 Subject: [PATCH] optimize params and return type --- src/Core/API.php | 20 ++++++++++---------- src/Core/Signature.php | 4 ++-- src/Core/Traits/ArgumentProcessingTrait.php | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Core/API.php b/src/Core/API.php index ebe5e23..b8366fd 100644 --- a/src/Core/API.php +++ b/src/Core/API.php @@ -28,10 +28,10 @@ class API extends AbstractAPI * API constructor. * * @param Foundation $app - * @param string $classify - * @param array $filter + * @param string $classify + * @param array $filter */ - public function __construct(Foundation $app, $classify, $filter) + public function __construct(Foundation $app, string $classify, array $filter) { parent::__construct($app); $this->classify = $classify; @@ -41,16 +41,16 @@ public function __construct(Foundation $app, $classify, $filter) /** * 请求API. * - * @param string $method - * @param array $params - * @param array $files - * - * @throws NotFoundException - * @throws IllegalParameterException + * @param string $method + * @param array $params + * @param array $files * * @return array + *@throws IllegalParameterException + * + * @throws NotFoundException */ - public function request($method, $params = [], $files = []) + public function request(string $method, array $params = [], array $files = []): array { $url = sprintf('%s/%s/%s_%s', self::BASE_API, $this->classify, $this->classify, strtolower($method)); if (!array_key_exists(strtolower($method), $this->filter)) { diff --git a/src/Core/Signature.php b/src/Core/Signature.php index 4fcbe51..4447b4a 100644 --- a/src/Core/Signature.php +++ b/src/Core/Signature.php @@ -32,11 +32,11 @@ public function __construct($appId, $secret) } /** - * @param array $params + * @param array $params * * @return string */ - public function getReqSign(&$params) + public function getReqSign(array &$params): string { $params['app_id'] = $this->appId; ksort($params); diff --git a/src/Core/Traits/ArgumentProcessingTrait.php b/src/Core/Traits/ArgumentProcessingTrait.php index 2bcea9b..b978391 100644 --- a/src/Core/Traits/ArgumentProcessingTrait.php +++ b/src/Core/Traits/ArgumentProcessingTrait.php @@ -8,11 +8,11 @@ trait ArgumentProcessingTrait { /** * @param Signature $signature - * @param array $params + * @param array $params * * @return array */ - public function processParams(Signature $signature, $params) + public function processParams(Signature $signature, array $params): array { if (empty($params['nonce_str'])) { $params['nonce_str'] = md5(uniqid('TencentAi_'));