Passed
Push — master ( e73c8b...2ea20b )
by Songda
04:10 queued 02:00
created

AddRadarPlugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 32
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A assembly() 0 18 1
A getHeaders() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Douyin\V1\Pay;
6
7
use Closure;
8
use GuzzleHttp\Psr7\Request;
9
use Yansongda\Artful\Contract\PluginInterface;
10
use Yansongda\Artful\Exception\ContainerException;
11
use Yansongda\Artful\Exception\InvalidParamsException;
12
use Yansongda\Artful\Exception\ServiceNotFoundException;
13
use Yansongda\Artful\Logger;
14
use Yansongda\Artful\Rocket;
15
16
use function Yansongda\Artful\get_radar_body;
17
use function Yansongda\Artful\get_radar_method;
18
use function Yansongda\Pay\get_douyin_url;
19
use function Yansongda\Pay\get_provider_config;
20
21
class AddRadarPlugin implements PluginInterface
22
{
23
    /**
24
     * @throws ContainerException
25
     * @throws InvalidParamsException
26
     * @throws ServiceNotFoundException
27
     */
28
    public function assembly(Rocket $rocket, Closure $next): Rocket
29
    {
30
        Logger::debug('[Douyin][V1][Pay][AddRadarPlugin] 插件开始装载', ['rocket' => $rocket]);
31
32
        $params = $rocket->getParams();
33
        $payload = $rocket->getPayload();
34
        $config = get_provider_config('douyin', $params);
35
36
        $rocket->setRadar(new Request(
37
            get_radar_method($payload),
0 ignored issues
show
Bug introduced by
It seems like get_radar_method($payload) can also be of type null; however, parameter $method of GuzzleHttp\Psr7\Request::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

37
            /** @scrutinizer ignore-type */ get_radar_method($payload),
Loading history...
38
            get_douyin_url($config, $payload),
39
            $this->getHeaders(),
40
            get_radar_body($payload),
41
        ));
42
43
        Logger::info('[Douyin][V1][Pay][AddRadarPlugin] 插件装载完毕', ['rocket' => $rocket]);
44
45
        return $next($rocket);
46
    }
47
48
    protected function getHeaders(): array
49
    {
50
        return [
51
            'User-Agent' => 'yansongda/pay-v3',
52
            'Content-Type' => 'application/json; charset=utf-8',
53
        ];
54
    }
55
}
56