Gateway   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 9.76 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 8
loc 82
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
pay() 0 1 ?
A find() 8 8 2
getTradeType() 0 1 ?
A preOrder() 0 8 1

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\Wechat;
4
5
use Yansongda\Pay\Contracts\GatewayInterface;
6
use Yansongda\Pay\Events;
7
use Yansongda\Pay\Exceptions\GatewayException;
8
use Yansongda\Pay\Exceptions\InvalidArgumentException;
9
use Yansongda\Pay\Exceptions\InvalidSignException;
10
use Yansongda\Supports\Collection;
11
12
abstract class Gateway implements GatewayInterface
13
{
14
    /**
15
     * Mode.
16
     *
17
     * @var string
18
     */
19
    protected $mode;
20
21
    /**
22
     * Bootstrap.
23
     *
24
     * @author yansongda <[email protected]>
25
     *
26
     * @throws InvalidArgumentException
27
     */
28
    public function __construct()
29
    {
30
        $this->mode = Support::getInstance()->mode;
31
    }
32
33
    /**
34
     * Pay an order.
35
     *
36
     * @author yansongda <[email protected]>
37
     *
38
     * @param string $endpoint
39
     * @param array  $payload
40
     *
41
     * @return Collection
42
     */
43
    abstract public function pay($endpoint, array $payload);
44
45
    /**
46
     * Find.
47
     *
48
     * @author yansongda <[email protected]>
49
     *
50
     * @param string|array $order
51
     *
52
     * @return array
53
     */
54 View Code Duplication
    public function find($order): array
0 ignored issues
show
Duplication introduced by shaoyu
This method 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...
55
    {
56
        return [
57
            'endpoint' => 'pay/orderquery',
58
            'order' => is_array($order) ? $order : ['out_trade_no' => $order],
59
            'cert' => false,
60
        ];
61
    }
62
63
    /**
64
     * Get trade type config.
65
     *
66
     * @author yansongda <[email protected]>
67
     *
68
     * @return string
69
     */
70
    abstract protected function getTradeType();
71
72
    /**
73
     * Schedule an order.
74
     *
75
     * @author yansongda <[email protected]>
76
     *
77
     * @param array $payload
78
     *
79
     * @throws GatewayException
80
     * @throws InvalidArgumentException
81
     * @throws InvalidSignException
82
     *
83
     * @return Collection
84
     */
85
    protected function preOrder($payload): Collection
86
    {
87
        $payload['sign'] = Support::generateSign($payload);
88
89
        Events::dispatch(new Events\MethodCalled('Wechat', 'PreOrder', '', $payload));
90
91
        return Support::requestApi('pay/unifiedorder', $payload);
92
    }
93
}
94