Passed
Push — master ( d1dcd3...a849c7 )
by Songda
01:59
created

VerifySignaturePlugin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 8
dl 0
loc 26
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A assembly() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat;
6
7
use Closure;
8
use Yansongda\Pay\Contract\PluginInterface;
9
use Yansongda\Pay\Exception\ContainerException;
10
use Yansongda\Pay\Exception\DecryptException;
11
use Yansongda\Pay\Exception\InvalidConfigException;
12
use Yansongda\Pay\Exception\InvalidParamsException;
13
use Yansongda\Pay\Exception\InvalidSignException;
14
use Yansongda\Pay\Exception\ServiceNotFoundException;
15
use Yansongda\Pay\Logger;
16
use Yansongda\Pay\Rocket;
17
18
use function Yansongda\Pay\should_do_http_request;
19
use function Yansongda\Pay\verify_wechat_sign;
20
21
class VerifySignaturePlugin implements PluginInterface
22
{
23
    /**
24
     * @throws ContainerException
25
     * @throws InvalidConfigException
26
     * @throws InvalidSignException
27
     * @throws ServiceNotFoundException
28
     * @throws DecryptException
29
     * @throws InvalidParamsException
30
     */
31
    public function assembly(Rocket $rocket, Closure $next): Rocket
32
    {
33
        /* @var Rocket $rocket */
34
        $rocket = $next($rocket);
35
36
        Logger::debug('[Wechat][VerifySignaturePlugin] 插件开始装载', ['rocket' => $rocket]);
37
38
        if (!should_do_http_request($rocket->getDirection()) || is_null($rocket->getDestinationOrigin())) {
39
            return $rocket;
40
        }
41
42
        verify_wechat_sign($rocket->getDestinationOrigin(), $rocket->getParams());
43
44
        Logger::info('[Wechat][VerifySignaturePlugin] 插件装载完毕', ['rocket' => $rocket]);
45
46
        return $rocket;
47
    }
48
}
49