Passed
Push — master ( 273c7d...4c8747 )
by ma
02:37
created
src/Gateways/Naver.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             'scope'         => $this->config['scope'],
40 40
             'state'         => $this->config['state'] ?: Str::random(),
41 41
         ];
42
-        return $this->AuthorizeURL . '?' . http_build_query($params);
42
+        return $this->AuthorizeURL.'?'.http_build_query($params);
43 43
     }
44 44
 
45 45
     /**
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
      */
77 77
     public function getUserInfo()
78 78
     {
79
-        if($this->type == 'app'){//App登录
80
-            if(!isset($_REQUEST['access_token']) ){
79
+        if ($this->type == 'app') {//App登录
80
+            if (!isset($_REQUEST['access_token'])) {
81 81
                 throw new OAuthException("Naver APP登录 需要传输access_token参数! ");
82 82
             }
83 83
             $this->token['token_type'] = 'Bearer';
84 84
             $this->token['access_token'] = $_REQUEST['access_token'];
85
-        }else {
85
+        } else {
86 86
             $this->getToken();
87 87
         }
88 88
         $data = $this->call('nid/me', $this->token, 'GET');
@@ -105,10 +105,10 @@  discard block
 block discarded – undo
105 105
         $method  = strtoupper($method);
106 106
         $request = [
107 107
             'method' => $method,
108
-            'uri'    => self::API_BASE . $api,
108
+            'uri'    => self::API_BASE.$api,
109 109
         ];
110 110
 
111
-        $headers = ['Authorization' => $this->token['token_type'] . ' ' . $this->token['access_token']];
111
+        $headers = ['Authorization' => $this->token['token_type'].' '.$this->token['access_token']];
112 112
 
113 113
         $data = $this->$method($request['uri'], $params, $headers);
114 114
 
Please login to merge, or discard this patch.
src/Gateways/Coding.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             'scope'         => $this->config['scope'],
40 40
             'state'         => $this->config['state'],
41 41
         ];
42
-        return $this->AuthorizeURL . '?' . http_build_query($params);
42
+        return $this->AuthorizeURL.'?'.http_build_query($params);
43 43
     }
44 44
 
45 45
     /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
             'access_token' => $this->token['access_token'] ?? '',
60 60
             'channel' => ConstCode::TYPE_CODING,
61 61
             'nickname' => $response['name'] ?? '',
62
-            'gender'   => ConstCode::GENDER,  // Coding 不返回性别信息
62
+            'gender'   => ConstCode::GENDER, // Coding 不返回性别信息
63 63
             'avatar'   => $response['avatar'] ?? '',
64 64
             // 额外信息
65 65
             'email'    => $response['email'] ?? '',
@@ -80,8 +80,8 @@  discard block
 block discarded – undo
80 80
         ]);
81 81
         $data = json_decode($data, true);
82 82
         
83
-        if(!isset($data['id'])) {
84
-            throw new OAuthException("获取Coding用户信息失败:" . ($data['error_description'] ?? '未知错误'));
83
+        if (!isset($data['id'])) {
84
+            throw new OAuthException("获取Coding用户信息失败:".($data['error_description'] ?? '未知错误'));
85 85
         }
86 86
         return $data;
87 87
     }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
         if (isset($data['access_token'])) {
130 130
             return $data;
131 131
         }
132
-        throw new OAuthException("获取Coding ACCESS_TOKEN出错:" . ($data['error_description'] ?? '未知错误'));
132
+        throw new OAuthException("获取Coding ACCESS_TOKEN出错:".($data['error_description'] ?? '未知错误'));
133 133
     }
134 134
 
