Completed
Push — master ( 8a4b9b...6f1f97 )
by Songda
02:44 queued 01:20
created

GroupRedpackGateway   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 12.9 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A pay() 0 22 2
A getTradeType() 0 4 1
A find() 8 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\Events;
6
use Yansongda\Pay\Exceptions\GatewayException;
7
use Yansongda\Pay\Exceptions\InvalidArgumentException;
8
use Yansongda\Pay\Exceptions\InvalidSignException;
9
use Yansongda\Pay\Gateways\Wechat;
10
use Yansongda\Supports\Collection;
11
12
class GroupRedpackGateway extends Gateway
13
{
14
    /**
15
     * Pay an order.
16
     *
17
     * @author yansongda <[email protected]>
18
     *
19
     * @param string $endpoint
20
     *
21
     * @throws GatewayException
22
     * @throws InvalidArgumentException
23
     * @throws InvalidSignException
24
     */
25
    public function pay($endpoint, array $payload): Collection
26
    {
27
        $payload['wxappid'] = $payload['appid'];
28
        $payload['amt_type'] = 'ALL_RAND';
29
30
        if (Wechat::MODE_SERVICE === $this->mode) {
31
            $payload['msgappid'] = $payload['appid'];
32
        }
33
34
        unset($payload['appid'], $payload['trade_type'],
35
              $payload['notify_url'], $payload['spbill_create_ip']);
36
37
        $payload['sign'] = Support::generateSign($payload);
38
39
        Events::dispatch(new Events\PayStarted('Wechat', 'Group Redpack', $endpoint, $payload));
40
41
        return Support::requestApi(
42
            'mmpaymkttransfers/sendgroupredpack',
43
            $payload,
44
            true
45
        );
46
    }
47
48
    /**
49
     * Find.
50
     *
51
     * @author yansongda <[email protected]>
52
     *
53
     * @param $billno
54
     */
55 View Code Duplication
    public function find($billno): array
0 ignored issues
show
Duplication introduced by
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...
56
    {
57
        return [
58
            'endpoint' => 'mmpaymkttransfers/gethbinfo',
59
            'order' => ['mch_billno' => $billno, 'bill_type' => 'MCHT'],
60
            'cert' => true,
61
        ];
62
    }
63
64
    /**
65
     * Get trade type config.
66
     *
67
     * @author yansongda <[email protected]>
68
     */
69
    protected function getTradeType(): string
70
    {
71
        return '';
72
    }
73
}
74