Completed
Push — master ( ba17f6...fee6ef )
by Carlos
06:54 queued 03:35
created

Tag   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 137
Duplicated Lines 18.98 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 26
loc 137
rs 10
ccs 32
cts 32
cp 1
wmc 8
lcom 1
cbo 1

8 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 8 8 1
A lists() 0 4 1
A update() 0 11 1
A delete() 0 8 1
A userTags() 0 6 1
A usersOfTag() 0 6 1
A batchTagUsers() 9 9 1
A batchUntagUsers() 9 9 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
/**
13
 * Group.php.
14
 *
15
 * @author    overtrue <[email protected]>
16
 * @copyright 2015 overtrue <[email protected]>
17
 *
18
 * @link      https://github.com/overtrue
19
 * @link      http://overtrue.me
20
 */
21
namespace EasyWeChat\User;
22
23
use EasyWeChat\Core\AbstractAPI;
24
25
/**
26
 * Class Tag.
27
 */
28
class Tag extends AbstractAPI
29
{
30
    const API_GET = 'https://api.weixin.qq.com/cgi-bin/tags/get';
31
    const API_CREATE = 'https://api.weixin.qq.com/cgi-bin/tags/create';
32
    const API_UPDATE = 'https://api.weixin.qq.com/cgi-bin/tags/update';
33
    const API_DELETE = 'https://api.weixin.qq.com/cgi-bin/tags/delete';
34
    const API_USER_TAGS = 'https://api.weixin.qq.com/cgi-bin/tags/getidlist';
35
    const API_MEMBER_BATCH_TAG = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging';
36
    const API_MEMBER_BATCH_UNTAG = 'https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging';
37
    const API_USERS_OF_TAG = 'https://api.weixin.qq.com/cgi-bin/user/tag/get';
38
39
    /**
40
     * Create tag.
41
     *
42
     * @param string $name
43
     *
44
     * @return int
45
     */
46 1 View Code Duplication
    public function create($name)
47
    {
48
        $params = [
49 1
                   'tag' => ['name' => $name],
50 1
                  ];
51
52 1
        return $this->parseJSON('json', [self::API_CREATE, $params]);
53
    }
54
55
    /**
56
     * List all tags.
57
     *
58
     * @return array
59
     */
60 1
    public function lists()
61
    {
62 1
        return $this->parseJSON('get', [self::API_GET]);
63
    }
64
65
    /**
66
     * Update a tag name.
67
     *
68
     * @param int    $tagId
69
     * @param string $name
70
     *
71
     * @return bool
72
     */
73 1
    public function update($tagId, $name)
74
    {
75
        $params = [
76
                   'tag' => [
77 1
                               'id' => $tagId,
78 1
                               'name' => $name,
79 1
                              ],
80 1
                  ];
81
82 1
        return $this->parseJSON('json', [self::API_UPDATE, $params]);
83
    }
84
85
    /**
86
     * Delete tag.
87
     *
88
     * @param int $tagId
89
     *
90
     * @return bool
91
     */
92 1
    public function delete($tagId)
93
    {
94
        $params = [
95 1
                   'tag' => ['id' => $tagId],
96 1
                  ];
97
98 1
        return $this->parseJSON('json', [self::API_DELETE, $params]);
99
    }
100
101
    /**
102
     * Get user tags.
103
     *
104
     * @param string $openId
105
     *
106
     * @return int
107
     */
108 1
    public function userTags($openId)
109
    {
110 1
        $params = ['openid' => $openId];
111
112 1
        return $this->parseJSON('json', [self::API_USER_TAGS, $params]);
113
    }
114
115
    /**
116
     * Get users from a tag.
117
     *
118
     * @param string $openId
0 ignored issues
show
Bug introduced by
There is no parameter named $openId. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
119
     *
120
     * @return int
121
     */
122 1
    public function usersOfTag($tagId)
123
    {
124 1
        $params = ['tagid' => $tagId];
125
126 1
        return $this->parseJSON('json', [self::API_USERS_OF_TAG, $params]);
127
    }
128
129
    /**
130
     * Batch tag users.
131
     *
132
     * @param array $openIds
133
     * @param int   $tagid
0 ignored issues
show
Bug introduced by
There is no parameter named $tagid. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
134
     *
135
     * @return bool
136
     */
137 1 View Code Duplication
    public function batchTagUsers(array $openIds, $tagId)
138
    {
139
        $params = [
140 1
                   'openid_list' => $openIds,
141 1
                   'tagid' => $tagId,
142 1
                  ];
143
144 1
        return $this->parseJSON('json', [self::API_MEMBER_BATCH_TAG, $params]);
145
    }
146
147
    /**
148
     * Untag users from a tag.
149
     *
150
     * @param array $openIds
151
     * @param int   $tagid
0 ignored issues
show
Bug introduced by
There is no parameter named $tagid. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
152
     *
153
     * @return bool
154
     */
155 1 View Code Duplication
    public function batchUntagUsers(array $openIds, $tagId)
156
    {
157
        $params = [
158 1
                   'openid_list' => $openIds,
159 1
                   'tagid' => $tagId,
160 1
                  ];
161
162 1
        return $this->parseJSON('json', [self::API_MEMBER_BATCH_UNTAG, $params]);
163
    }
164
}
165