135 135
     /**
Please login to merge, or discard this patch.
src/Gateways/Oschina.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -48,8 +48,8 @@  discard block
 block discarded – undo
48 48
         ]);
49 49
         $data = json_decode($data, true);
50 50
         
51
-        if(!isset($data['id'])) {
52
-            throw new OAuthException("获取OSChina用户信息失败:" . ($data['error_description'] ?? '未知错误'));
51
+        if (!isset($data['id'])) {
52
+            throw new OAuthException("获取OSChina用户信息失败:".($data['error_description'] ?? '未知错误'));
53 53
         }
54 54
         return $data;
55 55
     }
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
             'state'         => $this->config['state'],
69 69
             'scope'         => $this->config['scope'],
70 70
         ];
71
-        return $this->AuthorizeURL . '?' . http_build_query($params);
71
+        return $this->AuthorizeURL.'?'.http_build_query($params);
72 72
     }
73 73
 
74 74
     /**
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         if (isset($data['access_token'])) {
116 116
             return $data;
117 117
         }
118
-        throw new OAuthException("获取OSChina ACCESS_TOKEN出错:" . ($data['error_description'] ?? '未知错误'));
118
+        throw new OAuthException("获取OSChina ACCESS_TOKEN出错:".($data['error_description'] ?? '未知错误'));
119 119
     }
120 120
 
121 121
     /**
Please login to merge, or discard this patch.
src/Gateways/Wechat.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
         $this->saveState();
43 43
 
44 44
         //获取代理链接
45
-        if(isset($this->config['proxy_url'])){
45
+        if (isset($this->config['proxy_url'])) {
46 46
             return $this->getProxyURL();
47 47
         }
48 48
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
             'scope'         => $this->config['scope'],
56 56
             'state'         => $this->config['state'],
57 57
         ];
58
-        return $this->AuthorizeURL . '?' . http_build_query($params) . '#wechat_redirect';
58
+        return $this->AuthorizeURL.'?'.http_build_query($params).'#wechat_redirect';
59 59
     }
60 60
 
61 61
     /**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
             'state'         => $this->config['state'],
74 74
             'redirect_uri'    => $this->config['callback'],
75 75
         ];
76
-        return $this->config['proxy_url'] . '?' . http_build_query($params);
76
+        return $this->config['proxy_url'].'?'.http_build_query($params);
77 77
     }
78 78
 
79 79
     /**
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
             'union_id'=> $this->token['unionid'] ?? '',
111 111
             'access_token'=> $this->token['access_token'] ?? '',
112 112
             'channel' => ConstCode::TYPE_WECHAT,
113
-            'nickname'=> $result['nickname']??'',
113
+            'nickname'=> $result['nickname'] ?? '',
114 114
             'gender'  => $result['sex'] ?? ConstCode::GENDER,
115
-            'avatar'  => $result['headimgurl']??'',
115
+            'avatar'  => $result['headimgurl'] ?? '',
116 116
             'type'    => ConstCode::getTypeConst(ConstCode::TYPE_WECHAT, $this->type),
117 117
             // 额外信息
118
-            'session_key'  => $result['session_key']??'',
118
+            'session_key'  => $result['session_key'] ?? '',
119 119
             'native'   => $result,
120 120
         ];
121 121
         return $userInfo;
@@ -130,15 +130,15 @@  discard block
 block discarded – undo
130 130
      */
131 131
     public function getUserInfo()
132 132
     {
133
-        if($this->type == 'app'){//App登录
134
-            if(!isset($_REQUEST['access_token']) ){
133
+        if ($this->type == 'app') {//App登录
134
+            if (!isset($_REQUEST['access_token'])) {
135 135
                 throw new OAuthException("Wechat APP登录 需要传输access_token参数! ");
136 136
             }
137 137
             $this->token['access_token'] = $_REQUEST['access_token'];
138
-        }elseif ($this->type == 'applets'){
138
+        }elseif ($this->type == 'applets') {
139 139
             //小程序
140 140
             return $this->applets();
141
-        }else {
141
+        } else {
142 142
             /** 获取token信息 */
143 143
             $this->getToken();
144 144
         }
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
             'openid'=>$this->openid(),
150 150
             'lang'=>'zh_CN',
151 151
         ];
152
-        $data = $this->get(self::API_BASE . 'userinfo', $params);
152
+        $data = $this->get(self::API_BASE.'userinfo', $params);
153 153
         return json_decode($data, true);
154 154
     }
155 155
 
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
      * @return array|mixed|null
158 158
      * @throws OAuthException
159 159
      */
160
-    public function applets(){
160
+    public function applets() {
161 161
         /** 获取参数 */
162 162
         $params = $this->accessTokenParams();
163 163
         $params['js_code'] = $params['code'];
164 164
 
165 165
         /** 获取access_token */
166
-        $token =  $this->get($this->jsCode2Session, $params);
166
+        $token = $this->get($this->jsCode2Session, $params);
167 167
         /** 解析token值(子类实现此方法) */
168 168
         $this->token = $this->parseToken($token);
169 169
         return $this->token;
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
         $data = json_decode($token, true);
220 220
         if (isset($data['access_token'])) {
221 221
             return $data;
222
-        }elseif (isset($data['session_key'])){
222
+        }elseif (isset($data['session_key'])) {
223 223
             //小程序登录
224 224
             return $data;
225 225
         } else {
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
                 'access_token' => $accessToken,
299 299
                 'openid'      => $this->openid(),
300 300
             ];
301
-            $result = $this->get(self::API_BASE . 'auth', $params);
301
+            $result = $this->get(self::API_BASE.'auth', $params);
302 302
             $result = json_decode($result, true);
303 303
             return isset($result['errcode']) && $result['errcode'] == 0;
304 304
         } catch (\Exception $e) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -135,10 +135,10 @@  discard block
 block discarded – undo
135 135
                 throw new OAuthException("Wechat APP登录 需要传输access_token参数! ");
136 136
             }
137 137
             $this->token['access_token'] = $_REQUEST['access_token'];
138
-        }elseif ($this->type == 'applets'){
138
+        } elseif ($this->type == 'applets'){
139 139
             //小程序
140 140
             return $this->applets();
141
-        }else {
141
+        } else {
142 142
             /** 获取token信息 */
143 143
             $this->getToken();
144 144
         }
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
         $data = json_decode($token, true);
