Completed
Push — master ( 058da3...8d02ae )
by Carlos
05:22 queued 02:18
created

Group   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 134
Duplicated Lines 12.69 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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