UserApi   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 90
Duplicated Lines 15.56 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 1
dl 14
loc 90
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getUserMsg() 0 11 1
A getUserList() 14 14 2
A getUserOpenidList() 0 10 1
A setUserRemark() 0 11 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
namespace Wechat\API;
3
4
/**
5
 * 微信用户相关接口.
6
 *
7
 * @author Tian.
8
 */
9
class UserApi extends BaseApi
10
{
11
    /**
12
     * 获取用户信息.
13
     *
14
     * @author Tian
15
     *
16
     * @param string $openid 用户openid
17
     * @param string $lang
18
     *
19
     * @return array 用户信息.
20
     */
21
    public function getUserMsg($openid, $lang = 'zh_CN')
22
    {
23
        $queryStr = [
24
            'openid' => $openid,
25
            'lang'   => $lang,
26
        ];
27
28
        $res = $this->_get('info', $queryStr);
29
30
        return $res;
31
    }
32
33
    /**
34
     * 批量获取用户基本信息.
35
     *
36
     * @author Tian
37
     *
38
     * @param  array $user_list 用户openid列表
39
     *
40
     * @return array|bool 用户信息.
41
     */
42 View Code Duplication
    public function getUserList(array $user_list)
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...
43
    {
44
        if (!is_array($user_list)) {
45
            $this->setError('参数必须为一个数组');
46
47
            return false;
48
        }
49
50
        $this->module = 'user';
51
52
        $res = $this->_post('info/batchget', $user_list);
53
54
        return $res;
55
    }
56
57
    /**
58
     * 获取用户Openid列表.
59
     *
60
     * @author Tian
61
     *
62
     * @param string $next_openid 下一个openid
63
     *
64
     * @return array Openid列表.
65
     */
66
    public function getUserOpenidList($next_openid = '')
67
    {
68
        $queryStr = [
69
            'next_openid' => $next_openid,
70
        ];
71
72
        $res = $this->_get('get', $queryStr);
73
74
        return $res;
75
    }
76
77
    /**
78
     *  设置用户备注名.
79
     *
80
     * @author Tian
81
     *
82
     * @param string $openid 用户openid  sting
83
     * @param string $remark 用户备注名,长度必须小于30字符
84
     *
85
     * @return string bool.
86
     */
87
    public function setUserRemark($openid, $remark = "")
88
    {
89
        $queryStr = [
90
            'openid' => $openid,
91
            'remark' => $remark,
92
        ];
93
94
        $res = $this->_post('info/updateremark', $queryStr);
95
96
        return $res;
97
    }
98
}
99