220 220
         if (isset($data['access_token'])) {
221 221
             return $data;
222
-        }elseif (isset($data['session_key'])){
222
+        } elseif (isset($data['session_key'])){
223 223
             //小程序登录
224 224
             return $data;
225 225
         } else {
Please login to merge, or discard this patch.
src/Gateways/Facebook.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             'scope'         => $this->config['scope'],
55 55
             'state'         => $this->config['state'] ?: Str::random(),
56 56
         ];
57
-        return $this->AuthorizeURL . '?' . http_build_query($params);
57
+        return $this->AuthorizeURL.'?'.http_build_query($params);
58 58
     }
59 59
 
60 60
     /**
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function getUserInfo()
93 93
     {
94
-        if($this->type == 'app'){//App登录
95
-            if(!isset($_REQUEST['access_token']) ){
94
+        if ($this->type == 'app') {//App登录
95
+            if (!isset($_REQUEST['access_token'])) {
96 96
                 throw new OAuthException("Facebook APP登录 需要传输access_token参数! ");
97 97
             }
98 98
             $this->token['access_token'] = $_REQUEST['access_token'];
99
-        }else {
99
+        } else {
100 100
             $this->getToken();
101 101
         }
102 102
         $fields = isset($this->config['fields']) ? $this->config['fields'] : 'id,name,gender,picture.width(400)';
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         $method  = strtoupper($method);
117 117
         $request = [
118 118
             'method' => $method,
119
-            'uri'    => self::API_BASE . $api,
119
+            'uri'    => self::API_BASE.$api,
120 120
         ];
121 121
 
122 122
         $data = $this->$method($request['uri'], $params);
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -96,7 +96,7 @@
 block discarded – undo
96 96
                 throw new OAuthException("Facebook APP登录 需要传输access_token参数! ");
97 97
             }
98 98
             $this->token['access_token'] = $_REQUEST['access_token'];
99
-        }else {
99
+        } else {
100 100
             $this->getToken();
101 101
         }
102 102
         $fields = isset($this->config['fields']) ? $this->config['fields'] : 'id,name,gender,picture.width(400)';
Please login to merge, or discard this patch.
src/Connector/GatewayTrait.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
      */
20 20
     protected function get($url, $params = [], $headers = [])
21 21
     {
22
-        return \tinymeng\tools\HttpRequest::httpGet($url, $params,$headers);
22
+        return \tinymeng\tools\HttpRequest::httpGet($url, $params, $headers);
23 23
     }
24 24
 
25 25
     /**
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
      */
34 34
     protected function post($url, $params = [], $headers = [])
35 35
     {
36
-        $headers[] = 'Accept: application/json';//GitHub需要的header
37
-        return \tinymeng\tools\HttpRequest::httpPost($url, $params,$headers);
36
+        $headers[] = 'Accept: application/json'; //GitHub需要的header
37
+        return \tinymeng\tools\HttpRequest::httpPost($url, $params, $headers);
38 38
     }
39 39
 
40 40
 
Please login to merge, or discard this patch.
src/Connector/Gateway.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         if (!$config) {
113 113
             throw new OAuthException('传入的配置不能为空');
114 114
         }
115
-        if(isset($_GET['referer']) && $config['callback']){
115
+        if (isset($_GET['referer']) && $config['callback']) {
116 116
             $config['callback'] .= ((strpos($config['callback'], '?') !== false) ? '&' : '?').'referer='.$_GET['referer'];
117 117
         }
118 118
         //默认参数
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
             'proxy'         => '',
126 126
             'state'         => '',
127 127
             'type'          => '',
128
-            'is_sandbox'    => false,//是否是沙箱环境
128
+            'is_sandbox'    => false, //是否是沙箱环境
129 129
         ];
130
-        $this->config    = array_merge($_config, $config);
131
-        foreach($this->config as $key=>$val){
132
-            if(property_exists($this,$key)) $this->$key=$val;
130
+        $this->config = array_merge($_config, $config);
131
+        foreach ($this->config as $key=>$val) {
132
+            if (property_exists($this, $key)) $this->$key = $val;
133 133
         }
134 134
         $this->timestamp = time();
135 135
     }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      * Updater:
166 166
      * @return $this
167 167
      */
