Tag   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 126
Duplicated Lines 36.51 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 46
loc 126
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 9 9 1
A lists() 0 4 1
A update() 9 9 1
A delete() 8 8 1
A usersOfTag() 0 6 1
A batchTagUsers() 10 10 1
A batchUntagUsers() 10 10 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 YEntWeChat\User;
4
5
use YEntWeChat\Core\AbstractAPI;
6
7
/**
8
 * Class Tag.
9
 */
10
class Tag extends AbstractAPI
11
{
12
    const API_GET = 'https://qyapi.weixin.qq.com/cgi-bin/tag/list';
13
    const API_CREATE = 'https://qyapi.weixin.qq.com/cgi-bin/tag/create';
14
    const API_UPDATE = 'https://qyapi.weixin.qq.com/cgi-bin/tag/update';
15
    const API_DELETE = 'https://qyapi.weixin.qq.com/cgi-bin/tag/delete';
16
    const API_MEMBER_BATCH_TAG = 'https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers';
17
    const API_MEMBER_BATCH_UNTAG = 'https://qyapi.weixin.qq.com/cgi-bin/tag/deltagusers';
18
    const API_USERS_OF_TAG = 'https://qyapi.weixin.qq.com/cgi-bin/tag/get';
19
20
    /**
21
     * Create tag.
22
     *
23
     * @param string $name
24
     * @param null   $tagI
0 ignored issues
show
Bug introduced by
There is no parameter named $tagI. 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...
25
     *
26
     * @return int
27
     */
28 View Code Duplication
    public function create($name, $tagId = null)
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...
29
    {
30
        $params = [
31
            'tagname' => $name,
32
            'tagid'   => $tagId,
33
        ];
34
35
        return $this->parseJSON('json', [self::API_CREATE, $params]);
36
    }
37
38
    /**
39
     * List all tags.
40
     *
41
     * @return array
42
     */
43
    public function lists()
44
    {
45
        return $this->parseJSON('get', [self::API_GET]);
46
    }
47
48
    /**
49
     * Update a tag name.
50
     *
51
     * @param int    $tagId
52
     * @param string $name
53
     *
54
     * @return bool
55
     */
56 View Code Duplication
    public function update($tagId, $name)
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...
57
    {
58
        $params = [
59
            'tagid'   => $tagId,
60
            'tagname' => $name,
61
        ];
62
63
        return $this->parseJSON('json', [self::API_UPDATE, $params]);
64
    }
65
66
    /**
67
     * Delete tag.
68
     *
69
     * @param int $tagId
70
     *
71
     * @return bool
72
     */
73 View Code Duplication
    public function delete($tagId)
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...
74
    {
75
        $params = [
76
            'tagid' => $tagId,
77
        ];
78
79
        return $this->parseJSON('json', [self::API_DELETE, $params]);
80
    }
81
82
    /**
83
     * Get users from a tag.
84
     *
85
     * @param string $tagId
86
     *
87
     * @return int
88
     */
89
    public function usersOfTag($tagId)
90
    {
91
        $params = ['tagid' => $tagId];
92
93
        return $this->parseJSON('json', [self::API_USERS_OF_TAG, $params]);
94
    }
95
96
    /**
97
     * Batch tag users.
98
     *
99
     * @param       $tagId
100
     * @param array $userIds
101
     * @param array $partyIds
102
     *
103
     * @return bool
104
     */
105 View Code Duplication
    public function batchTagUsers($tagId, array $userIds = [], array $partyIds = [])
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...
106
    {
107
        $params = [
108
            'tagid'     => $tagId,
109
            'userlist'  => $userIds,
110
            'partylist' => $partyIds,
111
        ];
112
113
        return $this->parseJSON('json', [self::API_MEMBER_BATCH_TAG, $params]);
114
    }
115
116
    /**
117
     * Untag users from a tag.
118
     *
119
     * @param       $tagId
120
     * @param array $userIds
121
     * @param array $partyIds
122
     *
123
     * @return bool
124
     */
125 View Code Duplication
    public function batchUntagUsers($tagId, array $userIds = [], array $partyIds = [])
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...
126
    {
127
        $params = [
128
            'tagid'     => $tagId,
129
            'userlist'  => $userIds,
130
            'partylist' => $partyIds,
131
        ];
132
133
        return $this->parseJSON('json', [self::API_MEMBER_BATCH_UNTAG, $params]);
134
    }
135
}
136