GetTaxCodePlugin::assembly()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 20
rs 9.9
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\V3\Marketing\Fapiao\Blockchain;
6
7
use Closure;
8
use Yansongda\Artful\Contract\PluginInterface;
9
use Yansongda\Artful\Exception\InvalidParamsException;
10
use Yansongda\Artful\Logger;
11
use Yansongda\Artful\Rocket;
12
use Yansongda\Pay\Exception\Exception;
13
14
/**
15
 * @see https://pay.weixin.qq.com/docs/merchant/apis/fapiao/fapiao-merchant/list-merchant-tax-codes.html
16
 */
17
class GetTaxCodePlugin implements PluginInterface
18
{
19
    /**
20
     * @throws InvalidParamsException
21
     */
22
    public function assembly(Rocket $rocket, Closure $next): Rocket
23
    {
24
        Logger::debug('[Wechat][V3][Marketing][Fapiao][Blockchain][GetTaxCodePlugin] 插件开始装载', ['rocket' => $rocket]);
25
26
        $payload = $rocket->getPayload();
27
        $offset = $payload?->get('offset') ?? null;
28
        $limit = $payload?->get('limit') ?? null;
29
30
        if (empty($offset) || empty($limit)) {
31
            throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 获取商户可开具的商品和服务税收分类编码对照表,缺少 `offset` 或 `limit` 参数');
32
        }
33
34
        $rocket->setPayload([
35
            '_method' => 'GET',
36
            '_url' => 'v3/new-tax-control-fapiao/merchant/tax-codes?offset='.$offset.'&limit='.$limit,
37
        ]);
38
39
        Logger::info('[Wechat][V3][Marketing][Fapiao][Blockchain][GetTaxCodePlugin] 插件装载完毕', ['rocket' => $rocket]);
40
41
        return $next($rocket);
42
    }
43
}
44