Completed
Pull Request — master (#972)
by mingyoung
04:37
created

Client   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
Duplicated Lines 16.98 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 9
loc 53
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A info() 9 9 1
A sendNormal() 0 10 1
A sendGroup() 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
/*
4
 * This file is part of the overtrue/wechat.
5
 *
6
 * (c) overtrue <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace EasyWeChat\Payment\Redpack;
13
14
use EasyWeChat\Kernel\Support;
15
use EasyWeChat\Payment\Kernel\BaseClient;
16
17
/**
18
 * Class Client.
19
 *
20
 * @author tianyong90 <[email protected]>
21
 */
22
class Client extends BaseClient
23
{
24
    /**
25
     * Query redpack.
26
     *
27
     * @param array $params
28
     *
29
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
30
     */
31 View Code Duplication
    public function info(array $params)
32
    {
33
        $base = [
34
            'appid' => $this->app['config']->app_id,
35
            'bill_type' => 'MCHT',
36
        ];
37
38
        return $this->safeRequest('mmpaymkttransfers/gethbinfo', array_merge($base, $params));
39
    }
40
41
    /**
42
     * Send normal redpack.
43
     *
44
     * @param array $params
45
     *
46
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
47
     */
48
    public function sendNormal(array $params)
49
    {
50
        $base = [
51
            'total_num' => 1,
52
            'client_ip' => $params['client_ip'] ?? Support\get_server_ip(),
53
            'wxappid' => $this->app['config']->app_id,
54
        ];
55
56
        return $this->safeRequest('mmpaymkttransfers/sendredpack', array_merge($base, $params));
57
    }
58
59
    /**
60
     * Send group redpack.
61
     *
62
     * @param array $params
63
     *
64
     * @return \Psr\Http\Message\ResponseInterface|\EasyWeChat\Kernel\Support\Collection|array|object|string
65
     */
66
    public function sendGroup(array $params)
67
    {
68
        $base = [
69
            'amt_type' => 'ALL_RAND',
70
        ];
71
72
        return $this->safeRequest('mmpaymkttransfers/sendgroupredpack', array_merge($base, $params));
73
    }
74
}
75