diff --git a/.gitattributes b/.gitattributes index c4ff8b1..20855fc 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4,9 +4,4 @@ /.github export-ignore .gitattributes export-ignore .gitignore export-ignore -.scrutinizer.yml export-ignore -.travis.yml export-ignore -phpunit.php export-ignore phpunit.xml.dist export-ignore -phpunit.xml export-ignore -.php_cs export-ignore diff --git a/.github/workflows/php.yaml b/.github/workflows/php.yaml index 468e3eb..ee192ac 100644 --- a/.github/workflows/php.yaml +++ b/.github/workflows/php.yaml @@ -9,7 +9,7 @@ jobs: strategy: matrix: operating-system: ['ubuntu-latest'] - php-versions: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] + php-versions: ['8.1', '8.2'] steps: - name: Checkout uses: actions/checkout@v2 @@ -23,14 +23,10 @@ jobs: coverage: none - name: Install dependencies - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer update --prefer-stable --prefer-dist --no-interaction --no-progress + run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - - name: PHPUnit Test - run: vendor/bin/phpunit --verbose + - name: PHP Unit Test + run: vendor/bin/phpunit env: BAIDU_ACCESS_KEY: ${{ secrets.BAIDU_ACCESS_KEY }} BAIDU_SECRET_KEY: ${{ secrets.BAIDU_SECRET_KEY }} @@ -46,7 +42,7 @@ jobs: fail-fast: false matrix: php-version: - - 8.0 + - 8.2 dependencies: - highest steps: @@ -59,18 +55,13 @@ jobs: php-version: ${{ matrix.php-version }} coverage: pcov extensions: gd - tools: composer:v2, php-cs-fixer - - - name: Coding Guidelines - run: php-cs-fixer fix --config=.php-cs-fixer.php + tools: composer:v2 - - name: Install lowest dependencies with composer - if: matrix.dependencies == 'lowest' - run: composer update --no-ansi --no-interaction --no-progress --prefer-lowest + - name: Install dependencies + run: composer update --prefer-stable --prefer-dist --no-interaction --no-progress - - name: Install highest dependencies with composer - if: matrix.dependencies == 'highest' - run: composer update --no-ansi --no-interaction --no-progress + - name: Coding Guidelines + run: vendor/bin/pint --test --config ./pint.json - name: Collect code coverage with phpunit run: vendor/bin/phpunit --coverage-clover=coverage.xml @@ -86,10 +77,3 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} files: ./coverage.xml - version: "v0.1.15" - env: - BAIDU_ACCESS_KEY: ${{ secrets.BAIDU_ACCESS_KEY }} - BAIDU_SECRET_KEY: ${{ secrets.BAIDU_SECRET_KEY }} - ALIYUN_APPCODE: ${{ secrets.ALIYUN_APPCODE }} - TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }} - TENCENT_SECRET_KEY: ${{ secrets.TENCENT_SECRET_KEY }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9768a98..8d86d34 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ composer.lock *.log /.php-cs-fixer.cache /.phpunit.result.cache +.phpunit.cache diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php deleted file mode 100644 index 6b9a99b..0000000 --- a/.php-cs-fixer.php +++ /dev/null @@ -1,30 +0,0 @@ - - -This source file is subject to the MIT license that is bundled. -EOF; - -use PhpCsFixer\Config; -use PhpCsFixer\Finder; - -return (new Config())->setRules([ - '@PSR2' => true, - 'header_comment' => ['header' => $header], - 'array_syntax' => ['syntax' => 'short'], - 'ordered_imports' => true, - 'no_useless_else' => true, - 'no_useless_return' => true, -]) - ->setFinder( - Finder::create() - ->in(__DIR__) - ->exclude('vendor') - ->name('*.php') - ->notName('*.blade.php') - ) - ->setUsingCache(false) - ->setRiskyAllowed(true); diff --git a/README.md b/README.md index 287870a..f58f939 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,15 @@ ## Requirement -- PHP >= 7.1 +- PHP >= 8.1 - composer ## Installation -> 注意此版本**不兼容** 1.x 版本,若你在寻在 1.x 版本,请查看 [这里](https://github.com/godruoyi/ocr/tree/1.1.4)。 - -``` -composer require "godruoyi/ocr:^2.1" -``` +| SDK Version | PHP Version | Composer Command | +| ----------- | ----------- |----------------------------------------| +| 3.x | >= 8.1 | `composer require "godruoyi/ocr:^3.0"` | +| 2.x | >= 7.2 | `composer require "godruoyi/ocr:^2.1"` | ## Document diff --git a/composer.json b/composer.json index d99a2f3..bc8f927 100644 --- a/composer.json +++ b/composer.json @@ -10,18 +10,19 @@ "email": "godruoyi@gmail.com" }], "require": { - "php": ">=7.1.3", - "guzzlehttp/guzzle": "^6.3 || ^7.0", - "monolog/monolog": "^1.22 || ^2.0", - "psr/log": "^1.0", - "godruoyi/easy-container": "^1.1", - "psr/simple-cache": "^1.0 || ^2.0 || ^3.0", - "symfony/cache": "^4.4 || ^5.0 || ^6.0", + "php": ">=8.1", + "guzzlehttp/guzzle": "^7.2", + "monolog/monolog": "^3.0", + "psr/log": "^2.0 || ^3.0", + "godruoyi/easy-container": "^2.0", + "psr/simple-cache": "^2.0 || ^3.0", + "symfony/cache": "^6.1", "ext-json": "*" }, "require-dev": { - "phpunit/phpunit": ">=6.0", - "mockery/mockery": "^1.0", + "phpunit/phpunit": "^10.1", + "mockery/mockery": "^1.6", + "laravel/pint": "^1.10", "ext-gd": "*" }, "autoload": { @@ -35,6 +36,7 @@ } }, "scripts": { - "test": "vendor/bin/phpunit" + "test": "vendor/bin/phpunit", + "pint": "vendor/bin/pint" } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3bfc6f4..8286553 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,22 @@ - - - - ./tests/ - - - - - - src/ - - - - - - - - - - - - + + + + ./tests/ + + + + + + + + + + + + + + src/ + + diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..18bef1d --- /dev/null +++ b/pint.json @@ -0,0 +1,14 @@ +{ + "rules": { + "header_comment": { + "header": "This file is part of the godruoyi/ocr.\n \n(c) Godruoyi \n \nThis source file is subject to the MIT license that is bundled." + }, + "no_superfluous_phpdoc_tags": false, + "array_syntax" : { + "syntax" : "short" + }, + "ordered_imports" : true, + "no_useless_else" : true, + "no_useless_return" : true + } +} diff --git a/src/Application.php b/src/Application.php index c597c1c..d45c0d7 100644 --- a/src/Application.php +++ b/src/Application.php @@ -47,6 +47,7 @@ class Application extends Manager /** * Create application instance. + * * @throws Exception */ public function __construct(array $config = []) @@ -69,6 +70,7 @@ public function getContainer(): Container /** * Boot application for ocr. + * * @throws Exception */ protected function boot() @@ -81,6 +83,7 @@ protected function boot() * Registe core alias and service. * * @return void + * * @throws Exception */ protected function registerCore() @@ -114,7 +117,7 @@ protected function registerDefaultProvider() /** * Register a service to container. * - * @param mixed $service + * @param mixed $service */ public function register($service) { @@ -138,8 +141,7 @@ public function register($service) /** * Recover __get method. * - * @param mixed $key - * + * @param mixed $key * @return mixed */ public function __get($key) @@ -149,9 +151,6 @@ public function __get($key) /** * RebindCache cache support. - * - * @param CacheInterface $cache - * @return Application */ public function rebindCache(CacheInterface $cache): self { diff --git a/src/Clients/AliyunClient.php b/src/Clients/AliyunClient.php index b8e01b7..55506c6 100644 --- a/src/Clients/AliyunClient.php +++ b/src/Clients/AliyunClient.php @@ -26,23 +26,41 @@ class AliyunClient extends Client { public const OCR_IDCARD = 'https://dm-51.data.aliyun.com/rest/160601/ocr/ocr_idcard.json'; + public const OCR_VEHICLE = 'https://dm-53.data.aliyun.com/rest/160601/ocr/ocr_vehicle.json'; + public const OCR_DRIVER_LICENSE = 'https://dm-52.data.aliyun.com/rest/160601/ocr/ocr_driver_license.json'; + public const OCR_BUSINESS_LICENSE = 'https://dm-58.data.aliyun.com/rest/160601/ocr/ocr_business_license.json'; + public const OCR_BANK_CARD = 'http://yhk.market.alicloudapi.com/rest/160601/ocr/ocr_bank_card.json'; + public const OCR_BUSINESS_CARD = 'https://dm-57.data.aliyun.com/rest/160601/ocr/ocr_business_card.json'; + public const OCR_TRAIN_TICKET = 'http://ocrhcp.market.alicloudapi.com/api/predict/ocr_train_ticket'; + public const OCR_VEHICLE_PLATE = 'http://ocrcp.market.alicloudapi.com/rest/160601/ocr/ocr_vehicle_plate.json'; + public const OCR_GENERAL = 'http://tysbgpu.market.alicloudapi.com/api/predict/ocr_general'; + public const OCR_PASSPORT = 'https://ocrhz.market.alicloudapi.com/rest/160601/ocr/ocr_passport.json'; + public const TABLE_PARSE = 'https://form.market.alicloudapi.com/api/predict/ocr_table_parse'; + public const OCR_VIN = 'https://vin.market.alicloudapi.com/api/predict/ocr_vin'; + public const OCR_INVOICE = 'https://ocrapi-invoice.taobao.com/ocrservice/invoice'; + public const OCR_GENERAL_ADVANCED = 'https://ocrapi-advanced.taobao.com/ocrservice/advanced'; + public const OCR_HOUSECERT = 'https://ocrapi-house-cert.taobao.com/ocrservice/houseCert'; + public const OCR_DOCUMENT = 'https://ocrapi-document.taobao.com/ocrservice/document'; + public const OCR_ECOMMERCE = 'https://ocrapi-ecommerce.taobao.com/ocrservice/ecommerce'; + public const OCR_UGC = 'https://ocrapi-ugc.taobao.com/ocrservice/ugc'; + public const OCR_CUSTOM = 'https://ocrdiy.market.alicloudapi.com/api/predict/ocr_sdt'; /** @@ -58,11 +76,10 @@ public function __construct(AliyunRequest $request) * * @see https://market.aliyun.com/products/57124001/cmapi010401.html#sku=yuncode440100000 * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * side N string 默认face,身份证正反面类型:face/back - * * @return array */ public function idcard($images, array $options = []) @@ -77,10 +94,9 @@ public function idcard($images, array $options = []) * * @see https://market.aliyun.com/products/57002003/cmapi011791.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * side N string 默认face,行驶证正反面类型:face/back - * * @return array */ public function vehicle($images, array $options = []) @@ -95,11 +111,10 @@ public function vehicle($images, array $options = []) * * @see https://market.aliyun.com/products/57002002/cmapi010402.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * side N string 默认face,驾驶证首页/副页:face/back - * * @return array */ public function driverLicense($images, array $options = []) @@ -114,10 +129,9 @@ public function driverLicense($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi013592.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * null - * * @return array */ public function businessLicense($images, array $options = []) @@ -130,10 +144,9 @@ public function businessLicense($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi016870.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * null - * * @return array */ public function bankCard($images, array $options = []) @@ -146,10 +159,9 @@ public function bankCard($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi013591.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * null - * * @return array */ public function businessCard($images, array $options = []) @@ -162,10 +174,9 @@ public function businessCard($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi016682.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * null - * * @return array */ public function passport($images, array $options = []) @@ -178,14 +189,13 @@ public function passport($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi024968.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * format N string format 输出格式html/json/xlsx * dir_assure N bool 图片方向是否确定是正向的: true(确定)/false(不确定) * line_less N bool 是否无线条: true(无线条,或者只有横线没有竖线)/false(有线条) * skip_detection N bool 是否跳过检测,如果没有检测到表格,可以设置"skip_detection":true - * * @return array */ public function tableParse($images, array $options = []) @@ -200,10 +210,9 @@ public function tableParse($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi023049.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 - * * @return array */ public function vin($images, array $options = []) @@ -216,10 +225,9 @@ public function vin($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi020096.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * null - * * @return array */ public function trainTicket($images, array $options = []) @@ -234,12 +242,11 @@ public function trainTicket($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi020094.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * multi_crop N boolean 当设成true时,会做多crop预测,只有当多crop返回的结果一致, * 并且置信度>0.9时,才返回结果 - * * @return array */ public function vehiclePlate($images, array $options = []) @@ -254,15 +261,14 @@ public function vehiclePlate($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi020020.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * min_size 16, 图片中文字的最小高度,单位像素 * output_prob true, 是否输出文字框的概率 * output_keypoints false, 是否输出文字框角点 * skip_detection false 是否跳过文字检测步骤直接进行文字识别 * without_predicting_direction false 是否关闭文字行方向预测 - * * @return array */ public function general($images, array $options = []) @@ -278,15 +284,14 @@ public function general($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi028554.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要 * charInfo N bool 是否需要单字识别功能,默认不需要。 true:需要 false:不需要 * rotate N bool 是否需要自动旋转功能,默认不需要。 true:需要 false:不需要 * table N bool 是否需要表格识别功能,默认不需要。 true:需要 false:不需要 * sortPage N bool 字块返回顺序,false表示从左往右,从上到下的顺序,true表示从上到下,从左往右的顺序,默认false - * * @return array */ public function generalAdvanced($images, array $options = []) @@ -309,10 +314,9 @@ public function generalAdvanced($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi027758.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 - * * @return array */ public function invoice($images, array $options = []) @@ -327,10 +331,9 @@ public function invoice($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi028523.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 - * * @return array */ public function houseCert($images, array $options = []) @@ -345,11 +348,10 @@ public function houseCert($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi023866.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要 - * * @return array */ public function document($images, array $options = []) @@ -364,11 +366,10 @@ public function document($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi023869.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要 - * * @return array */ public function ugc($images, array $options = []) @@ -383,11 +384,10 @@ public function ugc($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi029975.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要 - * * @return array */ public function custom($images, array $options = []) @@ -402,11 +402,10 @@ public function custom($images, array $options = []) * * @see https://market.aliyun.com/products/57124001/cmapi023866.html * - * @param string|SplFIleInfo $images - * @param array $options + * @param string|SplFIleInfo $images + * @param array $options * 参数 是否可选 类型 可选范围/说明 * prob N bool 是否需要识别结果中每一行的置信度,默认不需要。 true:需要 false:不需要 - * * @return array */ public function ecommerce($images, array $options = []) diff --git a/src/Clients/BaiduClient.php b/src/Clients/BaiduClient.php index 8077ab5..7fcb7dc 100644 --- a/src/Clients/BaiduClient.php +++ b/src/Clients/BaiduClient.php @@ -36,8 +36,7 @@ public function __construct(BaiduRequest $request) * * @see https://ai.baidu.com/ai-doc/OCR/zk3h7xz52 查看请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function generalBasic($images, array $options = []) @@ -50,8 +49,7 @@ public function generalBasic($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/1k3h7y3db 查看请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function accurateBasic($images, array $options = []) @@ -66,8 +64,7 @@ public function accurateBasic($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/vk3h7y58v 查看请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function general($images, array $options = []) @@ -80,8 +77,7 @@ public function general($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/tk3h7y2aq 查看请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function accurate($images, array $options = []) @@ -96,8 +92,7 @@ public function accurate($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/ykg9c09ji 查看请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function docAnalysisOffice($images, array $options = []) @@ -112,8 +107,7 @@ public function docAnalysisOffice($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/hk3h7y2qq 查看完整请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function handwriting($images, array $options = []) @@ -128,8 +122,7 @@ public function handwriting($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/rk3h7xzck * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function idcard($images, array $options = []) @@ -144,8 +137,7 @@ public function idcard($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/ak3h7xxg3 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function bankcard($images, array $options = []) @@ -158,8 +150,7 @@ public function bankcard($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/sk3h7y3zs * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function businessLicense($images, array $options = []) @@ -174,8 +165,7 @@ public function businessLicense($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Wk3h7y1gi * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function passport($images, array $options = []) @@ -188,8 +178,7 @@ public function passport($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/5k3h7xyi2 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function businessCard($images, array $options = []) @@ -202,8 +191,7 @@ public function businessCard($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/ak3h7xzk7 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function householdRegister($images, array $options = []) @@ -216,8 +204,7 @@ public function householdRegister($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/mk3h7y1o6 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function birthCertificate($images, array $options = []) @@ -230,8 +217,7 @@ public function birthCertificate($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/nkbq6wxxy * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function multiCardClassify($images, array $options = []) @@ -244,8 +230,7 @@ public function multiCardClassify($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/4k3h7y0ly * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function hkMacauExitentrypermit($images, array $options = []) @@ -258,8 +243,7 @@ public function hkMacauExitentrypermit($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/kk3h7y2yc * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function taiwanExitentrypermit($images, array $options = []) @@ -274,8 +258,7 @@ public function taiwanExitentrypermit($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Ik3h7y238 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function asynTable($images, array $options = []) @@ -290,13 +273,12 @@ public function asynTable($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Ik3h7y238 * - * @param string|\SplFileInfo $requestId - * @param array $requestType 期望获取结果的类型,取值为 “excel” 时返回 xls 文件的地址, + * @param string|\SplFileInfo $requestId + * @param array $requestType 期望获取结果的类型,取值为 “excel” 时返回 xls 文件的地址, * 取值为 “json” 时返回 json 格式的字符串,默认为 ”excel” + * @return array * * @throws \RuntimeException - * - * @return array */ public function asynTableInfo(string $requestId, string $requestType = null) { @@ -315,8 +297,7 @@ public function asynTableInfo(string $requestId, string $requestType = null) * * @see https://ai.baidu.com/ai-doc/OCR/ik3h7xyxf 查看请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function syncTable($images, array $options = []) @@ -329,8 +310,7 @@ public function syncTable($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/6k3h7y11b * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function receipt($images, array $options = []) @@ -345,8 +325,7 @@ public function receipt($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/yke30j1hq * - * @param mixed $images - * + * @param mixed $images * @return array */ public function medicalInvoice($images, array $options = []) @@ -361,8 +340,7 @@ public function medicalInvoice($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Jke30ki7d * - * @param mixed $images - * + * @param mixed $images * @return array */ public function medicalStatement($images, array $options = []) @@ -377,8 +355,7 @@ public function medicalStatement($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/1ke30k2s2 * - * @param mixed $images - * + * @param mixed $images * @return array */ public function medicalRecord($images, array $options = []) @@ -393,8 +370,7 @@ public function medicalRecord($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Wk3h7y0eb * - * @param mixed $images - * + * @param mixed $images * @return array */ public function insuranceDocuments($images, array $options = []) @@ -409,8 +385,7 @@ public function insuranceDocuments($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/nk3h7xy2t * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function vatInvoice($images, array $options = []) @@ -425,8 +400,7 @@ public function vatInvoice($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Ok3h7y35u * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function trainTicket($images, array $options = []) @@ -441,8 +415,7 @@ public function trainTicket($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Zk3h7xxnn * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function taxiReceipt($images, array $options = []) @@ -457,8 +430,7 @@ public function taxiReceipt($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/lk3h7y4ev * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function quotaInvoice($images, array $options = []) @@ -471,8 +443,7 @@ public function quotaInvoice($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Vk3h7xzz7 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function drivingLicense($images, array $options = []) @@ -487,8 +458,7 @@ public function drivingLicense($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/yk3h7y3ks * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function vehicleLicense($images, array $options = []) @@ -503,8 +473,7 @@ public function vehicleLicense($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/ck3h7y191 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function licensePlate($images, array $options = []) @@ -519,8 +488,7 @@ public function licensePlate($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/vk3h7y4tx * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function vehicleInvoice($images, array $options = []) @@ -535,8 +503,7 @@ public function vehicleInvoice($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/yk3h7y3sc * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function vehicleCertificate($images, array $options = []) @@ -551,8 +518,7 @@ public function vehicleCertificate($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/jk9m7mj1l * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function docAnalysis($images, array $options = []) @@ -567,8 +533,7 @@ public function docAnalysis($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Ok3h7xxva * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function formula($images, array $options = []) @@ -583,8 +548,7 @@ public function formula($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/zk3h7y51e * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function vin($images, array $options = []) @@ -599,8 +563,7 @@ public function vin($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/qk3h7y5o7 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function qrcode($images, array $options = []) @@ -617,8 +580,7 @@ public function qrcode($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Ok3h7y1vo 查看请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function numbers($images, array $options = []) @@ -635,8 +597,7 @@ public function numbers($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Sk3h7xyad 查看请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function webimage($images, array $options = []) @@ -649,8 +610,7 @@ public function webimage($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Nkaz574we 查看请求参数 * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function webimageLoc($images, array $options = []) @@ -665,8 +625,7 @@ public function webimageLoc($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/ik3h7y5gl * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function lottery($images, array $options = []) @@ -681,8 +640,7 @@ public function lottery($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Jkafike0v * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function meter($images, array $options = []) @@ -697,8 +655,7 @@ public function meter($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Mk3h7y47a * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function seal($images, array $options = []) @@ -713,8 +670,7 @@ public function seal($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/wk5hw3cvo * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function facade($images, array $options = []) @@ -729,8 +685,7 @@ public function facade($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Pk3h7y06q * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function invoice($images, array $options = []) @@ -745,8 +700,7 @@ public function invoice($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Qk3h7xzro * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function airTicket($images, array $options = []) @@ -761,8 +715,7 @@ public function airTicket($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/Kkblx01ww * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function busTicket($images, array $options = []) @@ -777,8 +730,7 @@ public function busTicket($images, array $options = []) * * @see https://ai.baidu.com/ai-doc/OCR/1kbpyx8js * - * @param string|\SplFileInfo $images - * + * @param string|\SplFileInfo $images * @return array */ public function tollInvoice($images, array $options = []) diff --git a/src/Clients/Client.php b/src/Clients/Client.php index d37b1ad..b1430fb 100644 --- a/src/Clients/Client.php +++ b/src/Clients/Client.php @@ -34,11 +34,9 @@ class Client implements ClientInterface /** * Register a custom method Closure. * - * @param \Closure $callback - * * @return $this */ - public function extend(string $method, Closure $fn) + public function extend(string $method, Closure $fn): static { $this->customMethods[$method] = $fn; @@ -48,14 +46,13 @@ public function extend(string $method, Closure $fn) /** * Dynamically call the default driver instance. * - * @param string $method - * @param array $parameters - * + * @param string $method + * @param array $parameters * @return mixed */ public function __call($method, $parameters) { - if (!isset($this->customMethods[$method])) { + if (! isset($this->customMethods[$method])) { throw new BadMethodCallException(sprintf('Method %s::%s does not exist.', static::class, $method)); } @@ -67,9 +64,8 @@ public function __call($method, $parameters) /** * Request. * - * @param string $url - * @param mixed $images - * + * @param string $url + * @param mixed $images * @return array */ public function request($url, $images, array $options = []): ResponseInterface diff --git a/src/Clients/TencentClient.php b/src/Clients/TencentClient.php index 8dc86c6..332875b 100644 --- a/src/Clients/TencentClient.php +++ b/src/Clients/TencentClient.php @@ -26,7 +26,7 @@ class TencentClient extends Client /** * Register request. * - * @param TencentClient $request + * @param TencentClient $request */ public function __construct(TencentRequest $request) { @@ -38,8 +38,7 @@ public function __construct(TencentRequest $request) * * @see https://cloud.tencent.com/document/product/866/33526 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function generalBasic($images, array $options = []) @@ -52,8 +51,7 @@ public function generalBasic($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/49524 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function advertise($images, array $options = []) @@ -66,8 +64,7 @@ public function advertise($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/34937 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function generalAccurate($images, array $options = []) @@ -80,8 +77,7 @@ public function generalAccurate($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37831 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function generalEfficient($images, array $options = []) @@ -94,8 +90,7 @@ public function generalEfficient($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/33525 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function generalFast($images, array $options = []) @@ -108,8 +103,7 @@ public function generalFast($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/34938 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function english($images, array $options = []) @@ -122,8 +116,7 @@ public function english($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/36212 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function generalHandwriting($images, array $options = []) @@ -136,8 +129,7 @@ public function generalHandwriting($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37830 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function textDetect($images, array $options = []) @@ -150,8 +142,7 @@ public function textDetect($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/33524 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function idCard($images, array $options = []) @@ -164,8 +155,7 @@ public function idCard($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/36214 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function businessCard($images, array $options = []) @@ -178,8 +168,7 @@ public function businessCard($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/36215 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function bizLicense($images, array $options = []) @@ -192,8 +181,7 @@ public function bizLicense($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/36216 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function bankCard($images, array $options = []) @@ -206,8 +194,7 @@ public function bankCard($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/37074 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function permit($images, array $options = []) @@ -220,8 +207,7 @@ public function permit($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/37656 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function mlidCard($images, array $options = []) @@ -234,8 +220,7 @@ public function mlidCard($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/37657 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function mlidPassport($images, array $options = []) @@ -248,8 +233,7 @@ public function mlidPassport($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/37840 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function passport($images, array $options = []) @@ -262,8 +246,7 @@ public function passport($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/38298 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function orgCodeCert($images, array $options = []) @@ -276,8 +259,7 @@ public function orgCodeCert($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/38299 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function institution($images, array $options = []) @@ -290,8 +272,7 @@ public function institution($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/38300 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function estateCert($images, array $options = []) @@ -304,8 +285,7 @@ public function estateCert($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/38849 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function enterpriseLicense($images, array $options = []) @@ -318,8 +298,7 @@ public function enterpriseLicense($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/40036 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function residenceBooklet($images, array $options = []) @@ -332,8 +311,7 @@ public function residenceBooklet($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/40037 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function propOwnerCert($images, array $options = []) @@ -346,8 +324,7 @@ public function propOwnerCert($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/43105 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function mainlandPermit($images, array $options = []) @@ -360,8 +337,7 @@ public function mainlandPermit($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/43106 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function hmtResidentPermitOCR($images, array $options = []) @@ -374,8 +350,7 @@ public function hmtResidentPermitOCR($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/46770 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function classifyDetect($images, array $options = []) @@ -388,8 +363,7 @@ public function classifyDetect($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/46919 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function hkIDCard($images, array $options = []) @@ -402,8 +376,7 @@ public function hkIDCard($images, array $options = []) * * @see @see https://cloud.tencent.com/document/product/866/48475 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function recognizeThaiIDCard($images, array $options = []) @@ -416,8 +389,7 @@ public function recognizeThaiIDCard($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/34934 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function waybill($images, array $options = []) @@ -430,8 +402,7 @@ public function waybill($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/36210 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function vatInvoice($images, array $options = []) @@ -444,8 +415,7 @@ public function vatInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37071 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function trainTicket($images, array $options = []) @@ -458,8 +428,7 @@ public function trainTicket($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37072 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function taxiInvoice($images, array $options = []) @@ -472,8 +441,7 @@ public function taxiInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37073 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function quotaInvoice($images, array $options = []) @@ -486,8 +454,7 @@ public function quotaInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37075 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function flightInvoice($images, array $options = []) @@ -500,8 +467,7 @@ public function flightInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37076 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function carInvoice($images, array $options = []) @@ -514,8 +480,7 @@ public function carInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37832 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function vatRollInvoice($images, array $options = []) @@ -528,8 +493,7 @@ public function vatRollInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37833 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function tollInvoice($images, array $options = []) @@ -542,8 +506,7 @@ public function tollInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37834 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function shipInvoice($images, array $options = []) @@ -556,8 +519,7 @@ public function shipInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37835 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function mixedInvoice($images, array $options = []) @@ -570,8 +532,7 @@ public function mixedInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37836 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function mixedInvoiceDetect($images, array $options = []) @@ -584,8 +545,7 @@ public function mixedInvoiceDetect($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37837 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function invoiceGeneral($images, array $options = []) @@ -598,8 +558,7 @@ public function invoiceGeneral($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37838 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function busInvoice($images, array $options = []) @@ -612,8 +571,7 @@ public function busInvoice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/37839 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function dutyPaidProof($images, array $options = []) @@ -626,8 +584,7 @@ public function dutyPaidProof($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/38295 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function finanBillSlice($images, array $options = []) @@ -640,8 +597,7 @@ public function finanBillSlice($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/38296 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function finanBill($images, array $options = []) @@ -654,8 +610,7 @@ public function finanBill($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/34935 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function vin($images, array $options = []) @@ -668,8 +623,7 @@ public function vin($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/36209 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function vehicleLicense($images, array $options = []) @@ -682,8 +636,7 @@ public function vehicleLicense($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/36211 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function licensePlate($images, array $options = []) @@ -696,8 +649,7 @@ public function licensePlate($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/36213 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function driverLicense($images, array $options = []) @@ -710,8 +662,7 @@ public function driverLicense($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/38297 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function vehicleRegCert($images, array $options = []) @@ -724,8 +675,7 @@ public function vehicleRegCert($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/47165 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function rideHailingDriverLicense($images, array $options = []) @@ -738,8 +688,7 @@ public function rideHailingDriverLicense($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/47325 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function rideHailingTransportLicense($images, array $options = []) @@ -754,8 +703,7 @@ public function rideHailingTransportLicense($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/49525 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function recognizeTable($images, array $options = []) @@ -770,8 +718,7 @@ public function recognizeTable($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/34936 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function table($images, array $options = []) @@ -784,8 +731,7 @@ public function table($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/34939 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function arithmetic($images, array $options = []) @@ -798,8 +744,7 @@ public function arithmetic($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/38293 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function formula($images, array $options = []) @@ -812,8 +757,7 @@ public function formula($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/38294 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function eduPaper($images, array $options = []) @@ -826,8 +770,7 @@ public function eduPaper($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/38848 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function insuranceBill($images, array $options = []) @@ -840,8 +783,7 @@ public function insuranceBill($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/45807 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function seal($images, array $options = []) @@ -856,8 +798,7 @@ public function seal($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/45513 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function queryBarCode($images, array $options = []) @@ -870,8 +811,7 @@ public function queryBarCode($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/38292 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function qrcode($images, array $options = []) @@ -886,8 +826,7 @@ public function qrcode($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/47278 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function verifyBizLicense($images, array $options = []) @@ -900,8 +839,7 @@ public function verifyBizLicense($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/47279 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function verifyBasicBizLicense($images, array $options = []) @@ -916,8 +854,7 @@ public function verifyBasicBizLicense($images, array $options = []) * * @see https://cloud.tencent.com/document/product/866/47324 * - * @param mixed $images - * + * @param mixed $images * @return mixed */ public function vatInvoiceVerify($images, array $options = []) diff --git a/src/Config.php b/src/Config.php index d0bcfb6..eb7b41b 100644 --- a/src/Config.php +++ b/src/Config.php @@ -30,9 +30,8 @@ public function __construct(array $items = []) /** * Get config item. * - * @param mixed $key - * @param mixed $default - * + * @param mixed $key + * @param mixed $default * @return mixed */ public function get($key, $default = null) diff --git a/src/Contracts/Client.php b/src/Contracts/Client.php index 667f214..10142f7 100644 --- a/src/Contracts/Client.php +++ b/src/Contracts/Client.php @@ -18,8 +18,8 @@ interface Client /** * Fire a ocr http request. * - * @param string $url - * @param mixed $images + * @param string $url + * @param mixed $images * * @throws RequestException */ diff --git a/src/Contracts/Request.php b/src/Contracts/Request.php index 432b735..7ddaf81 100644 --- a/src/Contracts/Request.php +++ b/src/Contracts/Request.php @@ -17,8 +17,8 @@ interface Request /** * Fire a ocr http request. * - * @param string $url - * @param mixed $images + * @param string $url + * @param mixed $images * * @throws \GuzzleHttp\Exception\RequestException */ diff --git a/src/Manager.php b/src/Manager.php index 9162d0a..6f964cd 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -67,7 +67,7 @@ public function driver(string $driver = null): Client // If the given driver has not been created before, we will create the instances // here and cache it so we can return it next time very quickly. If there is // already a driver created by this name, we'll just return that instance. - if (!isset($this->drivers[$driver])) { + if (! isset($this->drivers[$driver])) { $this->drivers[$driver] = $this->createDriver($driver); } @@ -77,8 +77,7 @@ public function driver(string $driver = null): Client /** * Create a new driver instance. * - * @param string $driver - * + * @param string $driver * @return mixed * * @throws InvalidArgumentException @@ -92,7 +91,7 @@ protected function createDriver($driver): Client return $this->callCustomCreator($driver); } - $method = 'create' . ucfirst($driver) . 'Driver'; + $method = 'create'.ucfirst($driver).'Driver'; if (method_exists($this, $method)) { return $this->$method(); @@ -104,8 +103,7 @@ protected function createDriver($driver): Client /** * Call a custom driver creator. * - * @param string $driver - * + * @param string $driver * @return mixed */ protected function callCustomCreator($driver) @@ -116,8 +114,7 @@ protected function callCustomCreator($driver) /** * Register a custom driver creator Closure. * - * @param string $driver - * + * @param string $driver * @return $this */ public function extend($driver, Closure $callback) @@ -140,9 +137,8 @@ public function getDrivers() /** * Dynamically call the default driver instance. * - * @param string $method - * @param array $parameters - * + * @param string $method + * @param array $parameters * @return mixed */ public function __call($method, $parameters) diff --git a/src/Requests/AliyunRequest.php b/src/Requests/AliyunRequest.php index 62be46e..051b34c 100644 --- a/src/Requests/AliyunRequest.php +++ b/src/Requests/AliyunRequest.php @@ -33,18 +33,18 @@ public function send($url, $images, array $options = []): ResponseInterface } /** - * @param mixed $images + * @param mixed $images */ protected function mergeOptions($images, array $options): array { $images = $this->filterOneImage($images, 'Aliyun ocr only one image can be identified at a time, default to array[0].'); $format = $options['_format'] ?? 'inputs'; - if (!in_array($format, $this->requestFormats, true)) { - throw new InvalidArgumentException(sprintf('Unallowed format type, only [%s]', join($this->requestFormats, ','))); + if (! in_array($format, $this->requestFormats, true)) { + throw new InvalidArgumentException(sprintf('Unallowed format type, only [%s]', implode($this->requestFormats, ','))); } - $format = 'format' . ucfirst($format); + $format = 'format'.ucfirst($format); return $this->{$format}($images, $options); } @@ -52,13 +52,13 @@ protected function mergeOptions($images, array $options): array /** * Basic request format. * - * @param mixed $images + * @param mixed $images */ protected function formatBasic($images, array $options): array { // If gieved image is not url, try get image content to base64 encode. // Be careful, some methods do not support online images. - if (!FileConverter::isUrl($images)) { + if (! FileConverter::isUrl($images)) { $images = FileConverter::toBase64Encode($images); } @@ -71,11 +71,11 @@ protected function formatBasic($images, array $options): array /** * Use inputs warp request data. * - * @param mixed $images + * @param mixed $images */ protected function formatInputs($images, array $options): array { - if (!FileConverter::isUrl($images)) { + if (! FileConverter::isUrl($images)) { $images = FileConverter::toBase64Encode($images); } @@ -98,15 +98,14 @@ protected function formatInputs($images, array $options): array /** * support online image. * - * @param mixed $images - * + * @param mixed $images * @return array */ protected function formatImgorurl($images, array $options) { $datas = []; - if (!FileConverter::isUrl($images)) { + if (! FileConverter::isUrl($images)) { $datas['img'] = FileConverter::toBase64Encode($images); } else { $datas['url'] = $images; @@ -145,8 +144,7 @@ protected function authRequest() /** * AppKey And AppSecret signature. * - * @param mixed $request - * + * @param mixed $request * @return mixed */ protected function signatureRequestUseAppSecret($request) @@ -158,15 +156,14 @@ protected function signatureRequestUseAppSecret($request) /** * Signature Request Use AppCode. * - * @param mixed $request - * + * @param mixed $request * @return mixed */ public function signatureRequestUseAppCode($request) { $appcode = $this->app['config']->get('drivers.aliyun.appcode'); - return $request->withHeader('Authorization', 'APPCODE ' . $appcode); + return $request->withHeader('Authorization', 'APPCODE '.$appcode); } protected function canUseSignatureWay(): bool @@ -174,6 +171,6 @@ protected function canUseSignatureWay(): bool $id = $this->app['config']->get('drivers.aliyun.secret_id'); $key = $this->app['config']->get('drivers.aliyun.secret_key'); - return !empty($id) && !empty($key); + return ! empty($id) && ! empty($key); } } diff --git a/src/Requests/BaiduRequest.php b/src/Requests/BaiduRequest.php index d1bd7a0..9bfc848 100644 --- a/src/Requests/BaiduRequest.php +++ b/src/Requests/BaiduRequest.php @@ -49,14 +49,15 @@ protected function init() */ public function send($url, $images, array $options = []): ResponseInterface { - $url = $url . '?access_token=' . $this->accessToken->getAccessToken(); + $url = $url.'?access_token='.$this->accessToken->getAccessToken(); + return $this->http->post($url, $this->mergeOptions($images, $options), [ 'base_uri' => self::BASEURL, ]); } /** - * @param mixed $images + * @param mixed $images */ public function mergeOptions($images, array $options): array { diff --git a/src/Requests/Request.php b/src/Requests/Request.php index 5968e23..683b087 100644 --- a/src/Requests/Request.php +++ b/src/Requests/Request.php @@ -39,7 +39,7 @@ abstract class Request implements RequestInterface /** * Auto regist http and container instance. * - * @param ContainerInterface $container + * @param ContainerInterface $container */ public function __construct(Http $http, ContainerInterface $app) { @@ -68,14 +68,13 @@ public function registerMiddlewares() /** * Register global http log middleware. * - * @param ContainerInterface $app - * + * @param ContainerInterface $app * @return callable */ protected function logMiddleware() { $driver = $this->app['config']->get('log.default'); - $config = $this->app['config']->get('log.channels.' . $driver); + $config = $this->app['config']->get('log.channels.'.$driver); $logger = $this->app['logger']; // because base64 image is very big, we just record request header if you not set formater in you log configurage. @@ -108,8 +107,7 @@ protected function init() /** * Translation $images and $options to guzzle http options. * - * @param mixed $images - * + * @param mixed $images * @return array */ abstract public function send($url, $images, array $options = []): ResponseInterface; @@ -137,8 +135,7 @@ public function getHttp() /** * Filter images to one. * - * @param mixed $images - * + * @param mixed $images * @return mixed */ protected function filterOneImage($images, $message = 'Only one image can be operated at a time.') diff --git a/src/Requests/TencentRequest.php b/src/Requests/TencentRequest.php index 5926d0e..5bc23e2 100644 --- a/src/Requests/TencentRequest.php +++ b/src/Requests/TencentRequest.php @@ -41,11 +41,6 @@ protected function init() /** * sdk default options. - * - * @param string $action - * @param string $region - * @param string $apiVersion - * @return array */ protected function requestOptions(string $action, string $region = '', string $apiVersion = '2018-11-19'): array { @@ -58,7 +53,7 @@ protected function requestOptions(string $action, string $region = '', string $a 'X-TC-Version' => $apiVersion, ]; - if (!empty($region)) { + if (! empty($region)) { $headers['X-TC-Region'] = $region; } @@ -94,8 +89,7 @@ protected function middlewares(): array /** * Format reqyest body. * - * @param mixed $images - * + * @param mixed $images * @return array */ protected function formatRequestBody($images, array $options = []) diff --git a/src/Support/Arr.php b/src/Support/Arr.php index 9cf1705..2172fe7 100644 --- a/src/Support/Arr.php +++ b/src/Support/Arr.php @@ -20,8 +20,7 @@ class Arr /** * Determine whether the given value is array accessible. * - * @param mixed $value - * + * @param mixed $value * @return bool */ public static function accessible($value) @@ -32,10 +31,9 @@ public static function accessible($value) /** * Add an element to an array using "dot" notation if it doesn't exist. * - * @param array $array - * @param string $key - * @param mixed $value - * + * @param array $array + * @param string $key + * @param mixed $value * @return array */ public static function add($array, $key, $value) @@ -50,8 +48,7 @@ public static function add($array, $key, $value) /** * Divide an array into two arrays. One with keys and the other with values. * - * @param array $array - * + * @param array $array * @return array */ public static function divide($array) @@ -62,9 +59,8 @@ public static function divide($array) /** * Get all of the given array except for a specified array of keys. * - * @param array $array - * @param array|string $keys - * + * @param array $array + * @param array|string $keys * @return array */ public static function except($array, $keys) @@ -77,9 +73,8 @@ public static function except($array, $keys) /** * Determine if the given key exists in the provided array. * - * @param \ArrayAccess|array $array - * @param string|int $key - * + * @param \ArrayAccess|array $array + * @param string|int $key * @return bool */ public static function exists($array, $key) @@ -94,10 +89,8 @@ public static function exists($array, $key) /** * Return the first element in an array passing a given truth test. * - * @param iterable $array - * @param callable|null $callback - * @param mixed $default - * + * @param iterable $array + * @param mixed $default * @return mixed */ public static function first($array, callable $callback = null, $default = null) @@ -124,10 +117,8 @@ public static function first($array, callable $callback = null, $default = null) /** * Return the last element in an array passing a given truth test. * - * @param array $array - * @param callable|null $callback - * @param mixed $default - * + * @param array $array + * @param mixed $default * @return mixed */ public static function last($array, callable $callback = null, $default = null) @@ -142,14 +133,14 @@ public static function last($array, callable $callback = null, $default = null) /** * Remove one or many array items from a given array using "dot" notation. * - * @param array $array - * @param array|string $keys + * @param array $array + * @param array|string $keys */ public static function forget(&$array, $keys) { $original = &$array; - $keys = (array)$keys; + $keys = (array) $keys; if (0 === count($keys)) { return; @@ -185,15 +176,14 @@ public static function forget(&$array, $keys) /** * Get an item from an array using "dot" notation. * - * @param \ArrayAccess|array $array - * @param string|int|null $key - * @param mixed $default - * + * @param \ArrayAccess|array $array + * @param string|int|null $key + * @param mixed $default * @return mixed */ public static function get($array, $key, $default = null) { - if (!static::accessible($array)) { + if (! static::accessible($array)) { return self::vvalue($default); } @@ -223,16 +213,15 @@ public static function get($array, $key, $default = null) /** * Check if an item or items exist in an array using "dot" notation. * - * @param \ArrayAccess|array $array - * @param string|array $keys - * + * @param \ArrayAccess|array $array + * @param string|array $keys * @return bool */ public static function has($array, $keys) { - $keys = (array)$keys; + $keys = (array) $keys; - if (!$array || $keys === []) { + if (! $array || $keys === []) { return false; } @@ -258,9 +247,8 @@ public static function has($array, $keys) /** * Determine if any of the keys exist in an array using "dot" notation. * - * @param \ArrayAccess|array $array - * @param string|array $keys - * + * @param \ArrayAccess|array $array + * @param string|array $keys * @return bool */ public static function hasAny($array, $keys) @@ -269,9 +257,9 @@ public static function hasAny($array, $keys) return false; } - $keys = (array)$keys; + $keys = (array) $keys; - if (!$array) { + if (! $array) { return false; } @@ -293,7 +281,6 @@ public static function hasAny($array, $keys) * * An array is "associative" if it doesn't have sequential numerical keys beginning with zero. * - * @param array $array * * @return bool */ @@ -307,23 +294,21 @@ public static function isAssoc(array $array) /** * Get a subset of the items from the given array. * - * @param array $array - * @param array|string $keys - * + * @param array $array + * @param array|string $keys * @return array */ public static function only($array, $keys) { - return array_intersect_key($array, array_flip((array)$keys)); + return array_intersect_key($array, array_flip((array) $keys)); } /** * Push an item onto the beginning of an array. * - * @param array $array - * @param mixed $value - * @param mixed $key - * + * @param array $array + * @param mixed $value + * @param mixed $key * @return array */ public static function prepend($array, $value, $key = null) @@ -340,10 +325,9 @@ public static function prepend($array, $value, $key = null) /** * Get a value from the array, and remove it. * - * @param array $array - * @param string $key - * @param mixed $default - * + * @param array $array + * @param string $key + * @param mixed $default * @return mixed */ public static function pull(&$array, $key, $default = null) @@ -358,9 +342,8 @@ public static function pull(&$array, $key, $default = null) /** * Get one or a specified number of random values from an array. * - * @param array $array - * @param int|null $number - * + * @param array $array + * @param int|null $number * @return mixed * * @throws \InvalidArgumentException @@ -381,7 +364,7 @@ public static function random($array, $number = null) return $array[array_rand($array)]; } - if (0 === (int)$number) { + if (0 === (int) $number) { return []; } @@ -389,7 +372,7 @@ public static function random($array, $number = null) $results = []; - foreach ((array)$keys as $key) { + foreach ((array) $keys as $key) { $results[] = $array[$key]; } @@ -401,10 +384,9 @@ public static function random($array, $number = null) * * If no key is given to the method, the entire array will be replaced. * - * @param array $array - * @param string|null $key - * @param mixed $value - * + * @param array $array + * @param string|null $key + * @param mixed $value * @return array */ public static function set(&$array, $key, $value) @@ -425,7 +407,7 @@ public static function set(&$array, $key, $value) // If the key doesn't exist at this depth, we will just create an empty array // to hold the next value, allowing us to create the arrays to hold final // values at the correct depth. Then we'll keep digging into the array. - if (!isset($array[$key]) || !is_array($array[$key])) { + if (! isset($array[$key]) || ! is_array($array[$key])) { $array[$key] = []; } @@ -440,9 +422,8 @@ public static function set(&$array, $key, $value) /** * Shuffle the given array and return the result. * - * @param array $array - * @param int|null $seed - * + * @param array $array + * @param int|null $seed * @return array */ public static function shuffle($array, $seed = null) @@ -461,8 +442,7 @@ public static function shuffle($array, $seed = null) /** * Recursively sort an array by keys and values. * - * @param array $array - * + * @param array $array * @return array */ public static function sortRecursive($array) @@ -485,8 +465,7 @@ public static function sortRecursive($array) /** * Convert the array into a query string. * - * @param array $array - * + * @param array $array * @return string */ public static function query($array) @@ -497,9 +476,7 @@ public static function query($array) /** * Filter the array using the given callback. * - * @param array $array - * @param callable $callback - * + * @param array $array * @return array */ public static function where($array, callable $callback) @@ -510,8 +487,7 @@ public static function where($array, callable $callback) /** * Rewrite value. * - * @param mixed|callable $value - * + * @param mixed|callable $value * @return mixed */ public static function vvalue($value) @@ -522,8 +498,7 @@ public static function vvalue($value) /** * If the given value is not an array and not null, wrap it in one. * - * @param mixed $value - * + * @param mixed $value * @return array */ public static function wrap($value) diff --git a/src/Support/BaiduAccessToken.php b/src/Support/BaiduAccessToken.php index 88eacd7..b414442 100644 --- a/src/Support/BaiduAccessToken.php +++ b/src/Support/BaiduAccessToken.php @@ -11,7 +11,6 @@ namespace Godruoyi\OCR\Support; use Psr\SimpleCache\CacheInterface; -use Psr\SimpleCache\InvalidArgumentException; use RuntimeException; class BaiduAccessToken diff --git a/src/Support/Encoder.php b/src/Support/Encoder.php index b1068b2..4db6822 100644 --- a/src/Support/Encoder.php +++ b/src/Support/Encoder.php @@ -33,7 +33,7 @@ public static function getCanonicalHeaders(array $headers) $v = null === $v ? '' : $v; - $headerStrings[] = strtolower(trim($k)) . ':' . strtolower(trim($v)); + $headerStrings[] = strtolower(trim($k)).':'.strtolower(trim($v)); } sort($headerStrings); diff --git a/src/Support/FileConverter.php b/src/Support/FileConverter.php index a634a31..d54ab4f 100644 --- a/src/Support/FileConverter.php +++ b/src/Support/FileConverter.php @@ -21,8 +21,7 @@ class FileConverter /** * Converter Image To String. * - * @param string|object|resource $image - * + * @param string|object|resource $image * @return string */ public static function toBase64Encode($image) @@ -37,8 +36,7 @@ public static function toBase64Encode($image) /** * Get image Content, support url/file/SplFileInfo. * - * @param string|\SplFileInfo|resource $image - * + * @param string|\SplFileInfo|resource $image * @return string */ public static function getContent($image) @@ -79,20 +77,18 @@ public static function getOnlineImageContent($url) /** * Determine the given file has a file. * - * @param mixed $file - * + * @param mixed $file * @return bool */ public static function isString($file) { - return is_string($file) && (!self::isUrl($file)); + return is_string($file) && (! self::isUrl($file)); } /** * Determine the given file has a active url. * - * @param mixed $file - * + * @param mixed $file * @return bool */ public static function isUrl($file) @@ -103,8 +99,7 @@ public static function isUrl($file) /** * Determine the given file has a active url. * - * @param mixed $file - * + * @param mixed $file * @return bool */ public static function isFile($file) @@ -115,8 +110,7 @@ public static function isFile($file) /** * Determine the given file has a image type. * - * @param mixed $file - * + * @param mixed $file * @return bool */ public static function isImage($file) @@ -131,8 +125,7 @@ public static function isImage($file) /** * Determine the given file has Rescouve stream. * - * @param mixed $resource - * + * @param mixed $resource * @return bool */ public static function isResource($resource) @@ -143,8 +136,7 @@ public static function isResource($resource) /** * Determine the given file has SplFileInfo instance. * - * @param mixed $splFile - * + * @param mixed $splFile * @return bool */ public static function isSplFileInfo($splFile) @@ -155,7 +147,6 @@ public static function isSplFileInfo($splFile) /** * Set http instance. * - * @param Http $http * @return void */ public static function setHttp(Http $http) diff --git a/src/Support/Http.php b/src/Support/Http.php index 00d097e..507d528 100644 --- a/src/Support/Http.php +++ b/src/Support/Http.php @@ -67,9 +67,8 @@ public function setHeaders(array $headers = []) /** * Send A Http Get Request. * - * @param string $url - * @param array $params - * + * @param string $url + * @param array $params * @return \Psr\Http\Message\ResponseInterface */ public function get($url, $params = [], array $options = []) @@ -80,9 +79,8 @@ public function get($url, $params = [], array $options = []) /** * Send A Http POST Request. * - * @param string $url - * @param array $params - * + * @param string $url + * @param array $params * @return \Psr\Http\Message\ResponseInterface */ public function post($url, $params = [], array $options = []) @@ -95,10 +93,9 @@ public function post($url, $params = [], array $options = []) /** * Send A Http Request For GuzzleHttp Http Client. * - * @param string $method - * @param string $url - * @param array $options - * + * @param string $method + * @param string $url + * @param array $options * @return \Psr\Http\Message\ResponseInterface */ public function request($method, $url, $options = []) @@ -124,11 +121,10 @@ public function request($method, $url, $options = []) /** * JSON request. * - * @param string $url - * @param string|array $data - * @param array $queries - * @param int $encodeOption - * + * @param string $url + * @param string|array $data + * @param array $queries + * @param int $encodeOption * @return ResponseInterface * * @throws HttpException @@ -174,7 +170,7 @@ public function customHttpHandler(callable $fu) */ public function getClient() { - if (empty($this->client) || !($this->client instanceof HttpClient)) { + if (empty($this->client) || ! ($this->client instanceof HttpClient)) { $this->client = new HttpClient(); } diff --git a/src/Support/Logger.php b/src/Support/Logger.php index 79b44b7..fba87e8 100644 --- a/src/Support/Logger.php +++ b/src/Support/Logger.php @@ -10,6 +10,7 @@ namespace Godruoyi\OCR\Support; +use function implode; use Monolog\Formatter\LineFormatter; use Monolog\Handler\ErrorLogHandler; use Monolog\Handler\HandlerInterface; @@ -19,6 +20,7 @@ use Monolog\Handler\SyslogHandler; use Monolog\Logger as Monolog; use Psr\Log\LoggerInterface; +use function sprintf; class Logger implements LoggerInterface { @@ -70,8 +72,7 @@ public function __construct(array $config = []) /** * Create a new, on-demand aggregate logger instance. * - * @param string|null $channel - * + * @param string|null $channel * @return \Psr\Log\LoggerInterface */ public function stack(array $channels, $channel = null) @@ -82,8 +83,7 @@ public function stack(array $channels, $channel = null) /** * Get a log channel instance. * - * @param string|null $channel - * + * @param string|null $channel * @return mixed */ public function channel($channel = null) @@ -94,8 +94,7 @@ public function channel($channel = null) /** * Get a log driver instance. * - * @param string|null $driver - * + * @param string|null $driver * @return mixed */ public function driver($driver = null) @@ -106,8 +105,7 @@ public function driver($driver = null) /** * Attempt to get the log from the local cache. * - * @param string $name - * + * @param string $name * @return \Psr\Log\LoggerInterface */ protected function get($name) @@ -132,8 +130,7 @@ protected function get($name) /** * Resolve the given log instance by name. * - * @param string $name - * + * @param string $name * @return \Psr\Log\LoggerInterface * * @throws \InvalidArgumentException @@ -142,23 +139,29 @@ protected function resolve($name) { $channels = Arr::get($this->config, 'channels', []); - if (empty($channels) || !isset($channels[$name])) { - throw new \InvalidArgumentException(\sprintf('Log [%s] is not defined.', $name)); + if (empty($channels) || ! isset($channels[$name])) { + throw new \InvalidArgumentException(sprintf('Log [%s] is not defined.', $name)); } $config = $channels[$name]; - if (isset($this->customCreators[$config['driver']])) { + if (isset($config['driver']) && isset($this->customCreators[$config['driver']])) { return $this->callCustomCreator($config); } - $driverMethod = 'create' . ucfirst($config['driver']) . 'Driver'; - - if (method_exists($this, $driverMethod)) { - return $this->{$driverMethod}($config); + $supportDrivers = ['stack', 'single', 'daily', 'slack', 'syslog', 'errorlog', 'monolog']; + if (! isset($config['driver']) || ! in_array($config['driver'], $supportDrivers)) { + throw new \InvalidArgumentException( + sprintf('Driver [%s] is not supported, only support [%s].', + $config['driver'] ?? '', + implode(',', $supportDrivers), + ) + ); } - throw new \InvalidArgumentException(\sprintf('Driver [%s] is not supported.', $config['driver'])); + $driverMethod = 'create'.ucfirst($config['driver']).'Driver'; + + return $this->{$driverMethod}($config); } /** @@ -169,7 +172,7 @@ protected function resolve($name) protected function createEmergencyLogger() { return new Monolog('OCR', $this->prepareHandlers([new StreamHandler( - \sys_get_temp_dir() . '/ocr.log', + \sys_get_temp_dir().'/ocr.log', $this->level(['level' => 'debug']) )])); } @@ -360,7 +363,7 @@ public function getDefaultDriver() /** * Set the default log driver name. * - * @param string $name + * @param string $name */ public function setDefaultDriver($name) { @@ -370,8 +373,7 @@ public function setDefaultDriver($name) /** * Register a custom driver creator Closure. * - * @param string $driver - * + * @param string $driver * @return $this */ public function extend($driver, \Closure $callback) @@ -384,13 +386,11 @@ public function extend($driver, \Closure $callback) /** * System is unusable. * - * @param string $message - * - * @return mixed + * @param string $message */ - public function emergency($message, array $context = []) + public function emergency($message, array $context = []): void { - return $this->driver()->emergency($message, $context); + $this->driver()->emergency($message, $context); } /** @@ -399,13 +399,11 @@ public function emergency($message, array $context = []) * Example: Entire website down, database unavailable, etc. This should * trigger the SMS alerts and wake you up. * - * @param string $message - * - * @return mixed + * @param string $message */ - public function alert($message, array $context = []) + public function alert($message, array $context = []): void { - return $this->driver()->alert($message, $context); + $this->driver()->alert($message, $context); } /** @@ -413,26 +411,22 @@ public function alert($message, array $context = []) * * Example: Application component unavailable, unexpected exception. * - * @param string $message - * - * @return mixed + * @param string $message */ - public function critical($message, array $context = []) + public function critical($message, array $context = []): void { - return $this->driver()->critical($message, $context); + $this->driver()->critical($message, $context); } /** * Runtime errors that do not require immediate action but should typically * be logged and monitored. * - * @param string $message - * - * @return mixed + * @param string $message */ - public function error($message, array $context = []) + public function error($message, array $context = []): void { - return $this->driver()->error($message, $context); + $this->driver()->error($message, $context); } /** @@ -441,25 +435,21 @@ public function error($message, array $context = []) * Example: Use of deprecated APIs, poor use of an API, undesirable things * that are not necessarily wrong. * - * @param string $message - * - * @return mixed + * @param string $message */ - public function warning($message, array $context = []) + public function warning($message, array $context = []): void { - return $this->driver()->warning($message, $context); + $this->driver()->warning($message, $context); } /** * Normal but significant events. * - * @param string $message - * - * @return mixed + * @param string $message */ - public function notice($message, array $context = []) + public function notice($message, array $context = []): void { - return $this->driver()->notice($message, $context); + $this->driver()->notice($message, $context); } /** @@ -467,46 +457,39 @@ public function notice($message, array $context = []) * * Example: User logs in, SQL logs. * - * @param string $message - * - * @return mixed + * @param string $message */ - public function info($message, array $context = []) + public function info($message, array $context = []): void { - return $this->driver()->info($message, $context); + $this->driver()->info($message, $context); } /** * Detailed debug information. * - * @param string $message - * - * @return mixed + * @param string $message */ - public function debug($message, array $context = []) + public function debug($message, array $context = []): void { - return $this->driver()->debug($message, $context); + $this->driver()->debug($message, $context); } /** * Logs with an arbitrary level. * - * @param mixed $level - * @param string $message - * - * @return mixed + * @param mixed $level + * @param string $message */ - public function log($level, $message, array $context = []) + public function log($level, $message, array $context = []): void { - return $this->driver()->log($level, $message, $context); + $this->driver()->log($level, $message, $context); } /** * Dynamically call the default driver instance. * - * @param string $method - * @param array $parameters - * + * @param string $method + * @param array $parameters * @return mixed */ public function __call($method, $parameters) diff --git a/src/Support/Macroable.php b/src/Support/Macroable.php index ca16fcd..f9ca652 100644 --- a/src/Support/Macroable.php +++ b/src/Support/Macroable.php @@ -27,8 +27,8 @@ trait Macroable /** * Register a custom macro. * - * @param string $name - * @param object|callable $macro + * @param string $name + * @param object|callable $macro */ public static function macro($name, $macro) { @@ -38,8 +38,8 @@ public static function macro($name, $macro) /** * Mix another object into the class. * - * @param object $mixin - * @param bool $replace + * @param object $mixin + * @param bool $replace * * @throws \ReflectionException */ @@ -50,7 +50,7 @@ public static function mixin($mixin, $replace = true) ); foreach ($methods as $method) { - if ($replace || !static::hasMacro($method->name)) { + if ($replace || ! static::hasMacro($method->name)) { $method->setAccessible(true); static::macro($method->name, $method->invoke($mixin)); } @@ -60,8 +60,7 @@ public static function mixin($mixin, $replace = true) /** * Checks if macro is registered. * - * @param string $name - * + * @param string $name * @return bool */ public static function hasMacro($name) @@ -72,16 +71,15 @@ public static function hasMacro($name) /** * Dynamically handle calls to the class. * - * @param string $method - * @param array $parameters - * + * @param string $method + * @param array $parameters * @return mixed * * @throws \BadMethodCallException */ public static function __callStatic($method, $parameters) { - if (!static::hasMacro($method)) { + if (! static::hasMacro($method)) { throw new BadMethodCallException(sprintf('Method %s::%s does not exist.', static::class, $method)); } @@ -97,16 +95,15 @@ public static function __callStatic($method, $parameters) /** * Dynamically handle calls to the class. * - * @param string $method - * @param array $parameters - * + * @param string $method + * @param array $parameters * @return mixed * * @throws \BadMethodCallException */ public function __call($method, $parameters) { - if (!static::hasMacro($method)) { + if (! static::hasMacro($method)) { throw new BadMethodCallException(sprintf('Method %s::%s does not exist.', static::class, $method)); } diff --git a/src/Support/Response.php b/src/Support/Response.php index 255dfae..a2ee4a8 100644 --- a/src/Support/Response.php +++ b/src/Support/Response.php @@ -11,6 +11,7 @@ namespace Godruoyi\OCR\Support; use GuzzleHttp\Psr7\Response as GuzzleHttpResponse; +use ReturnTypeWillChange; class Response extends GuzzleHttpResponse implements \ArrayAccess { @@ -28,7 +29,7 @@ public static function createFromGuzzleHttpResponse(GuzzleHttpResponse $response $response->getProtocolVersion(), $response->getReasonPhrase() ); - + $response->getBody()->rewind(); return $response; @@ -40,7 +41,7 @@ public static function createFromGuzzleHttpResponse(GuzzleHttpResponse $response public function toArray(): array { $this->getBody()->rewind(); - $body = (string)$this->getBody(); + $body = (string) $this->getBody(); if (empty($body)) { return []; @@ -64,11 +65,11 @@ public function toJson() { $this->getBody()->rewind(); - return (string)$this->getBody(); + return (string) $this->getBody(); } /** - * @param int $offset + * @param int $offset */ public function offsetExists($offset): bool { @@ -77,12 +78,8 @@ public function offsetExists($offset): bool return isset($item[$offset]); } - /** - * @param mixed $offset - * - * @return mixed - */ - public function offsetGet($offset) + #[ReturnTypeWillChange] + public function offsetGet(mixed $offset): mixed { $item = $this->toArray(); @@ -93,22 +90,11 @@ public function offsetGet($offset) return null; } - /** - * @param mixed $offset - * @param mixed $value - * - * @return mixed - */ - public function offsetSet($offset, $value): void + public function offsetSet(mixed $offset, mixed $value): void { } - /** - * @param mixed $offset - * - * @return mixed - */ - public function offsetUnset($offset): void + public function offsetUnset(mixed $offset): void { } } diff --git a/src/Support/TencentSignatureV3.php b/src/Support/TencentSignatureV3.php index a2e9695..bfab53f 100644 --- a/src/Support/TencentSignatureV3.php +++ b/src/Support/TencentSignatureV3.php @@ -41,7 +41,7 @@ class TencentSignatureV3 /** * Registe config. * - * @param array $configs + * @param array $configs */ public function __construct(string $secretId, string $secretKey) { @@ -77,11 +77,11 @@ public function canonicalRequest(RequestInterface $request) $signedHeaders = $this->getSignatureHeadersToString(); $hashedRequestPayload = $this->hashedRequestPayload($request->getBody()->getContents()); - return $httpRequestMethod . "\n" . - $canonicalURI . "\n" . - $canonicalQueryString . "\n" . - $canonicalHeaders . "\n\n" . - $signedHeaders . "\n" . + return $httpRequestMethod."\n". + $canonicalURI."\n". + $canonicalQueryString."\n". + $canonicalHeaders."\n\n". + $signedHeaders."\n". $hashedRequestPayload; } @@ -104,7 +104,7 @@ public function authorization(RequestInterface $request) $credentialScope = sprintf('%s/%s/%s', $date, $service, self::TC3_REQUEST); $str2sign = sprintf("%s\n%s\n%s\n%s", self::TC3_ALGORITHM, $xTcTimestamp, $credentialScope, hash('SHA256', $this->canonicalRequest($request))); - $dateKey = hash_hmac('SHA256', $date, 'TC3' . $this->secretKey, true); + $dateKey = hash_hmac('SHA256', $date, 'TC3'.$this->secretKey, true); $serviceKey = hash_hmac('SHA256', $service, $dateKey, true); $reqKey = hash_hmac('SHA256', self::TC3_REQUEST, $serviceKey, true); @@ -127,7 +127,7 @@ public function authorization(RequestInterface $request) */ public function getSignatureHeadersToString() { - return join(';', array_map(function ($h) { + return implode(';', array_map(function ($h) { return strtolower($h); }, $this->signatureHeaders)); } diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index 6e548a8..2c86eae 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -207,7 +207,7 @@ public function testCallMethod() $http = $this->mockHttpWithResponse(new Response(200, [], 'OK1'), $app['http']); $app['http'] = $http; - $this->assertSame('OK1', $this->application->aliyun->idcard(__DIR__ . '/stubs/common.png')->getBody()->getContents()); + $this->assertSame('OK1', $this->application->aliyun->idcard(__DIR__.'/stubs/common.png')->getBody()->getContents()); } public function testCallNotExistsDriver() @@ -224,7 +224,7 @@ public function testCallMethodWithDefault() $http = $this->mockHttpWithResponse(new Response(200, [], 'OK1'), $app['http']); $app['http'] = $http; - $this->assertSame('OK1', $this->application->idcard(__DIR__ . '/stubs/common.png')->getBody()->getContents()); + $this->assertSame('OK1', $this->application->idcard(__DIR__.'/stubs/common.png')->getBody()->getContents()); } public function testRebindCache() diff --git a/tests/Clients/AliyunClientTest.php b/tests/Clients/AliyunClientTest.php index 1a6b1f7..8866ce9 100644 --- a/tests/Clients/AliyunClientTest.php +++ b/tests/Clients/AliyunClientTest.php @@ -54,7 +54,7 @@ public function testBasic() $times = count($methods); $app = $this->application->getContainer(); $app->bind(AliyunRequest::class, function () use ($times) { - $mockRequest = Mockery::mock("Request, " . AliyunRequest::class); + $mockRequest = Mockery::mock('Request, '.AliyunRequest::class); $mockRequest->shouldReceive('send') ->times($times) ->andReturn(new Response(200, [], 'SUCCESS')); @@ -76,7 +76,7 @@ public function testManyImage() $app = $this->application->getContainer(); $app->bind(AliyunRequest::class, function ($app) { - $http = \Mockery::mock("http, " . Http::class); + $http = \Mockery::mock('http, '.Http::class); $http->shouldReceive('middlewares')->andReturn(null); $http->shouldReceive('json') ->once() @@ -85,12 +85,12 @@ public function testManyImage() && array_key_exists('image', $data) && array_key_exists('configure', $data); })) - ->andReturn(new \GuzzleHttp\Psr7\Response(200, [], "OK")); + ->andReturn(new \GuzzleHttp\Psr7\Response(200, [], 'OK')); return new AliyunRequest($http, $app); }); - $response = $this->application->aliyun->general([__DIR__ . '/../stubs/common.png', __DIR__ . '/stubs/common2.png', __DIR__ . '/stubs/common2.png']); + $response = $this->application->aliyun->general([__DIR__.'/../stubs/common.png', __DIR__.'/stubs/common2.png', __DIR__.'/stubs/common2.png']); $this->assertInstanceOf(ResponseInterface::class, $response); $this->assertSame('OK', $response->getBody()->getContents()); diff --git a/tests/Clients/BaiduClientTest.php b/tests/Clients/BaiduClientTest.php index 65017bc..4ff1ea7 100644 --- a/tests/Clients/BaiduClientTest.php +++ b/tests/Clients/BaiduClientTest.php @@ -79,7 +79,7 @@ public function testAllMethods() ]; $this->application->getContainer()->bind(BaiduRequest::class, function () use ($methods) { - $request = \Mockery::mock('Request, ' . BaiduRequest::class); + $request = \Mockery::mock('Request, '.BaiduRequest::class); $request->shouldReceive('send') ->times(count($methods)) ->andReturn(new Response(200, [], 'OK')); @@ -90,14 +90,14 @@ public function testAllMethods() if ($method == 'asynTableInfo') { $response = $this->application->baidu->$method('a', 'b'); } else { - $response = $this->application->baidu->$method(__DIR__ . '/../stubs/common.png', [ + $response = $this->application->baidu->$method(__DIR__.'/../stubs/common.png', [ 'language_type' => 'ENG', ]); } $this->assertInstanceOf(ResponseInterface::class, $response); $response->getBody()->rewind(); - $this->assertSame("OK", $response->getBody()->getContents()); + $this->assertSame('OK', $response->getBody()->getContents()); } } @@ -110,7 +110,7 @@ public function testGeneralBasic() ], $http); $this->application->getContainer()['http'] = $http; - $response = $this->application->baidu->generalBasic(__DIR__ . '/../stubs/common.png', [ + $response = $this->application->baidu->generalBasic(__DIR__.'/../stubs/common.png', [ 'language_type' => 'ENG', ]); diff --git a/tests/Clients/RealRequestClientTest.php b/tests/Clients/RealRequestClientTest.php index 9f7abda..0eb18f1 100644 --- a/tests/Clients/RealRequestClientTest.php +++ b/tests/Clients/RealRequestClientTest.php @@ -18,18 +18,21 @@ class RealRequestClientTest extends TestCase public function testFireRealAliyunRequest() { $d = $this->application->aliyun; - $response = $d->ugc(__DIR__ . '/../stubs/common.png', []); + $response = $d->ugc(__DIR__.'/../stubs/common.png', []); $this->assertInstanceOf(Response::class, $response); // If we get 403 error, it can be only that our quota is exhausted. if ($response->getStatusCode() == 403) { - $this->assertSame("Api Market Subscription quota exhausted", $response->getHeader('X-Ca-Error-Message')); + $error = $response->getHeader('X-Ca-Error-Message'); + if (isset($error[0]) && str_contains($error[0], 'quota')) { + $this->markTestSkipped('Aliyun quota exhausted.'); + } + return; } $this->assertSame(200, $response->getStatusCode()); - $json = json_decode($response->getBody()->getContents(), true); $this->assertSame(JSON_ERROR_NONE, json_last_error()); $this->assertIsArray($json); @@ -38,7 +41,7 @@ public function testFireRealAliyunRequest() public function testFireRealBaiduRequest() { $d = $this->application->baidu; - $response = $d->businessCard(__DIR__ . '/../stubs/common.png', []); + $response = $d->businessCard(__DIR__.'/../stubs/common.png', []); $this->assertInstanceOf(Response::class, $response); $this->assertSame(200, $response->getStatusCode()); @@ -49,7 +52,7 @@ public function testFireRealBaiduRequest() public function testFireRealTencentRequest() { $d = $this->application->tencent; - $response = $d->generalBasic(__DIR__ . '/../stubs/common.png', [ + $response = $d->generalBasic(__DIR__.'/../stubs/common.png', [ 'Region' => 'ap-guangzhou', ]); diff --git a/tests/Clients/TencentClientTest.php b/tests/Clients/TencentClientTest.php index 411917c..7bbcf6d 100644 --- a/tests/Clients/TencentClientTest.php +++ b/tests/Clients/TencentClientTest.php @@ -94,21 +94,22 @@ public function testAllMethod() ]; $this->application->getContainer()->bind(TencentRequest::class, function () use ($methods) { - $request = \Mockery::mock('Request, ' . TencentRequest::class); + $request = \Mockery::mock('Request, '.TencentRequest::class); $request->shouldReceive('send') ->times(count($methods)) ->andReturn(new Response(200, [], 'OK')); + return $request; }); foreach ($methods as $method) { - $response = $this->application->tencent->$method(__DIR__ . '/../stubs/common.png', [ - 'Region' => 'ap-shanghai' + $response = $this->application->tencent->$method(__DIR__.'/../stubs/common.png', [ + 'Region' => 'ap-shanghai', ]); $this->assertInstanceOf(ResponseInterface::class, $response); $response->getBody()->rewind(); - $this->assertSame("OK", $response->getBody()->getContents()); + $this->assertSame('OK', $response->getBody()->getContents()); } } } diff --git a/tests/Custom/HuaweiClient.php b/tests/Custom/HuaweiClient.php index efb6ab1..5bff78f 100644 --- a/tests/Custom/HuaweiClient.php +++ b/tests/Custom/HuaweiClient.php @@ -26,10 +26,8 @@ public function idcard($url, $images, array $options = []): ResponseInterface /** * Fire a ocr http request. * - * @param string $url - * @param mixed $images - * @param array $options - * @return ResponseInterface + * @param string $url + * @param mixed $images */ public function request($url, $images, array $options = []): ResponseInterface { diff --git a/tests/CustomServiceProvider.php b/tests/CustomServiceProvider.php index 488c361..151d669 100644 --- a/tests/CustomServiceProvider.php +++ b/tests/CustomServiceProvider.php @@ -26,7 +26,7 @@ class CustomServiceProvider implements ServiceProviderInterface * This method should only be used to configure services and parameters. * It should not get services. * - * @param ContainerInterface $container A container instance + * @param ContainerInterface $container A container instance */ public function register(ContainerInterface $container) { diff --git a/tests/Requests/AliyunRequestTest.php b/tests/Requests/AliyunRequestTest.php index b98fd2e..b6c5c5f 100644 --- a/tests/Requests/AliyunRequestTest.php +++ b/tests/Requests/AliyunRequestTest.php @@ -36,7 +36,7 @@ public function testBasicSend() $http = $this->mockHttpWithResponse($this->createSuccessResponse()); $request = new AliyunRequest($http, $app->getContainer()); - $response = $request->send('url', __DIR__ . '/../stubs/common.png'); + $response = $request->send('url', __DIR__.'/../stubs/common.png'); $this->assertInstanceOf(ResponseInterface::class, $response); $this->assertSame('OK', $response->getBody()->getContents()); @@ -60,7 +60,7 @@ public function testBasicSendEnableLog() $http = $this->mockHttpWithResponse($this->createSuccessResponse()); $request = new AliyunRequest($http, $app->getContainer()); - $response = $request->send('url', __DIR__ . '/../stubs/common.png'); + $response = $request->send('url', __DIR__.'/../stubs/common.png'); $this->assertInstanceOf(ResponseInterface::class, $response); $response->getBody()->rewind(); @@ -86,7 +86,7 @@ public function testCanNotUseSecretIDAndSecret() $this->expectException(Exception::class); $this->expectExceptionMessage('Aliyun AppKey and AppSecret has not be completed'); - $request->send('url', __DIR__ . '/../stubs/common.png'); + $request->send('url', __DIR__.'/../stubs/common.png'); } public function testUseAppCode() @@ -103,7 +103,7 @@ public function testUseAppCode() $request = new AliyunRequest($app->getContainer()['http'], $app->getContainer()); $this->mockHttpWithResponseAndHistory($request->getHttp(), $this->createSuccessResponse(), $histories); - $response = $request->send('url', __DIR__ . '/../stubs/common.png'); + $response = $request->send('url', __DIR__.'/../stubs/common.png'); $this->assertSame('APPCODE appcode', $histories[0]['request']->getHeaderLine('Authorization')); $this->assertSame('OK', $response->getBody()->getContents()); @@ -146,12 +146,13 @@ public function testFormatInputs() $http->shouldReceive('json') ->withArgs(function ($url, $options) { $image = $options['inputs'][0]['image']['dataValue']; - return $url == 'url' && is_string($image) && !empty($image); + + return $url == 'url' && is_string($image) && ! empty($image); }) ->andReturn(new Response(200, [], 'OK')); $request = new AliyunRequest($http, $this->application->getContainer()); - $response = $request->send('url', [__DIR__ . '/../stubs/common.png']); + $response = $request->send('url', [__DIR__.'/../stubs/common.png']); $this->assertSame('OK', $response->getBody()->getContents()); } @@ -162,12 +163,13 @@ public function testFormatBasic() $http->shouldReceive('json') ->withArgs(function ($url, $options) { $image = $options['image']; - return $url == 'url' && is_string($image) && !empty($image); + + return $url == 'url' && is_string($image) && ! empty($image); }) ->andReturn(new Response(200, [], 'OK')); $request = new AliyunRequest($http, $this->application->getContainer()); - $response = $request->send('url', [__DIR__ . '/../stubs/common.png'], ['_format' => 'basic']); + $response = $request->send('url', [__DIR__.'/../stubs/common.png'], ['_format' => 'basic']); $this->assertSame('OK', $response->getBody()->getContents()); } @@ -199,7 +201,7 @@ public function testFormatImgOrUrl() $http->shouldReceive('json') ->withArgs(function ($url, $options) { - return $url == 'url' && is_string($options['img']) && !empty($options['img']); + return $url == 'url' && is_string($options['img']) && ! empty($options['img']); }) ->once() ->andReturn(new Response(200, [], 'OK')); @@ -209,7 +211,7 @@ public function testFormatImgOrUrl() $response = $request->send('url', ['https://example.com'], ['_format' => 'imgorurl']); $this->assertSame('OK', $response->getBody()->getContents()); - $response = $request->send('url', [__DIR__ . '/../stubs/common.png'], ['_format' => 'imgorurl']); + $response = $request->send('url', [__DIR__.'/../stubs/common.png'], ['_format' => 'imgorurl']); $this->assertSame('OK', $response->getBody()->getContents()); } } diff --git a/tests/Requests/BaseRequestTest.php b/tests/Requests/BaseRequestTest.php index 0d7485a..26ca673 100644 --- a/tests/Requests/BaseRequestTest.php +++ b/tests/Requests/BaseRequestTest.php @@ -81,7 +81,7 @@ public function testSupportOnlineInamge() $accessToken = new BaiduAccessToken( $http, - new Psr16Cache(new FilesystemAdapter(time() . '_' . uniqid())), // set random cache dir + new Psr16Cache(new FilesystemAdapter(time().'_'.uniqid())), // set random cache dir 'access_key', 'secret_key' ); diff --git a/tests/Support/ArrTest.php b/tests/Support/ArrTest.php index 462ae4b..4f58753 100644 --- a/tests/Support/ArrTest.php +++ b/tests/Support/ArrTest.php @@ -70,7 +70,6 @@ public function testFirst() $this->assertSame('default', Arr::first([], null, 'default')); $this->assertSame('bar', Arr::first($array, null, 'default')); - $this->assertSame('bar', Arr::first($array, function ($v, $k) { return $k === 'foo'; })); diff --git a/tests/Support/BaiduAccessTokenTest.php b/tests/Support/BaiduAccessTokenTest.php index 53f9f27..7fc25b5 100644 --- a/tests/Support/BaiduAccessTokenTest.php +++ b/tests/Support/BaiduAccessTokenTest.php @@ -32,7 +32,7 @@ public function testGetAccessToken() $token = new BaiduAccessToken( $http, - new Psr16Cache(new FilesystemAdapter(time() . '_' . uniqid())), + new Psr16Cache(new FilesystemAdapter(time().'_'.uniqid())), 'secretID', 'secretKey' ); @@ -54,7 +54,7 @@ public function testGetAccessTokenFail() $token = new BaiduAccessToken( $http, - new Psr16Cache(new FilesystemAdapter(time() . '_' . uniqid())), + new Psr16Cache(new FilesystemAdapter(time().'_'.uniqid())), 'secretID', 'secretKey' ); diff --git a/tests/Support/FileConverterTest.php b/tests/Support/FileConverterTest.php index cb901da..ea14ed3 100644 --- a/tests/Support/FileConverterTest.php +++ b/tests/Support/FileConverterTest.php @@ -46,12 +46,12 @@ public function testGetContent() ], [ 'name' => 'test isResource', - 'file' => @fopen(__DIR__ . '/../stubs/config.php', 'r'), + 'file' => @fopen(__DIR__.'/../stubs/config.php', 'r'), ], [ 'name' => 'test isSplFileInfo', - 'file' => new SplFileInfo(__DIR__ . '/../stubs/config.php'), - ] + 'file' => new SplFileInfo(__DIR__.'/../stubs/config.php'), + ], ]; foreach ($tests as $t) { @@ -86,7 +86,7 @@ public function testIsImage() public function testIsSplFileInfo() { - $this->assertTrue(FileConverter::isSplFileInfo(new SplFileInfo(__DIR__ . '/../stubs/config.php'))); + $this->assertTrue(FileConverter::isSplFileInfo(new SplFileInfo(__DIR__.'/../stubs/config.php'))); } public function testGetOnlineImageContent() @@ -100,7 +100,7 @@ public function testGetOnlineImageContent() public function testIsFile() { - $this->assertTrue(FileConverter::isFile(__DIR__ . '/../stubs/config.php')); + $this->assertTrue(FileConverter::isFile(__DIR__.'/../stubs/config.php')); } public function testToBase64Encode() diff --git a/tests/TestCase.php b/tests/TestCase.php index 809f0cc..18e511a 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -30,7 +30,7 @@ class TestCase extends BaseTestCase */ protected function setUp(): void { - $this->config = require __DIR__ . '/stubs/config.php'; + $this->config = require __DIR__.'/stubs/config.php'; $this->application = new Application($this->config); } @@ -56,7 +56,7 @@ protected function mockHttpWithResponseAndHistory($http, $response, &$container protected function mockHttpWithResponse($response, $http = null): Http { - if (!$http) { + if (! $http) { $http = new Http(); } @@ -74,7 +74,7 @@ protected function createSuccessResponse(): GuzzleResponse protected function mockeryHttp() { - $http = Mockery::mock('HTTP, ' . Http::class); + $http = Mockery::mock('HTTP, '.Http::class); $http->shouldReceive('middlewares') ->andReturnNull(); diff --git a/tests/stubs/config.php b/tests/stubs/config.php index 09f8955..488e006 100644 --- a/tests/stubs/config.php +++ b/tests/stubs/config.php @@ -61,7 +61,7 @@ 'daily' => [ 'name' => 'OCR', 'driver' => 'daily', - 'path' => __DIR__ . '/ocr.log', + 'path' => __DIR__.'/ocr.log', 'level' => 'debug', 'days' => 14, ],