168
-    public function mustCheckState(){
168
+    public function mustCheckState() {
169 169
         $this->checkState = true;
170 170
         return $this;
171 171
     }
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
      * @Author: TinyMeng <[email protected]>
176 176
      * @return array
177 177
      */
178
-    public function getConfig(){
178
+    public function getConfig() {
179 179
         return $this->config;
180 180
     }
181 181
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      * @param $token
185 185
      * @return $this
186 186
      */
187
-    public function setToken($token){
187
+    public function setToken($token) {
188 188
         $this->token = $token;
189 189
         return $this;
190 190
     }
@@ -193,14 +193,14 @@  discard block
 block discarded – undo
193 193
      * 存储state
194 194
      * @Author: TinyMeng <[email protected]>
195 195
      */
196
-    public function saveState(){
196
+    public function saveState() {
197 197
         if ($this->checkState === true) {
198 198
             //是否开启session
199 199
             if (session_status() !== PHP_SESSION_ACTIVE) {
200 200
                 session_start();
201 201
             }
202
-            if(empty($this->config['state'])){
203
-                $this->config['state'] = Str::random();//生成随机state
202
+            if (empty($this->config['state'])) {
203
+                $this->config['state'] = Str::random(); //生成随机state
204 204
             }
205 205
             //存储到session
206 206
             $_SESSION['tinymeng_oauth_state'] = $this->config['state'];
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      * @Author: TinyMeng <[email protected]>
213 213
      * @throws OAuthException
214 214
      */
215
-    public function checkState(){
215
+    public function checkState() {
216 216
         if ($this->checkState === true) {
217 217
             if (session_status() !== PHP_SESSION_ACTIVE) {
218 218
                 session_start();
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      * @author: JiaMeng <[email protected]>
230 230
      * @return string
231 231
      */
232
-    public function getCode(){
232
+    public function getCode() {
233 233
         return isset($_REQUEST['code']) ? $_REQUEST['code'] : '';
234 234
     }
235 235
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
      * Updater:
240 240
      * @return array
241 241
      */
242
-    protected function accessTokenParams(){
242
+    protected function accessTokenParams() {
243 243
         $params = [
244 244
             'client_id'     => $this->config['app_id'],
245 245
             'client_secret' => $this->config['app_secret'],
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
      * @author: JiaMeng <[email protected]>
256 256
      * Updater:
257 257
      */
258
-    protected function getToken(){
258
+    protected function getToken() {
259 259
         if (empty($this->token)) {
260 260
             /** 验证state参数 */
261 261
             $this->checkState();
@@ -264,10 +264,10 @@  discard block
 block discarded – undo
264 264
             $params = $this->accessTokenParams();
265 265
 
266 266
             /** 获取access_token */
267
-            $token =  $this->POST($this->AccessTokenURL, $params);
267
+            $token = $this->POST($this->AccessTokenURL, $params);
268 268
             /** 解析token值(子类实现此方法) */
269 269
             $this->token = $this->parseToken($token);
270
-        }else{
270
+        } else {
271 271
             return $this->token;
272 272
         }
273 273
     }
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
      * M代表男性,F代表女性
278 278
      * @param $gender
279 279
      */
280
-    public function getGender($gender){
281
-        return strtolower(substr($gender , 0 , 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN;
280
+    public function getGender($gender) {
281
+        return strtolower(substr($gender, 0, 1)) == 'm' ? ConstCode::GENDER_MAN : ConstCode::GENDER_WOMEN;
282 282
     }
283 283
 
284 284
 
Please login to merge, or discard this patch.
src/Helper/Encryptor.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
 
7 7
 use tinymeng\OAuth2\Exception\OAuthException;
8 8
 
9
-class Encryptor{
9
+class Encryptor {
10 10
 
11 11
     /**
12 12
      * 解密数据(微信小程序手机号)
Please login to merge, or discard this patch.
src/OAuth.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      */
36 36
     protected static function init($gateway, $config)
37 37
     {
38
-        if(empty($config)){
38
+        if (empty($config)) {
39 39
             throw new OAuthException("第三方登录 [$gateway] config配置不能为空");
40 40
         }
41 41
         $baseConfig = [
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
             'scope'     => '',
46 46
             'type'      => '',
47 47
         ];
48
-        if($gateway == 'weixin'){
48
+        if ($gateway == 'weixin') {
49 49
             /** 兼容 tinymeng/oauth v1.0.0完美升级 */
50 50
             $gateway = 'wechat';
51 51
         }
52 52
         $gateway = Str::uFirst($gateway);
53
-        $class = __NAMESPACE__ . '\\Gateways\\' . $gateway;
53
+        $class = __NAMESPACE__.'\\Gateways\\'.$gateway;
54 54
         if (class_exists($class)) {
55
-            $app = new $class(array_replace_recursive($baseConfig,$config));
55
+            $app = new $class(array_replace_recursive($baseConfig, $config));
56 56
             if ($app instanceof GatewayInterface) {
57 57
                 return $app;
58 58
             }
Please login to merge, or discard this patch.