ScanGateway   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 32
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A pay() 14 14 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Yansongda\Pay\Gateways\Alipay;
4
5
use Yansongda\Pay\Events;
6
use Yansongda\Pay\Exceptions\GatewayException;
7
use Yansongda\Pay\Exceptions\InvalidArgumentException;
8
use Yansongda\Pay\Exceptions\InvalidConfigException;
9
use Yansongda\Pay\Exceptions\InvalidSignException;
10
use Yansongda\Pay\Gateways\Alipay;
11
use Yansongda\Supports\Collection;
12
13 View Code Duplication
class ScanGateway extends Gateway
0 ignored issues
show
Duplication introduced by yansongda
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * Pay an order.
17
     *
18
     * @author yansongda <[email protected]>
19
     *
20
     * @param string $endpoint
21
     * @param array  $payload
22
     *
23
     * @throws GatewayException
24
     * @throws InvalidArgumentException
25
     * @throws InvalidConfigException
26
     * @throws InvalidSignException
27
     *
28
     * @return Collection
29
     */
30
    public function pay($endpoint, array $payload): Collection
31
    {
32
        $payload['method'] = 'alipay.trade.precreate';
33
        $biz_array = json_decode($payload['biz_content'], true);
34
        if ((Alipay::MODE_SERVICE === $this->mode) && (!empty(Support::getInstance()->pid))) {
35
            $biz_array['extend_params'] = is_array($biz_array['extend_params']) ? array_merge(['sys_service_provider_id' => Support::getInstance()->pid], $biz_array['extend_params']) : ['sys_service_provider_id' => Support::getInstance()->pid];
36
        }
37
        $payload['biz_content'] = json_encode(array_merge($biz_array, ['product_code' => '']));
38
        $payload['sign'] = Support::generateSign($payload);
39
40
        Events::dispatch(new Events\PayStarted('Alipay', 'Scan', $endpoint, $payload));
41
42
        return Support::requestApi($payload);
43
    }
44
}
45