Completed
Pull Request — master (#546)
by
unknown
05:32
created

Group   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 134
Duplicated Lines 12.69 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 8 8 1
A update() 9 9 1
A delete() 0 8 1
A lists() 0 9 1
A getDetails() 0 10 1
A addDevice() 0 9 1
A removeDevice() 0 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    allen05ren <[email protected]>
16
 * @copyright 2016 overtrue <[email protected]>
17
 *
18
 * @link      https://github.com/overtrue
19
 * @link      http://overtrue.me
20
 */
21
namespace EasyWeChat\ShakeAround;
22
23
use EasyWeChat\Core\AbstractAPI;
24
25
/**
26
 * Class Group.
27
 */
28
class Group extends AbstractAPI
29
{
30
    const API_ADD = 'https://api.weixin.qq.com/shakearound/device/group/add';
31
    const API_UPDATE = 'https://api.weixin.qq.com/shakearound/device/group/update';
32
    const API_DELETE = 'https://api.weixin.qq.com/shakearound/device/group/delete';
33
    const API_GET_LIST = 'https://api.weixin.qq.com/shakearound/device/group/getlist';
34
    const API_GET_DETAIL = 'https://api.weixin.qq.com/shakearound/device/group/getdetail';
35
    const API_ADD_DEVICE = 'https://api.weixin.qq.com/shakearound/device/group/adddevice';
36
    const API_DELETE_DEVICE = 'https://api.weixin.qq.com/shakearound/device/group/deletedevice';
37
38
    /**
39
     * Add device group.
40
     *
41
     * @param string $name
42
     *
43
     * @return \EasyWeChat\Support\Collection
44
     */
45 View Code Duplication
    public function add($name)
46
    {
47
        $params = [
48
            'group_name' => $name,
49
        ];
50
51
        return $this->parseJSON('json', [self::API_ADD, $params]);
52
    }
53
54
    /**
55
     * Update a device group name.
56
     *
57
     * @param int    $groupId
58
     * @param string $name
59
     *
60
     * @return \EasyWeChat\Support\Collection
61
     */
62 View Code Duplication
    public function update($groupId, $name)
63
    {
64
        $params = [
65
            'group_id' => intval($groupId),
66
            'group_name' => $name,
67
        ];
68
69
        return $this->parseJSON('json', [self::API_UPDATE, $params]);
70
    }
71
72
    /**
73
     * Delete device group.
74
     *
75
     * @param int $groupId
76
     *
77
     * @return \EasyWeChat\Support\Collection
78
     */
79
    public function delete($groupId)
80
    {
81
        $params = [
82
            'group_id' => intval($groupId),
83
        ];
84
85
        return $this->parseJSON('json', [self::API_DELETE, $params]);
86
    }
87
88
    /**
89
     * List all device groups.
90
     *
91
     * @param int $begin
92
     * @param int $count
93
     *
94
     * @return \EasyWeChat\Support\Collection
95
     */
96
    public function lists($begin, $count)
97
    {
98
        $params = [
99
            'begin' => intval($begin),
100
            'count' => intval($count),
101
        ];
102
103
        return $this->parseJSON('json', [self::API_GET_LIST, $params]);
104
    }
105
106
    /**
107
     * Get details of a device group.
108
     *
109
     * @param int $groupId
110
     * @param int $begin
111
     * @param int $count
112
     *
113
     * @return \EasyWeChat\Support\Collection
114
     */
115
    public function getDetails($groupId, $begin, $count)
116
    {
117
        $params = [
118
            'group_id' => intval($groupId),
119
            'begin' => intval($begin),
120
            'count' => intval($count),
121
        ];
122
123
        return $this->parseJSON('json', [self::API_GET_DETAIL, $params]);
124
    }
125
126
    /**
127
     * Add  one or more devices to a device group.
128
     *
129
     * @param int   $groupId
130
     * @param array $device_identifiers
131
     *
132
     * @return \EasyWeChat\Support\Collection
133
     */
134
    public function addDevice($groupId, array $device_identifiers)
135
    {
136
        $params = [
137
            'group_id' => intval($groupId),
138
            'device_identifiers' => $device_identifiers,
139
        ];
140
141
        return $this->parseJSON('json', [self::API_ADD_DEVICE, $params]);
142
    }
143
144
    /**
145
     * Remove one or more devices from a device group.
146
     *
147
     * @param int   $groupId
148
     * @param array $device_identifiers
149
     *
150
     * @return \EasyWeChat\Support\Collection
151
     */
152
    public function removeDevice($groupId, array $device_identifiers)
153
    {
154
        $params = [
155
            'group_id' => intval($groupId),
156
            'device_identifiers' => $device_identifiers,
157
        ];
158
159
        return $this->parseJSON('json', [self::API_DELETE_DEVICE, $params]);
160
    }
161
}
162