Passed
Pull Request — master (#927)
by Songda
02:20
created

QueryUserTitlePlugin::assembly()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 18
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat\V3\Marketing\Fapiao;
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
use function Yansongda\Artful\filter_params;
15
16
/**
17
 * @see https://pay.weixin.qq.com/docs/merchant/apis/fapiao/user-title/get-user-title.html
18
 */
19
class QueryUserTitlePlugin implements PluginInterface
20
{
21
    /**
22
     * @throws InvalidParamsException
23
     */
24
    public function assembly(Rocket $rocket, Closure $next): Rocket
25
    {
26
        Logger::debug('[Wechat][V3][Marketing][Fapiao][QueryUserTitlePlugin] 插件开始装载', ['rocket' => $rocket]);
27
28
        $payload = $rocket->getPayload();
29
30
        if (empty($payload)) {
31
            throw new InvalidParamsException(Exception::PARAMS_NECESSARY_PARAMS_MISSING, '参数异常: 获取用户填写的抬头,缺少必要参数');
32
        }
33
34
        $rocket->setPayload([
35
            '_method' => 'GET',
36
            '_url' => 'v3/new-tax-control-fapiao/user-title?'.filter_params($payload)->query(),
37
        ]);
38
39
        Logger::info('[Wechat][V3][Marketing][Fapiao][QueryUserTitlePlugin] 插件装载完毕', ['rocket' => $rocket]);
40
41
        return $next($rocket);
42
    }
43
}
44