Test Setup Failed
Push — master ( d37a6a...512c0e )
by Carlos
03:19
created

Authorizer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 121
Duplicated Lines 33.06 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 40
loc 121
rs 10
c 1
b 0
f 0
ccs 0
cts 44
cp 0
wmc 6
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAuthorizationInfo() 0 9 2
A getAuthorizationToken() 10 10 1
A getAuthorizerInfo() 9 9 1
A getAuthorizerOption() 10 10 1
A setAuthorizerOption() 11 11 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
 * Authorizer.php.
14
 *
15
 * Part of Overtrue\WeChat.
16
 *
17
 * For the full copyright and license information, please view the LICENSE
18
 * file that was distributed with this source code.
19
 *
20
 * @author    mingyoung <[email protected]>
21
 * @author    lixiao <[email protected]>
22
 * @copyright 2016
23
 *
24
 * @see      https://github.com/overtrue
25
 * @see      http://overtrue.me
26
 */
27
28
namespace EasyWeChat\OpenPlatform\Components;
29
30
class Authorizer extends AbstractComponent
31
{
32
    /**
33
     * Get auth info api.
34
     */
35
    const GET_AUTH_INFO = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth';
36
37
    /**
38
     * Authorization token api.
39
     */
40
    const GET_AUTHORIZER_TOKEN = 'https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token';
41
42
    /**
43
     * Get authorizer info api.
44
     */
45
    const GET_AUTHORIZER_INFO = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info';
46
47
    /**
48
     * Get authorizer options api.
49
     */
50
    const GET_AUTHORIZER_OPTION = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option';
51
52
    /**
53
     * Set authorizer options api.
54
     */
55
    const SET_AUTHORIZER_OPTION = 'https://api.weixin.qq.com/cgi-bin/component/api_set_authorizer_option';
56
57
    /**
58
     * Get authorization info.
59
     *
60
     * @param $authCode
61
     *
62
     * @return \EasyWeChat\Support\Collection
63
     */
64
    public function getAuthorizationInfo($authCode = null)
65
    {
66
        $data = [
67
            'component_appid' => $this->getAppId(),
68
            'authorization_code' => $authCode ?: $this->request->get('auth_code'),
69
        ];
70
71
        return $this->parseJSON('json', [self::GET_AUTH_INFO, $data]);
72
    }
73
74
    /**
75
     * Get authorization token.
76
     *
77
     * @param $authorizerAppId
78
     * @param $authorizerRefreshToken
79
     *
80
     * @return \EasyWeChat\Support\Collection
81
     */
82 View Code Duplication
    public function getAuthorizationToken($authorizerAppId, $authorizerRefreshToken)
83
    {
84
        $data = [
85
            'component_appid' => $this->getAppId(),
86
            'authorizer_appid' => $authorizerAppId,
87
            'authorizer_refresh_token' => $authorizerRefreshToken,
88
        ];
89
90
        return $this->parseJSON('json', [self::GET_AUTHORIZER_TOKEN, $data]);
91
    }
92
93
    /**
94
     * Get authorizer info.
95
     *
96
     * @param $authorizerAppId
97
     *
98
     * @return \EasyWeChat\Support\Collection
99
     */
100 View Code Duplication
    public function getAuthorizerInfo($authorizerAppId)
101
    {
102
        $data = [
103
            'component_appid' => $this->getAppId(),
104
            'authorizer_appid' => $authorizerAppId,
105
        ];
106
107
        return $this->parseJSON('json', [self::GET_AUTHORIZER_INFO, $data]);
108
    }
109
110
    /**
111
     * Get options.
112
     *
113
     * @param $authorizerAppId
114
     * @param $optionName
115
     *
116
     * @return \EasyWeChat\Support\Collection
117
     */
118 View Code Duplication
    public function getAuthorizerOption($authorizerAppId, $optionName)
119
    {
120
        $data = [
121
            'component_appid' => $this->getAppId(),
122
            'authorizer_appid' => $authorizerAppId,
123
            'option_name' => $optionName,
124
        ];
125
126
        return $this->parseJSON('json', [self::GET_AUTHORIZER_OPTION, $data]);
127
    }
128
129
    /**
130
     * Set authorizer option.
131
     *
132
     * @param $authorizerAppId
133
     * @param $optionName
134
     * @param $optionValue
135
     *
136
     * @return \EasyWeChat\Support\Collection
137
     */
138 View Code Duplication
    public function setAuthorizerOption($authorizerAppId, $optionName, $optionValue)
139
    {
140
        $data = [
141
            'component_appid' => $this->getAppId(),
142
            'authorizer_appid' => $authorizerAppId,
143
            'option_name' => $optionName,
144
            'option_value' => $optionValue,
145
        ];
146
147
        return $this->parseJSON('json', [self::SET_AUTHORIZER_OPTION, $data]);
148
    }
149
150
}
151