Passed
Pull Request — master (#753)
by Songda
02:05 queued 20s
created

GeneralV2Plugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A doSomething() 0 10 1
A getHeaders() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Plugin\Wechat;
6
7
use function Yansongda\Pay\get_wechat_config;
8
9
use Yansongda\Pay\Rocket;
10
11
abstract class GeneralV2Plugin extends GeneralPlugin
12
{
13
    protected function getHeaders(): array
14
    {
15
        return [
16
            'Content-Type' => 'application/xml',
17
            'User-Agent' => 'yansongda/pay-v3',
18
        ];
19
    }
20
21
    /**
22
     * @throws \Yansongda\Pay\Exception\ContainerException
23
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
24
     */
25
    protected function doSomething(Rocket $rocket): void
26
    {
27
        $config = get_wechat_config($rocket->getParams());
28
        $configKey = $this->getConfigKey($rocket->getParams());
29
30
        $rocket->mergeParams(['_version' => 'v2']);
31
32
        $rocket->mergePayload([
33
            'appid' => $config[$configKey] ?? '',
34
            'mch_id' => $config['mch_id'] ?? '',
35
        ]);
36
    }
37
38
    abstract protected function getUri(Rocket $rocket): string;
39
}
40