Completed
Push — master ( 8f5b55...c52b56 )
by frey
04:17 queued 01:50
created

BaseApi   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 108
Duplicated Lines 26.85 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 29
loc 108
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAuthorizerInfo() 10 10 1
A getAuthorizationInfo() 9 9 2
A setAuthorizerOption() 0 9 1
A getAuthorizerToken() 10 10 1
A getProviderToken() 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
namespace EntWeChat\Suite\Api;
4
5
class BaseApi extends AbstractSuite
6
{
7
    /**
8
     * Get auth info api.
9
     */
10
    const GET_AUTH_INFO = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_auth_info';
11
12
    /**
13
     * Get permanent token api.
14
     */
15
    const GET_PERMANENT_TOKEN = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_permanent_code';
16
17
    /**
18
     * Set session info api.
19
     */
20
    const SET_SESSION_INFO = 'https://qyapi.weixin.qq.com/cgi-bin/service/set_session_info';
21
22
    /**
23
     * Get corp token api.
24
     */
25
    const GET_CORP_TOKEN = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_corp_token';
26
27
    /**
28
     * Get provider token api.
29
     */
30
    const GET_PROVIDER_TOKEN = 'https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token';
31
32
    /**
33
     * @param $authorizerCorpId
34
     * @param $permanentCode
35
     *
36
     * @return \EntWeChat\Support\Collection
37
     */
38 View Code Duplication
    public function getAuthorizerInfo($authorizerCorpId, $permanentCode)
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...
39
    {
40
        $params = [
41
            'suite_id'       => $this->getSuiteId(),
42
            'auth_corpid'    => $authorizerCorpId,
43
            'permanent_code' => $permanentCode,
44
        ];
45
46
        return $this->parseJSON('json', [self::GET_AUTH_INFO, $params]);
47
    }
48
49
    /**
50
     * @param null $authCode
51
     *
52
     * @return \EntWeChat\Support\Collection
53
     */
54 View Code Duplication
    public function getAuthorizationInfo($authCode = 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...
55
    {
56
        $params = [
57
            'suite_id'  => $this->getSuiteId(),
58
            'auth_code' => $authCode ?: $this->request->get('auth_code'),
59
        ];
60
61
        return $this->parseJSON('json', [self::GET_PERMANENT_TOKEN, $params]);
62
    }
63
64
    /**
65
     * @param $preAuthCode
66
     * @param $sessionInfo
67
     *
68
     * @return \EntWeChat\Support\Collection
69
     */
70
    public function setAuthorizerOption($preAuthCode, $sessionInfo)
71
    {
72
        $params = [
73
            'pre_auth_code' => $preAuthCode,
74
            'session_info'  => $sessionInfo,
75
        ];
76
77
        return $this->parseJSON('json', [self::SET_SESSION_INFO, $params]);
78
    }
79
80
    /**
81
     * @param $authorizerCorpId
82
     * @param $permanentCode
83
     *
84
     * @return \EntWeChat\Support\Collection
85
     */
86 View Code Duplication
    public function getAuthorizerToken($authorizerCorpId, $permanentCode)
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...
87
    {
88
        $params = [
89
            'suite_id'       => $this->getSuiteId(),
90
            'auth_corpid'    => $authorizerCorpId,
91
            'permanent_code' => $permanentCode,
92
        ];
93
94
        return $this->parseJSON('json', [self::GET_CORP_TOKEN, $params]);
95
    }
96
97
    /**
98
     * @param $providerCorpId
99
     * @param $providerSecret
100
     *
101
     * @return \EntWeChat\Support\Collection
102
     */
103
    public function getProviderToken($providerCorpId, $providerSecret)
104
    {
105
        $params = [
106
            'corpid'          => $providerCorpId,
107
            'provider_secret' => $providerSecret,
108
        ];
109
110
        return $this->parseJSON('json', [self::GET_PROVIDER_TOKEN, $params]);
111
    }
112
}
113