Passed
Push — master ( 1dfbea...9713c0 )
by Songda
02:53 queued 51s
created

CallbackPlugin::formatPayload()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Unipay;
6
7
use Closure;
8
use Yansongda\Pay\Contract\PluginInterface;
9
use Yansongda\Pay\Direction\NoHttpRequestDirection;
10
use Yansongda\Pay\Exception\ContainerException;
11
use Yansongda\Pay\Exception\InvalidConfigException;
12
use Yansongda\Pay\Exception\InvalidSignException;
13
use Yansongda\Pay\Exception\ServiceNotFoundException;
14
use Yansongda\Pay\Logger;
15
use Yansongda\Pay\Rocket;
16
17
use function Yansongda\Pay\filter_params;
18
use function Yansongda\Pay\get_unipay_config;
19
use function Yansongda\Pay\verify_unipay_sign;
20
21
class CallbackPlugin implements PluginInterface
22
{
23
    /**
24
     * @throws ContainerException
25
     * @throws InvalidConfigException
26
     * @throws InvalidSignException
27
     * @throws ServiceNotFoundException
28
     */
29
    public function assembly(Rocket $rocket, Closure $next): Rocket
30
    {
31
        Logger::debug('[Unipay][CallbackPlugin] 插件开始装载', ['rocket' => $rocket]);
32
33
        $params = $rocket->getParams();
34
        $config = get_unipay_config($params);
35
36
        $rocket->setPayload(filter_params($params, fn ($k, $v) => 'signature' != $k));
0 ignored issues
show
Unused Code introduced by
The parameter $v is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

36
        $rocket->setPayload(filter_params($params, fn ($k, /** @scrutinizer ignore-unused */ $v) => 'signature' != $k));

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
38
        verify_unipay_sign($config, $rocket->getPayload()->sortKeys()->toString(), $params['signature'] ?? '', $params['signPubKeyCert'] ?? null);
39
40
        $rocket->setDirection(NoHttpRequestDirection::class)
41
            ->setDestination($rocket->getPayload());
42
43
        Logger::info('[Unipay][CallbackPlugin] 插件装载完毕', ['rocket' => $rocket]);
44
45
        return $next($rocket);
46
    }
47
}
48