Passed
Pull Request — master (#547)
by Songda
03:06
created

loadAlipayServiceProvider()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 8
c 0
b 0
f 0
dl 0
loc 13
rs 10
cc 3
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yansongda\Pay\Traits;
6
7
use Yansongda\Pay\Pay;
8
use Yansongda\Pay\Rocket;
9
10
trait SupportServiceProviderTrait
11
{
12
    /**
13
     * @throws \Yansongda\Pay\Exception\ContainerDependencyException
14
     * @throws \Yansongda\Pay\Exception\ContainerException
15
     * @throws \Yansongda\Pay\Exception\ServiceNotFoundException
16
     */
17
    protected function loadAlipayServiceProvider(Rocket $rocket): void
18
    {
19
        $params = $rocket->getParams();
20
        $config = get_alipay_config($params);
21
        $serviceProviderId = $config->get('service_provider_id');
22
23
        if (Pay::MODE_SERVICE !== $config->get('mode', Pay::MODE_NORMAL) ||
24
            empty($serviceProviderId)) {
25
            return;
26
        }
27
28
        $rocket->mergeParams([
29
            'extend_params' => array_merge($params['extend_params'] ?? [], ['sys_service_provider_id' => $serviceProviderId]),
30
        ]);
31
    }
32
}
33