Completed
Pull Request — master (#7)
by frey
03:41 queued 50s
created

Batch   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 77
Duplicated Lines 35.06 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 27
loc 77
rs 10
wmc 4
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A batchSyncUser() 9 9 1
A batchReplaceUser() 9 9 1
A batchReplaceParty() 9 9 1
A getResult() 0 8 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 EntWeChat\User;
4
5
use EntWeChat\Core\AbstractAPI;
6
7
class Batch extends AbstractAPI
8
{
9
    const API_SYNC_USER = 'https://qyapi.weixin.qq.com/cgi-bin/batch/syncuser';
10
    const API_REPLACE_USER = 'https://qyapi.weixin.qq.com/cgi-bin/batch/replaceuser';
11
    const API_REPLACE_PARTY = 'https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty';
12
    const API_GET_RESULT = 'https://qyapi.weixin.qq.com/cgi-bin/batch/getresult';
13
14
    /**
15
     * Batch sync user.
16
     *
17
     * @param       $mediaId
18
     * @param array $callback
19
     *
20
     * @return \EntWeChat\Support\Collection
21
     */
22 View Code Duplication
    public function batchSyncUser($mediaId, $callback = [])
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...
23
    {
24
        $params = [
25
            'media_id' => $mediaId,
26
            'callback' => $callback,
27
        ];
28
29
        return $this->parseJSON('json', [self::API_SYNC_USER, $params]);
30
    }
31
32
    /**
33
     * Batch replace user.
34
     *
35
     * @param       $mediaId
36
     * @param array $callback
37
     *
38
     * @return \EntWeChat\Support\Collection
39
     */
40 View Code Duplication
    public function batchReplaceUser($mediaId, $callback = [])
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...
41
    {
42
        $params = [
43
            'media_id' => $mediaId,
44
            'callback' => $callback,
45
        ];
46
47
        return $this->parseJSON('json', [self::API_REPLACE_USER, $params]);
48
    }
49
50
    /**
51
     * Batch replace party.
52
     *
53
     * @param       $mediaId
54
     * @param array $callback
55
     *
56
     * @return \EntWeChat\Support\Collection
57
     */
58 View Code Duplication
    public function batchReplaceParty($mediaId, $callback = [])
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...
59
    {
60
        $params = [
61
            'media_id' => $mediaId,
62
            'callback' => $callback,
63
        ];
64
65
        return $this->parseJSON('json', [self::API_REPLACE_PARTY, $params]);
66
    }
67
68
    /**
69
     * Get result.
70
     *
71
     * @param $jobId
72
     *
73
     * @return \EntWeChat\Support\Collection
74
     */
75
    public function getResult($jobId)
76
    {
77
        $params = [
78
            'jobid' => $jobId,
79
        ];
80
81
        return $this->parseJSON('get', [self::API_GET_RESULT, $params]);
82
    }
83
}
84