Skip to content
This repository was archived by the owner on Jun 29, 2022. It is now read-only.

Commit 9a2079e

Browse files
author
justmd5
committed
code optimize
1 parent 78244d2 commit 9a2079e

File tree

7 files changed

+33
-29
lines changed

7 files changed

+33
-29
lines changed

src/Ai.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
* Class Ai.
1515
*
1616
* @property Core\Signature $signature
17-
* @property Core\API $aai
18-
* @property Core\API $face
19-
* @property Core\API $image
20-
* @property Core\API $nlp
21-
* @property Core\API $ocr
22-
* @property Core\API $ptu
23-
* @property Core\API $vision
17+
* @property Core\API $aai
18+
* @property Core\API $face
19+
* @property Core\API $image
20+
* @property Core\API $nlp
21+
* @property Core\API $ocr
22+
* @property Core\API $ptu
23+
* @property Core\API $vision
2424
*/
2525
class Ai extends Foundation
2626
{

src/Core/API.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,37 @@ class API extends AbstractAPI
3535
public function __construct(Signature $signature, $classify, $filter)
3636
{
3737
$this->signature = $signature;
38-
$this->classify = $classify;
39-
$this->filter = $filter;
38+
$this->classify = $classify;
39+
$this->filter = $filter;
4040
}
4141

4242
/**
4343
* 请求API.
4444
*
4545
* @param string $method
46-
* @param array $params
47-
* @param array $files
46+
* @param array $params
47+
* @param array $files
4848
*
49-
* @throws IllegalParameterException
49+
* @return array
5050
* @throws NotFoundException
5151
*
52-
* @return array
52+
* @throws IllegalParameterException
5353
*/
5454
public function request($method, $params = [], $files = [])
5555
{
5656
$url = sprintf('%s/%s/%s_%s', self::BASE_API, $this->classify, $this->classify, strtolower($method));
5757
if (!array_key_exists(strtolower($method), $this->filter)) {
5858
throw new NotFoundException(sprintf('the url %s can not found!please reaffirm', $url));
5959
}
60-
$factory = new ValidatorFactory(new Translator());
60+
$factory = new ValidatorFactory(new Translator());
6161
$validator = $factory->make($params, $this->filter[$method]);
6262
if (!$validator->passes()) {
6363
throw new IllegalParameterException(sprintf('参数错误:[%s]', json_encode($validator->errors(), JSON_UNESCAPED_UNICODE)));
6464
}
65-
$http = $this->getHttp();
66-
$params = $this->processParams($this->signature, $params);
65+
$http = $this->getHttp();
66+
$params = $this->processParams($this->signature, $params);
6767
$response = $files ? $http->upload($url, $params, $files) : $http->post($url, $params);
68-
$result = json_decode(strval($response->getBody()), true);
68+
$result = json_decode(strval($response->getBody()), true);
6969
if (isset($result['ret'])) {
7070
return $result;
7171
}

src/Core/ApplicationProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ApplicationProvider implements ServiceProviderInterface
2727
public function register(Container $pimple)
2828
{
2929
array_walk($this->filterArray, function ($filter, $key) use (&$pimple) {
30-
$pimple[$key] = function ($pimple) use ($filter,$key) {
30+
$pimple[$key] = function ($pimple) use ($filter, $key) {
3131
return new API($pimple['signature'], $key, $filter);
3232
};
3333
});

src/Core/Signature.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class Signature
2727
*/
2828
public function __construct($appId, $secret)
2929
{
30-
$this->appId = $appId;
30+
$this->appId = $appId;
3131
$this->secret = $secret;
3232
}
3333

src/Core/Traits/FilterTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ trait FilterTrait
2424
'tts' => [],
2525
'tta' => [],
2626
'detectkeyword' => [ //关键词检索
27-
'callback_url' => 'require|url',
28-
'speech' => 'required_without:speech_url',
29-
'speech_url' => 'required_without:speech',
30-
'key_words' => 'required',
31-
'format' => 'require|integer|in:1',
27+
'callback_url' => 'require|url',
28+
'speech' => 'required_without:speech_url',
29+
'speech_url' => 'required_without:speech',
30+
'key_words' => 'required',
31+
'format' => 'require|integer|in:1',
3232
],
3333
],
3434
'face' => [
@@ -37,7 +37,7 @@ trait FilterTrait
3737
'facecompare' => ['image_a' => 'required', 'image_b' => 'required'],
3838
'detectcrossageface' => ['source_image' => 'required', 'target_image' => 'required'],
3939
'faceshape' => ['image' => 'required', 'mode' => 'required:in:0,1'],
40-
'faceidentify' => ['image' => 'required', 'group_id'=>'required', 'topn'=>'required|between:1,10'],
40+
'faceidentify' => ['image' => 'required', 'group_id' => 'required', 'topn' => 'required|between:1,10'],
4141
'faceverify' => [],
4242
'newperson' => [],
4343
'delperson' => [],
@@ -57,10 +57,10 @@ trait FilterTrait
5757
'fuzzy' => ['image' => 'required'],
5858
],
5959
'nlp' => [
60-
'speechtranslate' => ['seq'=>'required|integer', 'end'=>'required|integer', 'session_id'=>'required|string|size:64'],
60+
'speechtranslate' => ['seq' => 'required|integer', 'end' => 'required|integer', 'session_id' => 'required|string|size:64'],
6161
'textpolar' => ['text' => 'required|max:200'],
6262
'texttrans' => ['text' => 'required|max:1024'],
63-
'texttranslate' => ['type'=>'required|integer|between:0,16', 'text' => 'required|max:1024'],
63+
'texttranslate' => ['type' => 'required|integer|between:0,16', 'text' => 'required|max:1024'],
6464
'textchat' => [
6565
'session' => 'required|max:32',
6666
'question' => 'required|max:3000',

src/Exception/IllegalParameterException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
namespace Justmd5\TencentAi\Exception;
1010

11-
class IllegalParameterException extends \Exception
11+
use Exception;
12+
13+
class IllegalParameterException extends Exception
1214
{
1315
protected $code = 10403;
1416
}

src/Exception/NotFoundException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
namespace Justmd5\TencentAi\Exception;
1010

11-
class NotFoundException extends \Exception
11+
use Exception;
12+
13+
class NotFoundException extends Exception
1214
{
1315
protected $code = 10404;
1416
}

0 commit comments

Comments
 (0)