Passed
Push — master ( bd5724...8a312b )
by
unknown
01:47
created
src/Provider/Instagram.php 1 patch
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -17,240 +17,240 @@
 block discarded – undo
17 17
  */
18 18
 class Instagram extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'user_profile,user_media';
24
-
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://graph.instagram.com';
29
-
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl = 'https://api.instagram.com/oauth/authorize';
34
-
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://api.instagram.com/oauth/access_token';
39
-
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    protected $apiDocumentation = 'https://developers.facebook.com/docs/instagram-basic-display-api';
44
-
45
-    /**
46
-     * {@inheritdoc}
47
-     */
48
-    protected function initialize()
49
-    {
50
-        parent::initialize();
51
-
52
-        // The Instagram API requires an access_token from authenticated users
53
-        // for each endpoint.
54
-        $accessToken = $this->getStoredData($this->accessTokenName);
55
-        $this->apiRequestParameters[$this->accessTokenName] = $accessToken;
56
-    }
57
-
58
-    /**
59
-     * {@inheritdoc}
60
-     */
61
-    protected function validateAccessTokenExchange($response)
62
-    {
63
-        $collection = parent::validateAccessTokenExchange($response);
64
-
65
-        if (!$collection->exists('expires_in')) {
66
-            // Instagram tokens always expire in an hour, but this is implicit not explicit
67
-
68
-            $expires_in = 60 * 60;
69
-
70
-            $expires_at = time() + $expires_in;
71
-
72
-            $this->storeData('expires_in', $expires_in);
73
-            $this->storeData('expires_at', $expires_at);
74
-        }
75
-
76
-        return $collection;
77
-    }
78
-
79
-    /**
80
-     * {@inheritdoc}
81
-     */
82
-    public function maintainToken()
83
-    {
84
-        if (!$this->isConnected()) {
85
-            return;
86
-        }
87
-
88
-        // Handle token exchange prior to the standard handler for an API request
89
-        $exchange_by_expiry_days = $this->config->get('exchange_by_expiry_days') ?: 45;
90
-        if ($exchange_by_expiry_days !== null) {
91
-            $projected_timestamp = time() + 60 * 60 * 24 * $exchange_by_expiry_days;
92
-            if (!$this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) {
93
-                $this->exchangeAccessToken();
94
-            }
95
-        }
96
-    }
97
-
98
-    /**
99
-     * Exchange the Access Token with one that expires further in the future.
100
-     *
101
-     * @return string Raw Provider API response
102
-     * @throws \Hybridauth\Exception\HttpClientFailureException
103
-     * @throws \Hybridauth\Exception\HttpRequestFailedException
104
-     * @throws InvalidAccessTokenException
105
-     */
106
-    public function exchangeAccessToken()
107
-    {
108
-        if ($this->getStoredData('expires_in') >= 5000000) {
109
-            /*
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'user_profile,user_media';
24
+
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://graph.instagram.com';
29
+
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl = 'https://api.instagram.com/oauth/authorize';
34
+
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://api.instagram.com/oauth/access_token';
39
+
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	protected $apiDocumentation = 'https://developers.facebook.com/docs/instagram-basic-display-api';
44
+
45
+	/**
46
+	 * {@inheritdoc}
47
+	 */
48
+	protected function initialize()
49
+	{
50
+		parent::initialize();
51
+
52
+		// The Instagram API requires an access_token from authenticated users
53
+		// for each endpoint.
54
+		$accessToken = $this->getStoredData($this->accessTokenName);
55
+		$this->apiRequestParameters[$this->accessTokenName] = $accessToken;
56
+	}
57
+
58
+	/**
59
+	 * {@inheritdoc}
60
+	 */
61
+	protected function validateAccessTokenExchange($response)
62
+	{
63
+		$collection = parent::validateAccessTokenExchange($response);
64
+
65
+		if (!$collection->exists('expires_in')) {
66
+			// Instagram tokens always expire in an hour, but this is implicit not explicit
67
+
68
+			$expires_in = 60 * 60;
69
+
70
+			$expires_at = time() + $expires_in;
71
+
72
+			$this->storeData('expires_in', $expires_in);
73
+			$this->storeData('expires_at', $expires_at);
74
+		}
75
+
76
+		return $collection;
77
+	}
78
+
79
+	/**
80
+	 * {@inheritdoc}
81
+	 */
82
+	public function maintainToken()
83
+	{
84
+		if (!$this->isConnected()) {
85
+			return;
86
+		}
87
+
88
+		// Handle token exchange prior to the standard handler for an API request
89
+		$exchange_by_expiry_days = $this->config->get('exchange_by_expiry_days') ?: 45;
90
+		if ($exchange_by_expiry_days !== null) {
91
+			$projected_timestamp = time() + 60 * 60 * 24 * $exchange_by_expiry_days;
92
+			if (!$this->hasAccessTokenExpired() && $this->hasAccessTokenExpired($projected_timestamp)) {
93
+				$this->exchangeAccessToken();
94
+			}
95
+		}
96
+	}
97
+
98
+	/**
99
+	 * Exchange the Access Token with one that expires further in the future.
100
+	 *
101
+	 * @return string Raw Provider API response
102
+	 * @throws \Hybridauth\Exception\HttpClientFailureException
103
+	 * @throws \Hybridauth\Exception\HttpRequestFailedException
104
+	 * @throws InvalidAccessTokenException
105
+	 */
106
+	public function exchangeAccessToken()
107
+	{
108
+		if ($this->getStoredData('expires_in') >= 5000000) {
109
+			/*
110 110
             Refresh a long-lived token (needed on Instagram, but not Facebook).
111 111
             It's not an oAuth style refresh using a refresh token.
112 112
             Actually it's really just another exchange, and invalidates the old token.
113 113
             Facebook/Instagram documentation is not very helpful at explaining that!
114 114
             */
115
-            $exchangeTokenParameters = [
116
-                'grant_type'        => 'ig_refresh_token',
117
-                'client_secret'     => $this->clientSecret,
118
-                'access_token'      => $this->getStoredData('access_token'),
119
-            ];
120
-            $url = 'https://graph.instagram.com/refresh_access_token';
121
-        } else {
122
-            // Exchange short-lived to long-lived
123
-            $exchangeTokenParameters = [
124
-                'grant_type'        => 'ig_exchange_token',
125
-                'client_secret'     => $this->clientSecret,
126
-                'access_token'      => $this->getStoredData('access_token'),
127
-            ];
128
-            $url = 'https://graph.instagram.com/access_token';
129
-        }
130
-
131
-        $response = $this->httpClient->request(
132
-            $url,
133
-            'GET',
134
-            $exchangeTokenParameters
135
-        );
136
-
137
-        $this->validateApiResponse('Unable to exchange the access token');
138
-
139
-        $this->validateAccessTokenExchange($response);
140
-
141
-        return $response;
142
-    }
143
-
144
-    /**
145
-     * {@inheritdoc}
146
-     */
147
-    public function getUserProfile()
148
-    {
149
-        $response = $this->apiRequest('me', 'GET', [
150
-            'fields' => 'id,username,account_type,media_count',
151
-        ]);
152
-
153
-        $data = new Collection($response);
154
-        if (!$data->exists('id')) {
155
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
156
-        }
157
-
158
-        $userProfile = new User\Profile();
159
-        $userProfile->identifier = $data->get('id');
160
-        $userProfile->displayName = $data->get('username');
161
-        $userProfile->profileURL = "https://instagram.com/{$userProfile->displayName}";
162
-        $userProfile->data = [
163
-            'account_type' => $data->get('account_type'),
164
-            'media_count' => $data->get('media_count'),
165
-        ];
166
-
167
-        return $userProfile;
168
-    }
169
-
170
-    /**
171
-     * Fetch user medias.
172
-     *
173
-     * @param int $limit Number of elements per page.
174
-     * @param string $pageId Current pager ID.
175
-     * @param array|null $fields Fields to fetch per media.
176
-     *
177
-     * @return \Hybridauth\Data\Collection
178
-     *
179
-     * @throws \Hybridauth\Exception\HttpClientFailureException
180
-     * @throws \Hybridauth\Exception\HttpRequestFailedException
181
-     * @throws \Hybridauth\Exception\InvalidAccessTokenException
182
-     * @throws \Hybridauth\Exception\UnexpectedApiResponseException
183
-     */
184
-    public function getUserMedia($limit = 12, $pageId = null, array $fields = null)
185
-    {
186
-        if (empty($fields)) {
187
-            $fields = [
188
-                'id',
189
-                'caption',
190
-                'media_type',
191
-                'media_url',
192
-                'thumbnail_url',
193
-                'permalink',
194
-                'timestamp',
195
-                'username',
196
-            ];
197
-        }
198
-
199
-        $params = [
200
-            'fields' => implode(',', $fields),
201
-            'limit' => $limit,
202
-        ];
203
-        if ($pageId !== null) {
204
-            $params['after'] = $pageId;
205
-        }
206
-
207
-        $response = $this->apiRequest('me/media', 'GET', $params);
208
-
209
-        $data = new Collection($response);
210
-        if (!$data->exists('data')) {
211
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
212
-        }
213
-
214
-        return $data;
215
-    }
216
-
217
-    /**
218
-     * Fetches a single user's media.
219
-     *
220
-     * @param string $mediaId Media ID.
221
-     * @param array|null $fields Fields to fetch per media.
222
-     *
223
-     * @return \Hybridauth\Data\Collection
224
-     *
225
-     * @throws \Hybridauth\Exception\HttpClientFailureException
226
-     * @throws \Hybridauth\Exception\HttpRequestFailedException
227
-     * @throws \Hybridauth\Exception\InvalidAccessTokenException
228
-     * @throws \Hybridauth\Exception\UnexpectedApiResponseException
229
-     */
230
-    public function getMedia($mediaId, array $fields = null)
231
-    {
232
-        if (empty($fields)) {
233
-            $fields = [
234
-                'id',
235
-                'caption',
236
-                'media_type',
237
-                'media_url',
238
-                'thumbnail_url',
239
-                'permalink',
240
-                'timestamp',
241
-                'username',
242
-            ];
243
-        }
244
-
245
-        $response = $this->apiRequest($mediaId, 'GET', [
246
-            'fields' => implode(',', $fields),
247
-        ]);
248
-
249
-        $data = new Collection($response);
250
-        if (!$data->exists('id')) {
251
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
252
-        }
253
-
254
-        return $data;
255
-    }
115
+			$exchangeTokenParameters = [
116
+				'grant_type'        => 'ig_refresh_token',
117
+				'client_secret'     => $this->clientSecret,
118
+				'access_token'      => $this->getStoredData('access_token'),
119
+			];
120
+			$url = 'https://graph.instagram.com/refresh_access_token';
121
+		} else {
122
+			// Exchange short-lived to long-lived
123
+			$exchangeTokenParameters = [
124
+				'grant_type'        => 'ig_exchange_token',
125
+				'client_secret'     => $this->clientSecret,
126
+				'access_token'      => $this->getStoredData('access_token'),
127
+			];
128
+			$url = 'https://graph.instagram.com/access_token';
129
+		}
130
+
131
+		$response = $this->httpClient->request(
132
+			$url,
133
+			'GET',
134
+			$exchangeTokenParameters
135
+		);
136
+
137
+		$this->validateApiResponse('Unable to exchange the access token');
138
+
139
+		$this->validateAccessTokenExchange($response);
140
+
141
+		return $response;
142
+	}
143
+
144
+	/**
145
+	 * {@inheritdoc}
146
+	 */
147
+	public function getUserProfile()
148
+	{
149
+		$response = $this->apiRequest('me', 'GET', [
150
+			'fields' => 'id,username,account_type,media_count',
151
+		]);
152
+
153
+		$data = new Collection($response);
154
+		if (!$data->exists('id')) {
155
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
156
+		}
157
+
158
+		$userProfile = new User\Profile();
159
+		$userProfile->identifier = $data->get('id');
160
+		$userProfile->displayName = $data->get('username');
161
+		$userProfile->profileURL = "https://instagram.com/{$userProfile->displayName}";
162
+		$userProfile->data = [
163
+			'account_type' => $data->get('account_type'),
164
+			'media_count' => $data->get('media_count'),
165
+		];
166
+
167
+		return $userProfile;
168
+	}
169
+
170
+	/**
171
+	 * Fetch user medias.
172
+	 *
173
+	 * @param int $limit Number of elements per page.
174
+	 * @param string $pageId Current pager ID.
175
+	 * @param array|null $fields Fields to fetch per media.
176
+	 *
177
+	 * @return \Hybridauth\Data\Collection
178
+	 *
179
+	 * @throws \Hybridauth\Exception\HttpClientFailureException
180
+	 * @throws \Hybridauth\Exception\HttpRequestFailedException
181
+	 * @throws \Hybridauth\Exception\InvalidAccessTokenException
182
+	 * @throws \Hybridauth\Exception\UnexpectedApiResponseException
183
+	 */
184
+	public function getUserMedia($limit = 12, $pageId = null, array $fields = null)
185
+	{
186
+		if (empty($fields)) {
187
+			$fields = [
188
+				'id',
189
+				'caption',
190
+				'media_type',
191
+				'media_url',
192
+				'thumbnail_url',
193
+				'permalink',
194
+				'timestamp',
195
+				'username',
196
+			];
197
+		}
198
+
199
+		$params = [
200
+			'fields' => implode(',', $fields),
201
+			'limit' => $limit,
202
+		];
203
+		if ($pageId !== null) {
204
+			$params['after'] = $pageId;
205
+		}
206
+
207
+		$response = $this->apiRequest('me/media', 'GET', $params);
208
+
209
+		$data = new Collection($response);
210
+		if (!$data->exists('data')) {
211
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
212
+		}
213
+
214
+		return $data;
215
+	}
216
+
217
+	/**
218
+	 * Fetches a single user's media.
219
+	 *
220
+	 * @param string $mediaId Media ID.
221
+	 * @param array|null $fields Fields to fetch per media.
222
+	 *
223
+	 * @return \Hybridauth\Data\Collection
224
+	 *
225
+	 * @throws \Hybridauth\Exception\HttpClientFailureException
226
+	 * @throws \Hybridauth\Exception\HttpRequestFailedException
227
+	 * @throws \Hybridauth\Exception\InvalidAccessTokenException
228
+	 * @throws \Hybridauth\Exception\UnexpectedApiResponseException
229
+	 */
230
+	public function getMedia($mediaId, array $fields = null)
231
+	{
232
+		if (empty($fields)) {
233
+			$fields = [
234
+				'id',
235
+				'caption',
236
+				'media_type',
237
+				'media_url',
238
+				'thumbnail_url',
239
+				'permalink',
240
+				'timestamp',
241
+				'username',
242
+			];
243
+		}
244
+
245
+		$response = $this->apiRequest($mediaId, 'GET', [
246
+			'fields' => implode(',', $fields),
247
+		]);
248
+
249
+		$data = new Collection($response);
250
+		if (!$data->exists('id')) {
251
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
252
+		}
253
+
254
+		return $data;
255
+	}
256 256
 }
Please login to merge, or discard this patch.
src/Provider/AutoDesk.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -17,80 +17,80 @@
 block discarded – undo
17 17
  */
18 18
 class AutoDesk extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'data:read';
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'data:read';
24 24
 
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://developer.api.autodesk.com/';
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://developer.api.autodesk.com/';
29 29
 
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl
34
-        = 'https://developer.api.autodesk.com/authentication/v1/authorize';
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl
34
+		= 'https://developer.api.autodesk.com/authentication/v1/authorize';
35 35
 
36
-    /**
37
-     * {@inheritdoc}
38
-     */
39
-    protected $accessTokenUrl
40
-        = 'https://developer.api.autodesk.com/authentication/v1/gettoken';
36
+	/**
37
+	 * {@inheritdoc}
38
+	 */
39
+	protected $accessTokenUrl
40
+		= 'https://developer.api.autodesk.com/authentication/v1/gettoken';
41 41
 
42
-    /**
43
-     * {@inheritdoc}
44
-     */
45
-    protected $refreshTokenUrl
46
-        = 'https://developer.api.autodesk.com/authentication/v1/refreshtoken';
42
+	/**
43
+	 * {@inheritdoc}
44
+	 */
45
+	protected $refreshTokenUrl
46
+		= 'https://developer.api.autodesk.com/authentication/v1/refreshtoken';
47 47
 
48
-    /**
49
-     * {@inheritdoc}
50
-     */
51
-    protected $apiDocumentation
52
-        = 'https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/overview/';
48
+	/**
49
+	 * {@inheritdoc}
50
+	 */
51
+	protected $apiDocumentation
52
+		= 'https://forge.autodesk.com/en/docs/oauth/v2/developers_guide/overview/';
53 53
 
54
-    /**
55
-     * {@inheritdoc}
56
-     */
57
-    protected function initialize()
58
-    {
59
-        parent::initialize();
54
+	/**
55
+	 * {@inheritdoc}
56
+	 */
57
+	protected function initialize()
58
+	{
59
+		parent::initialize();
60 60
         
61
-        if ($this->isRefreshTokenAvailable()) {
62
-            $this->tokenRefreshParameters += [
63
-                'client_id'     => $this->clientId,
64
-                'client_secret' => $this->clientSecret,
65
-                'grant_type'    => 'refresh_token',
66
-            ];
67
-        }
68
-    }
61
+		if ($this->isRefreshTokenAvailable()) {
62
+			$this->tokenRefreshParameters += [
63
+				'client_id'     => $this->clientId,
64
+				'client_secret' => $this->clientSecret,
65
+				'grant_type'    => 'refresh_token',
66
+			];
67
+		}
68
+	}
69 69
 
70
-    /**
71
-     * {@inheritdoc}
72
-     *
73
-     * See: https://forge.autodesk.com/en/docs/oauth/v2/reference/http/users-@me-GET/
74
-     */
75
-    public function getUserProfile()
76
-    {
77
-        $response = $this->apiRequest('userprofile/v1/users/@me');
70
+	/**
71
+	 * {@inheritdoc}
72
+	 *
73
+	 * See: https://forge.autodesk.com/en/docs/oauth/v2/reference/http/users-@me-GET/
74
+	 */
75
+	public function getUserProfile()
76
+	{
77
+		$response = $this->apiRequest('userprofile/v1/users/@me');
78 78
 
79
-        $collection = new Data\Collection($response);
79
+		$collection = new Data\Collection($response);
80 80
 
81
-        $userProfile = new User\Profile();
81
+		$userProfile = new User\Profile();
82 82
 
83
-        $userProfile->identifier = $collection->get('userId');
84
-        $userProfile->displayName
85
-            = $collection->get('firstName') .' '. $collection->get('lastName');
86
-        $userProfile->firstName = $collection->get('firstName');
87
-        $userProfile->lastName = $collection->get('lastName');
88
-        $userProfile->email = $collection->get('emailId');
89
-        $userProfile->language = $collection->get('language');
90
-        $userProfile->webSiteURL = $collection->get('websiteUrl');
91
-        $userProfile->photoURL
92
-            = $collection->filter('profileImages')->get('sizeX360');
83
+		$userProfile->identifier = $collection->get('userId');
84
+		$userProfile->displayName
85
+			= $collection->get('firstName') .' '. $collection->get('lastName');
86
+		$userProfile->firstName = $collection->get('firstName');
87
+		$userProfile->lastName = $collection->get('lastName');
88
+		$userProfile->email = $collection->get('emailId');
89
+		$userProfile->language = $collection->get('language');
90
+		$userProfile->webSiteURL = $collection->get('websiteUrl');
91
+		$userProfile->photoURL
92
+			= $collection->filter('profileImages')->get('sizeX360');
93 93
 
94
-        return $userProfile;
95
-    }
94
+		return $userProfile;
95
+	}
96 96
 }
Please login to merge, or discard this patch.
src/Provider/WeChat.php 1 patch
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -17,121 +17,121 @@
 block discarded – undo
17 17
  */
18 18
 class WeChat extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'snsapi_login,snsapi_userinfo,scope.userInfo';
24
-
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://api.wechat.com/sns/';
29
-
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl = 'https://open.weixin.qq.com/connect/qrconnect';
34
-
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://api.wechat.com/sns/oauth2/access_token';
39
-
40
-    /**
41
-     * Refresh Token Endpoint
42
-     * @var string
43
-     */
44
-    protected $tokenRefreshUrl = 'https://api.wechat.com/sns/oauth2/refresh_token';
45
-
46
-    /**
47
-     * {@ịnheritdoc}
48
-     */
49
-    protected $accessTokenInfoUrl = 'https://api.wechat.com/sns/auth';
50
-
51
-    /**
52
-     * {@inheritdoc}
53
-     */
54
-    protected $tokenExchangeMethod = 'GET';
55
-
56
-    /**
57
-     * {@inheritdoc}
58
-     */
59
-    protected $tokenRefreshMethod = 'GET';
60
-
61
-    /**
62
-     * {@inheritdoc}
63
-     */
64
-    protected $apiDocumentation = ''; // Not available
65
-
66
-    /**
67
-     * {@inheritdoc}
68
-     */
69
-    protected function initialize()
70
-    {
71
-        parent::initialize();
72
-
73
-        $this->AuthorizeUrlParameters += [
74
-            'appid' => $this->clientId
75
-        ];
76
-        unset($this->AuthorizeUrlParameters['client_id']);
77
-
78
-        $this->tokenExchangeParameters += [
79
-            'appid' => $this->clientId,
80
-            'secret' => $this->clientSecret
81
-        ];
82
-        unset($this->tokenExchangeParameters['client_id']);
83
-        unset($this->tokenExchangeParameters['client_secret']);
84
-
85
-        if ($this->isRefreshTokenAvailable()) {
86
-            $this->tokenRefreshParameters += [
87
-                'appid' => $this->clientId,
88
-            ];
89
-        }
90
-
91
-        $this->apiRequestParameters = [
92
-            'appid' => $this->clientId,
93
-            'secret' => $this->clientSecret
94
-        ];
95
-    }
96
-
97
-    /**
98
-     * {@inheritdoc}
99
-     */
100
-    protected function validateAccessTokenExchange($response)
101
-    {
102
-        $collection = parent::validateAccessTokenExchange($response);
103
-
104
-        $this->storeData('openid', $collection->get('openid'));
105
-        $this->storeData('access_token', $collection->get('access_token'));
106
-    }
107
-
108
-    /**
109
-     * {@inheritdoc}
110
-     */
111
-    public function getUserProfile()
112
-    {
113
-        $openid = $this->getStoredData('openid');
114
-        $access_token = $this->getStoredData('access_token');
115
-
116
-        $response = $this->apiRequest('userinfo', 'GET', ['openid' => $openid, 'access_token' => $access_token]);
117
-
118
-        $data = new Data\Collection($response);
119
-
120
-        if (!$data->exists('openid')) {
121
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
122
-        }
123
-
124
-        $userProfile = new User\Profile();
125
-
126
-        $userProfile->identifier = $data->get('openid');
127
-        $userProfile->displayName = $data->get('nickname');
128
-        $userProfile->photoURL = $data->get('headimgurl');
129
-        $userProfile->city = $data->get('city');
130
-        $userProfile->region = $data->get('province');
131
-        $userProfile->country = $data->get('country');
132
-        $genders = ['', 'male', 'female'];
133
-        $userProfile->gender = $genders[(int)$data->get('sex')];
134
-
135
-        return $userProfile;
136
-    }
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'snsapi_login,snsapi_userinfo,scope.userInfo';
24
+
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://api.wechat.com/sns/';
29
+
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl = 'https://open.weixin.qq.com/connect/qrconnect';
34
+
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://api.wechat.com/sns/oauth2/access_token';
39
+
40
+	/**
41
+	 * Refresh Token Endpoint
42
+	 * @var string
43
+	 */
44
+	protected $tokenRefreshUrl = 'https://api.wechat.com/sns/oauth2/refresh_token';
45
+
46
+	/**
47
+	 * {@ịnheritdoc}
48
+	 */
49
+	protected $accessTokenInfoUrl = 'https://api.wechat.com/sns/auth';
50
+
51
+	/**
52
+	 * {@inheritdoc}
53
+	 */
54
+	protected $tokenExchangeMethod = 'GET';
55
+
56
+	/**
57
+	 * {@inheritdoc}
58
+	 */
59
+	protected $tokenRefreshMethod = 'GET';
60
+
61
+	/**
62
+	 * {@inheritdoc}
63
+	 */
64
+	protected $apiDocumentation = ''; // Not available
65
+
66
+	/**
67
+	 * {@inheritdoc}
68
+	 */
69
+	protected function initialize()
70
+	{
71
+		parent::initialize();
72
+
73
+		$this->AuthorizeUrlParameters += [
74
+			'appid' => $this->clientId
75
+		];
76
+		unset($this->AuthorizeUrlParameters['client_id']);
77
+
78
+		$this->tokenExchangeParameters += [
79
+			'appid' => $this->clientId,
80
+			'secret' => $this->clientSecret
81
+		];
82
+		unset($this->tokenExchangeParameters['client_id']);
83
+		unset($this->tokenExchangeParameters['client_secret']);
84
+
85
+		if ($this->isRefreshTokenAvailable()) {
86
+			$this->tokenRefreshParameters += [
87
+				'appid' => $this->clientId,
88
+			];
89
+		}
90
+
91
+		$this->apiRequestParameters = [
92
+			'appid' => $this->clientId,
93
+			'secret' => $this->clientSecret
94
+		];
95
+	}
96
+
97
+	/**
98
+	 * {@inheritdoc}
99
+	 */
100
+	protected function validateAccessTokenExchange($response)
101
+	{
102
+		$collection = parent::validateAccessTokenExchange($response);
103
+
104
+		$this->storeData('openid', $collection->get('openid'));
105
+		$this->storeData('access_token', $collection->get('access_token'));
106
+	}
107
+
108
+	/**
109
+	 * {@inheritdoc}
110
+	 */
111
+	public function getUserProfile()
112
+	{
113
+		$openid = $this->getStoredData('openid');
114
+		$access_token = $this->getStoredData('access_token');
115
+
116
+		$response = $this->apiRequest('userinfo', 'GET', ['openid' => $openid, 'access_token' => $access_token]);
117
+
118
+		$data = new Data\Collection($response);
119
+
120
+		if (!$data->exists('openid')) {
121
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
122
+		}
123
+
124
+		$userProfile = new User\Profile();
125
+
126
+		$userProfile->identifier = $data->get('openid');
127
+		$userProfile->displayName = $data->get('nickname');
128
+		$userProfile->photoURL = $data->get('headimgurl');
129
+		$userProfile->city = $data->get('city');
130
+		$userProfile->region = $data->get('province');
131
+		$userProfile->country = $data->get('country');
132
+		$genders = ['', 'male', 'female'];
133
+		$userProfile->gender = $genders[(int)$data->get('sex')];
134
+
135
+		return $userProfile;
136
+	}
137 137
 }
Please login to merge, or discard this patch.
src/Provider/Twitter.php 1 patch
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -40,225 +40,225 @@
 block discarded – undo
40 40
  */
41 41
 class Twitter extends OAuth1
42 42
 {
43
-    /**
44
-     * {@inheritdoc}
45
-     */
46
-    protected $apiBaseUrl = 'https://api.twitter.com/1.1/';
47
-
48
-    /**
49
-     * {@inheritdoc}
50
-     */
51
-    protected $authorizeUrl = 'https://api.twitter.com/oauth/authenticate';
52
-
53
-    /**
54
-     * {@inheritdoc}
55
-     */
56
-    protected $requestTokenUrl = 'https://api.twitter.com/oauth/request_token';
57
-
58
-    /**
59
-     * {@inheritdoc}
60
-     */
61
-    protected $accessTokenUrl = 'https://api.twitter.com/oauth/access_token';
62
-
63
-    /**
64
-     * {@inheritdoc}
65
-     */
66
-    protected $apiDocumentation = 'https://dev.twitter.com/web/sign-in/implementing';
67
-
68
-    /**
69
-     * {@inheritdoc}
70
-     */
71
-    protected function getAuthorizeUrl($parameters = [])
72
-    {
73
-        if ($this->config->get('authorize') === true) {
74
-            $this->authorizeUrl = 'https://api.twitter.com/oauth/authorize';
75
-        }
76
-
77
-        return parent::getAuthorizeUrl($parameters);
78
-    }
79
-
80
-    /**
81
-     * {@inheritdoc}
82
-     */
83
-    public function getUserProfile()
84
-    {
85
-        $response = $this->apiRequest('account/verify_credentials.json', 'GET', [
86
-            'include_email' => $this->config->get('include_email') === false ? 'false' : 'true',
87
-        ]);
88
-
89
-        $data = new Data\Collection($response);
90
-
91
-        if (!$data->exists('id_str')) {
92
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
93
-        }
94
-
95
-        $userProfile = new User\Profile();
96
-
97
-        $userProfile->identifier = $data->get('id_str');
98
-        $userProfile->displayName = $data->get('screen_name');
99
-        $userProfile->description = $data->get('description');
100
-        $userProfile->firstName = $data->get('name');
101
-        $userProfile->email = $data->get('email');
102
-        $userProfile->emailVerified = $data->get('email');
103
-        $userProfile->webSiteURL = $data->get('url');
104
-        $userProfile->region = $data->get('location');
105
-
106
-        $userProfile->profileURL = $data->exists('screen_name')
107
-            ? ('https://twitter.com/' . $data->get('screen_name'))
108
-            : '';
109
-
110
-        $photoSize = $this->config->get('photo_size') ?: 'original';
111
-        $photoSize = $photoSize === 'original' ? '' : "_{$photoSize}";
112
-        $userProfile->photoURL = $data->exists('profile_image_url_https')
113
-            ? str_replace('_normal', $photoSize, $data->get('profile_image_url_https'))
114
-            : '';
115
-
116
-        $userProfile->data = [
117
-            'followed_by' => $data->get('followers_count'),
118
-            'follows' => $data->get('friends_count'),
119
-        ];
120
-
121
-        return $userProfile;
122
-    }
123
-
124
-    /**
125
-     * {@inheritdoc}
126
-     */
127
-    public function getUserContacts($parameters = [])
128
-    {
129
-        $parameters = ['cursor' => '-1'] + $parameters;
130
-
131
-        $response = $this->apiRequest('friends/ids.json', 'GET', $parameters);
132
-
133
-        $data = new Data\Collection($response);
134
-
135
-        if (!$data->exists('ids')) {
136
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
137
-        }
138
-
139
-        if ($data->filter('ids')->isEmpty()) {
140
-            return [];
141
-        }
142
-
143
-        $contacts = [];
144
-
145
-        // 75 id per time should be okey
146
-        $contactsIds = array_chunk((array)$data->get('ids'), 75);
147
-
148
-        foreach ($contactsIds as $chunk) {
149
-            $parameters = ['user_id' => implode(',', $chunk)];
150
-
151
-            try {
152
-                $response = $this->apiRequest('users/lookup.json', 'GET', $parameters);
153
-
154
-                if ($response && count($response)) {
155
-                    foreach ($response as $item) {
156
-                        $contacts[] = $this->fetchUserContact($item);
157
-                    }
158
-                }
159
-            } catch (\Exception $e) {
160
-                continue;
161
-            }
162
-        }
163
-
164
-        return $contacts;
165
-    }
166
-
167
-    /**
168
-     * @param $item
169
-     *
170
-     * @return User\Contact
171
-     */
172
-    protected function fetchUserContact($item)
173
-    {
174
-        $item = new Data\Collection($item);
175
-
176
-        $userContact = new User\Contact();
177
-
178
-        $userContact->identifier = $item->get('id_str');
179
-        $userContact->displayName = $item->get('name');
180
-        $userContact->photoURL = $item->get('profile_image_url');
181
-        $userContact->description = $item->get('description');
182
-
183
-        $userContact->profileURL = $item->exists('screen_name')
184
-            ? ('https://twitter.com/' . $item->get('screen_name'))
185
-            : '';
186
-
187
-        return $userContact;
188
-    }
189
-
190
-    /**
191
-     * {@inheritdoc}
192
-     */
193
-    public function setUserStatus($status)
194
-    {
195
-        if (is_string($status)) {
196
-            $status = ['status' => $status];
197
-        }
198
-
199
-        // Prepare request parameters.
200
-        $params = [];
201
-        if (isset($status['status'])) {
202
-            $params['status'] = $status['status'];
203
-        }
204
-        if (isset($status['picture'])) {
205
-            $media = $this->apiRequest('https://upload.twitter.com/1.1/media/upload.json', 'POST', [
206
-                'media' => base64_encode(file_get_contents($status['picture'])),
207
-            ]);
208
-            $params['media_ids'] = $media->media_id;
209
-        }
210
-
211
-        $response = $this->apiRequest('statuses/update.json', 'POST', $params);
212
-
213
-        return $response;
214
-    }
215
-
216
-    /**
217
-     * {@inheritdoc}
218
-     */
219
-    public function getUserActivity($stream = 'me')
220
-    {
221
-        $apiUrl = ($stream == 'me')
222
-            ? 'statuses/user_timeline.json'
223
-            : 'statuses/home_timeline.json';
224
-
225
-        $response = $this->apiRequest($apiUrl);
226
-
227
-        if (!$response) {
228
-            return [];
229
-        }
230
-
231
-        $activities = [];
232
-
233
-        foreach ($response as $item) {
234
-            $activities[] = $this->fetchUserActivity($item);
235
-        }
236
-
237
-        return $activities;
238
-    }
239
-
240
-    /**
241
-     * @param $item
242
-     * @return User\Activity
243
-     */
244
-    protected function fetchUserActivity($item)
245
-    {
246
-        $item = new Data\Collection($item);
247
-
248
-        $userActivity = new User\Activity();
249
-
250
-        $userActivity->id = $item->get('id_str');
251
-        $userActivity->date = $item->get('created_at');
252
-        $userActivity->text = $item->get('text');
253
-
254
-        $userActivity->user->identifier = $item->filter('user')->get('id_str');
255
-        $userActivity->user->displayName = $item->filter('user')->get('name');
256
-        $userActivity->user->photoURL = $item->filter('user')->get('profile_image_url');
257
-
258
-        $userActivity->user->profileURL = $item->filter('user')->get('screen_name')
259
-            ? ('https://twitter.com/' . $item->filter('user')->get('screen_name'))
260
-            : '';
261
-
262
-        return $userActivity;
263
-    }
43
+	/**
44
+	 * {@inheritdoc}
45
+	 */
46
+	protected $apiBaseUrl = 'https://api.twitter.com/1.1/';
47
+
48
+	/**
49
+	 * {@inheritdoc}
50
+	 */
51
+	protected $authorizeUrl = 'https://api.twitter.com/oauth/authenticate';
52
+
53
+	/**
54
+	 * {@inheritdoc}
55
+	 */
56
+	protected $requestTokenUrl = 'https://api.twitter.com/oauth/request_token';
57
+
58
+	/**
59
+	 * {@inheritdoc}
60
+	 */
61
+	protected $accessTokenUrl = 'https://api.twitter.com/oauth/access_token';
62
+
63
+	/**
64
+	 * {@inheritdoc}
65
+	 */
66
+	protected $apiDocumentation = 'https://dev.twitter.com/web/sign-in/implementing';
67
+
68
+	/**
69
+	 * {@inheritdoc}
70
+	 */
71
+	protected function getAuthorizeUrl($parameters = [])
72
+	{
73
+		if ($this->config->get('authorize') === true) {
74
+			$this->authorizeUrl = 'https://api.twitter.com/oauth/authorize';
75
+		}
76
+
77
+		return parent::getAuthorizeUrl($parameters);
78
+	}
79
+
80
+	/**
81
+	 * {@inheritdoc}
82
+	 */
83
+	public function getUserProfile()
84
+	{
85
+		$response = $this->apiRequest('account/verify_credentials.json', 'GET', [
86
+			'include_email' => $this->config->get('include_email') === false ? 'false' : 'true',
87
+		]);
88
+
89
+		$data = new Data\Collection($response);
90
+
91
+		if (!$data->exists('id_str')) {
92
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
93
+		}
94
+
95
+		$userProfile = new User\Profile();
96
+
97
+		$userProfile->identifier = $data->get('id_str');
98
+		$userProfile->displayName = $data->get('screen_name');
99
+		$userProfile->description = $data->get('description');
100
+		$userProfile->firstName = $data->get('name');
101
+		$userProfile->email = $data->get('email');
102
+		$userProfile->emailVerified = $data->get('email');
103
+		$userProfile->webSiteURL = $data->get('url');
104
+		$userProfile->region = $data->get('location');
105
+
106
+		$userProfile->profileURL = $data->exists('screen_name')
107
+			? ('https://twitter.com/' . $data->get('screen_name'))
108
+			: '';
109
+
110
+		$photoSize = $this->config->get('photo_size') ?: 'original';
111
+		$photoSize = $photoSize === 'original' ? '' : "_{$photoSize}";
112
+		$userProfile->photoURL = $data->exists('profile_image_url_https')
113
+			? str_replace('_normal', $photoSize, $data->get('profile_image_url_https'))
114
+			: '';
115
+
116
+		$userProfile->data = [
117
+			'followed_by' => $data->get('followers_count'),
118
+			'follows' => $data->get('friends_count'),
119
+		];
120
+
121
+		return $userProfile;
122
+	}
123
+
124
+	/**
125
+	 * {@inheritdoc}
126
+	 */
127
+	public function getUserContacts($parameters = [])
128
+	{
129
+		$parameters = ['cursor' => '-1'] + $parameters;
130
+
131
+		$response = $this->apiRequest('friends/ids.json', 'GET', $parameters);
132
+
133
+		$data = new Data\Collection($response);
134
+
135
+		if (!$data->exists('ids')) {
136
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
137
+		}
138
+
139
+		if ($data->filter('ids')->isEmpty()) {
140
+			return [];
141
+		}
142
+
143
+		$contacts = [];
144
+
145
+		// 75 id per time should be okey
146
+		$contactsIds = array_chunk((array)$data->get('ids'), 75);
147
+
148
+		foreach ($contactsIds as $chunk) {
149
+			$parameters = ['user_id' => implode(',', $chunk)];
150
+
151
+			try {
152
+				$response = $this->apiRequest('users/lookup.json', 'GET', $parameters);
153
+
154
+				if ($response && count($response)) {
155
+					foreach ($response as $item) {
156
+						$contacts[] = $this->fetchUserContact($item);
157
+					}
158
+				}
159
+			} catch (\Exception $e) {
160
+				continue;
161
+			}
162
+		}
163
+
164
+		return $contacts;
165
+	}
166
+
167
+	/**
168
+	 * @param $item
169
+	 *
170
+	 * @return User\Contact
171
+	 */
172
+	protected function fetchUserContact($item)
173
+	{
174
+		$item = new Data\Collection($item);
175
+
176
+		$userContact = new User\Contact();
177
+
178
+		$userContact->identifier = $item->get('id_str');
179
+		$userContact->displayName = $item->get('name');
180
+		$userContact->photoURL = $item->get('profile_image_url');
181
+		$userContact->description = $item->get('description');
182
+
183
+		$userContact->profileURL = $item->exists('screen_name')
184
+			? ('https://twitter.com/' . $item->get('screen_name'))
185
+			: '';
186
+
187
+		return $userContact;
188
+	}
189
+
190
+	/**
191
+	 * {@inheritdoc}
192
+	 */
193
+	public function setUserStatus($status)
194
+	{
195
+		if (is_string($status)) {
196
+			$status = ['status' => $status];
197
+		}
198
+
199
+		// Prepare request parameters.
200
+		$params = [];
201
+		if (isset($status['status'])) {
202
+			$params['status'] = $status['status'];
203
+		}
204
+		if (isset($status['picture'])) {
205
+			$media = $this->apiRequest('https://upload.twitter.com/1.1/media/upload.json', 'POST', [
206
+				'media' => base64_encode(file_get_contents($status['picture'])),
207
+			]);
208
+			$params['media_ids'] = $media->media_id;
209
+		}
210
+
211
+		$response = $this->apiRequest('statuses/update.json', 'POST', $params);
212
+
213
+		return $response;
214
+	}
215
+
216
+	/**
217
+	 * {@inheritdoc}
218
+	 */
219
+	public function getUserActivity($stream = 'me')
220
+	{
221
+		$apiUrl = ($stream == 'me')
222
+			? 'statuses/user_timeline.json'
223
+			: 'statuses/home_timeline.json';
224
+
225
+		$response = $this->apiRequest($apiUrl);
226
+
227
+		if (!$response) {
228
+			return [];
229
+		}
230
+
231
+		$activities = [];
232
+
233
+		foreach ($response as $item) {
234
+			$activities[] = $this->fetchUserActivity($item);
235
+		}
236
+
237
+		return $activities;
238
+	}
239
+
240
+	/**
241
+	 * @param $item
242
+	 * @return User\Activity
243
+	 */
244
+	protected function fetchUserActivity($item)
245
+	{
246
+		$item = new Data\Collection($item);
247
+
248
+		$userActivity = new User\Activity();
249
+
250
+		$userActivity->id = $item->get('id_str');
251
+		$userActivity->date = $item->get('created_at');
252
+		$userActivity->text = $item->get('text');
253
+
254
+		$userActivity->user->identifier = $item->filter('user')->get('id_str');
255
+		$userActivity->user->displayName = $item->filter('user')->get('name');
256
+		$userActivity->user->photoURL = $item->filter('user')->get('profile_image_url');
257
+
258
+		$userActivity->user->profileURL = $item->filter('user')->get('screen_name')
259
+			? ('https://twitter.com/' . $item->filter('user')->get('screen_name'))
260
+			: '';
261
+
262
+		return $userActivity;
263
+	}
264 264
 }
Please login to merge, or discard this patch.
src/Data/Collection.php 1 patch
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -12,143 +12,143 @@
 block discarded – undo
12 12
  */
13 13
 final class Collection
14 14
 {
15
-    /**
16
-     * Data collection
17
-     *
18
-     * @var mixed
19
-     */
20
-    protected $collection = null;
21
-
22
-    /**
23
-     * @param mixed $data
24
-     */
25
-    public function __construct($data = null)
26
-    {
27
-        $this->collection = (object)$data;
28
-    }
29
-
30
-    /**
31
-     * Retrieves the whole collection as array
32
-     *
33
-     * @return mixed
34
-     */
35
-    public function toArray()
36
-    {
37
-        return (array)$this->collection;
38
-    }
39
-
40
-    /**
41
-     * Retrieves an item
42
-     *
43
-     * @param $property
44
-     *
45
-     * @return mixed
46
-     */
47
-    public function get($property)
48
-    {
49
-        if ($this->exists($property)) {
50
-            return $this->collection->$property;
51
-        }
52
-
53
-        return null;
54
-    }
55
-
56
-    /**
57
-     * Add or update an item
58
-     *
59
-     * @param $property
60
-     * @param mixed $value
61
-     */
62
-    public function set($property, $value)
63
-    {
64
-        if ($property) {
65
-            $this->collection->$property = $value;
66
-        }
67
-    }
68
-
69
-    /**
70
-     * .. until I come with a better name..
71
-     *
72
-     * @param $property
73
-     *
74
-     * @return Collection
75
-     */
76
-    public function filter($property)
77
-    {
78
-        if ($this->exists($property)) {
79
-            $data = $this->get($property);
80
-
81
-            if (!is_a($data, 'Collection')) {
82
-                $data = new Collection($data);
83
-            }
84
-
85
-            return $data;
86
-        }
87
-
88
-        return new Collection([]);
89
-    }
90
-
91
-    /**
92
-     * Checks whether an item within the collection
93
-     *
94
-     * @param $property
95
-     *
96
-     * @return bool
97
-     */
98
-    public function exists($property)
99
-    {
100
-        return property_exists($this->collection, $property);
101
-    }
102
-
103
-    /**
104
-     * Finds whether the collection is empty
105
-     *
106
-     * @return bool
107
-     */
108
-    public function isEmpty()
109
-    {
110
-        return !(bool)$this->count();
111
-    }
112
-
113
-    /**
114
-     * Count all items in collection
115
-     *
116
-     * @return int
117
-     */
118
-    public function count()
119
-    {
120
-        return count($this->properties());
121
-    }
122
-
123
-    /**
124
-     * Returns all items properties names
125
-     *
126
-     * @return array
127
-     */
128
-    public function properties()
129
-    {
130
-        $properties = [];
131
-
132
-        foreach ($this->collection as $key => $value) {
133
-            $properties[] = $key;
134
-        }
135
-
136
-        return $properties;
137
-    }
138
-
139
-    /**
140
-     * Returns all items values
141
-     *
142
-     * @return array
143
-     */
144
-    public function values()
145
-    {
146
-        $values = [];
147
-
148
-        foreach ($this->collection as $value) {
149
-            $values[] = $value;
150
-        }
151
-
152
-        return $values;
153
-    }
15
+	/**
16
+	 * Data collection
17
+	 *
18
+	 * @var mixed
19
+	 */
20
+	protected $collection = null;
21
+
22
+	/**
23
+	 * @param mixed $data
24
+	 */
25
+	public function __construct($data = null)
26
+	{
27
+		$this->collection = (object)$data;
28
+	}
29
+
30
+	/**
31
+	 * Retrieves the whole collection as array
32
+	 *
33
+	 * @return mixed
34
+	 */
35
+	public function toArray()
36
+	{
37
+		return (array)$this->collection;
38
+	}
39
+
40
+	/**
41
+	 * Retrieves an item
42
+	 *
43
+	 * @param $property
44
+	 *
45
+	 * @return mixed
46
+	 */
47
+	public function get($property)
48
+	{
49
+		if ($this->exists($property)) {
50
+			return $this->collection->$property;
51
+		}
52
+
53
+		return null;
54
+	}
55
+
56
+	/**
57
+	 * Add or update an item
58
+	 *
59
+	 * @param $property
60
+	 * @param mixed $value
61
+	 */
62
+	public function set($property, $value)
63
+	{
64
+		if ($property) {
65
+			$this->collection->$property = $value;
66
+		}
67
+	}
68
+
69
+	/**
70
+	 * .. until I come with a better name..
71
+	 *
72
+	 * @param $property
73
+	 *
74
+	 * @return Collection
75
+	 */
76
+	public function filter($property)
77
+	{
78
+		if ($this->exists($property)) {
79
+			$data = $this->get($property);
80
+
81
+			if (!is_a($data, 'Collection')) {
82
+				$data = new Collection($data);
83
+			}
84
+
85
+			return $data;
86
+		}
87
+
88
+		return new Collection([]);
89
+	}
90
+
91
+	/**
92
+	 * Checks whether an item within the collection
93
+	 *
94
+	 * @param $property
95
+	 *
96
+	 * @return bool
97
+	 */
98
+	public function exists($property)
99
+	{
100
+		return property_exists($this->collection, $property);
101
+	}
102
+
103
+	/**
104
+	 * Finds whether the collection is empty
105
+	 *
106
+	 * @return bool
107
+	 */
108
+	public function isEmpty()
109
+	{
110
+		return !(bool)$this->count();
111
+	}
112
+
113
+	/**
114
+	 * Count all items in collection
115
+	 *
116
+	 * @return int
117
+	 */
118
+	public function count()
119
+	{
120
+		return count($this->properties());
121
+	}
122
+
123
+	/**
124
+	 * Returns all items properties names
125
+	 *
126
+	 * @return array
127
+	 */
128
+	public function properties()
129
+	{
130
+		$properties = [];
131
+
132
+		foreach ($this->collection as $key => $value) {
133
+			$properties[] = $key;
134
+		}
135
+
136
+		return $properties;
137
+	}
138
+
139
+	/**
140
+	 * Returns all items values
141
+	 *
142
+	 * @return array
143
+	 */
144
+	public function values()
145
+	{
146
+		$values = [];
147
+
148
+		foreach ($this->collection as $value) {
149
+			$values[] = $value;
150
+		}
151
+
152
+		return $values;
153
+	}
154 154
 }
Please login to merge, or discard this patch.
src/HttpClient/Guzzle.php 1 patch
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -33,244 +33,244 @@
 block discarded – undo
33 33
  */
34 34
 class Guzzle implements HttpClientInterface
35 35
 {
36
-    /**
37
-     * Method request() arguments
38
-     *
39
-     * This is used for debugging.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $requestArguments = [];
44
-
45
-    /**
46
-     * Default request headers
47
-     *
48
-     * @var array
49
-     */
50
-    protected $requestHeader = [];
51
-
52
-    /**
53
-     * Raw response returned by server
54
-     *
55
-     * @var string
56
-     */
57
-    protected $responseBody = '';
58
-
59
-    /**
60
-     * Headers returned in the response
61
-     *
62
-     * @var array
63
-     */
64
-    protected $responseHeader = [];
65
-
66
-    /**
67
-     * Response HTTP status code
68
-     *
69
-     * @var int
70
-     */
71
-    protected $responseHttpCode = 0;
72
-
73
-    /**
74
-     * Last curl error number
75
-     *
76
-     * @var mixed
77
-     */
78
-    protected $responseClientError = null;
79
-
80
-    /**
81
-     * Information about the last transfer
82
-     *
83
-     * @var mixed
84
-     */
85
-    protected $responseClientInfo = [];
86
-
87
-    /**
88
-     * Hybridauth logger instance
89
-     *
90
-     * @var object
91
-     */
92
-    protected $logger = null;
93
-
94
-    /**
95
-     * GuzzleHttp client
96
-     *
97
-     * @var \GuzzleHttp\Client
98
-     */
99
-    protected $client = null;
100
-
101
-    /**
102
-     * ..
103
-     * @param null $client
104
-     * @param array $config
105
-     */
106
-    public function __construct($client = null, $config = [])
107
-    {
108
-        $this->client = $client ? $client : new Client($config);
109
-    }
110
-
111
-    /**
112
-     * {@inheritdoc}
113
-     */
114
-    public function request($uri, $method = 'GET', $parameters = [], $headers = [], $multipart = false)
115
-    {
116
-        $this->requestHeader = array_replace($this->requestHeader, (array)$headers);
117
-
118
-        $this->requestArguments = [
119
-            'uri' => $uri,
120
-            'method' => $method,
121
-            'parameters' => $parameters,
122
-            'headers' => $this->requestHeader,
123
-        ];
124
-
125
-        $response = null;
126
-
127
-        try {
128
-            switch ($method) {
129
-                case 'GET':
130
-                case 'DELETE':
131
-                    $response = $this->client->request($method, $uri, [
132
-                        'query' => $parameters,
133
-                        'headers' => $this->requestHeader,
134
-                    ]);
135
-                    break;
136
-                case 'PUT':
137
-                case 'PATCH':
138
-                case 'POST':
139
-                    $body_type = $multipart ? 'multipart' : 'form_params';
140
-
141
-                    if (isset($this->requestHeader['Content-Type'])
142
-                        && $this->requestHeader['Content-Type'] === 'application/json'
143
-                    ) {
144
-                        $body_type = 'json';
145
-                    }
146
-
147
-                    $body_content = $parameters;
148
-                    if ($multipart) {
149
-                        $body_content = [];
150
-                        foreach ($parameters as $key => $val) {
151
-                            if ($val instanceof \CURLFile) {
152
-                                $val = fopen($val->getFilename(), 'r');
153
-                            }
154
-
155
-                            $body_content[] = [
156
-                                'name' => $key,
157
-                                'contents' => $val,
158
-                            ];
159
-                        }
160
-                    }
161
-
162
-                    $response = $this->client->request($method, $uri, [
163
-                        $body_type => $body_content,
164
-                        'headers' => $this->requestHeader,
165
-                    ]);
166
-                    break;
167
-            }
168
-        } catch (\Exception $e) {
169
-            $response = $e->getResponse();
170
-
171
-            $this->responseClientError = $e->getMessage();
172
-        }
173
-
174
-        if (!$this->responseClientError) {
175
-            $this->responseBody = $response->getBody();
176
-            $this->responseHttpCode = $response->getStatusCode();
177
-            $this->responseHeader = $response->getHeaders();
178
-        }
179
-
180
-        if ($this->logger) {
181
-            // phpcs:ignore
182
-            $this->logger->debug(sprintf('%s::request( %s, %s ), response:', get_class($this), $uri, $method), $this->getResponse());
183
-
184
-            if ($this->responseClientError) {
185
-                // phpcs:ignore
186
-                $this->logger->error(sprintf('%s::request( %s, %s ), error:', get_class($this), $uri, $method), [$this->responseClientError]);
187
-            }
188
-        }
189
-
190
-        return $this->responseBody;
191
-    }
192
-
193
-    /**
194
-     * Get response details
195
-     *
196
-     * @return array Map structure of details
197
-     */
198
-    public function getResponse()
199
-    {
200
-        return [
201
-            'request' => $this->getRequestArguments(),
202
-            'response' => [
203
-                'code' => $this->getResponseHttpCode(),
204
-                'headers' => $this->getResponseHeader(),
205
-                'body' => $this->getResponseBody(),
206
-            ],
207
-            'client' => [
208
-                'error' => $this->getResponseClientError(),
209
-                'info' => $this->getResponseClientInfo(),
210
-                'opts' => null,
211
-            ],
212
-        ];
213
-    }
214
-
215
-    /**
216
-     * Set logger instance
217
-     *
218
-     * @param object $logger
219
-     */
220
-    public function setLogger($logger)
221
-    {
222
-        $this->logger = $logger;
223
-    }
224
-
225
-    /**
226
-     * {@inheritdoc}
227
-     */
228
-    public function getResponseBody()
229
-    {
230
-        return $this->responseBody;
231
-    }
232
-
233
-    /**
234
-     * {@inheritdoc}
235
-     */
236
-    public function getResponseHeader()
237
-    {
238
-        return $this->responseHeader;
239
-    }
240
-
241
-    /**
242
-     * {@inheritdoc}
243
-     */
244
-    public function getResponseHttpCode()
245
-    {
246
-        return $this->responseHttpCode;
247
-    }
248
-
249
-    /**
250
-     * {@inheritdoc}
251
-     */
252
-    public function getResponseClientError()
253
-    {
254
-        return $this->responseClientError;
255
-    }
256
-
257
-    /**
258
-     * @return array
259
-     */
260
-    protected function getResponseClientInfo()
261
-    {
262
-        return $this->responseClientInfo;
263
-    }
264
-
265
-    /**
266
-     * Returns method request() arguments
267
-     *
268
-     * This is used for debugging.
269
-     *
270
-     * @return array
271
-     */
272
-    protected function getRequestArguments()
273
-    {
274
-        return $this->requestArguments;
275
-    }
36
+	/**
37
+	 * Method request() arguments
38
+	 *
39
+	 * This is used for debugging.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $requestArguments = [];
44
+
45
+	/**
46
+	 * Default request headers
47
+	 *
48
+	 * @var array
49
+	 */
50
+	protected $requestHeader = [];
51
+
52
+	/**
53
+	 * Raw response returned by server
54
+	 *
55
+	 * @var string
56
+	 */
57
+	protected $responseBody = '';
58
+
59
+	/**
60
+	 * Headers returned in the response
61
+	 *
62
+	 * @var array
63
+	 */
64
+	protected $responseHeader = [];
65
+
66
+	/**
67
+	 * Response HTTP status code
68
+	 *
69
+	 * @var int
70
+	 */
71
+	protected $responseHttpCode = 0;
72
+
73
+	/**
74
+	 * Last curl error number
75
+	 *
76
+	 * @var mixed
77
+	 */
78
+	protected $responseClientError = null;
79
+
80
+	/**
81
+	 * Information about the last transfer
82
+	 *
83
+	 * @var mixed
84
+	 */
85
+	protected $responseClientInfo = [];
86
+
87
+	/**
88
+	 * Hybridauth logger instance
89
+	 *
90
+	 * @var object
91
+	 */
92
+	protected $logger = null;
93
+
94
+	/**
95
+	 * GuzzleHttp client
96
+	 *
97
+	 * @var \GuzzleHttp\Client
98
+	 */
99
+	protected $client = null;
100
+
101
+	/**
102
+	 * ..
103
+	 * @param null $client
104
+	 * @param array $config
105
+	 */
106
+	public function __construct($client = null, $config = [])
107
+	{
108
+		$this->client = $client ? $client : new Client($config);
109
+	}
110
+
111
+	/**
112
+	 * {@inheritdoc}
113
+	 */
114
+	public function request($uri, $method = 'GET', $parameters = [], $headers = [], $multipart = false)
115
+	{
116
+		$this->requestHeader = array_replace($this->requestHeader, (array)$headers);
117
+
118
+		$this->requestArguments = [
119
+			'uri' => $uri,
120
+			'method' => $method,
121
+			'parameters' => $parameters,
122
+			'headers' => $this->requestHeader,
123
+		];
124
+
125
+		$response = null;
126
+
127
+		try {
128
+			switch ($method) {
129
+				case 'GET':
130
+				case 'DELETE':
131
+					$response = $this->client->request($method, $uri, [
132
+						'query' => $parameters,
133
+						'headers' => $this->requestHeader,
134
+					]);
135
+					break;
136
+				case 'PUT':
137
+				case 'PATCH':
138
+				case 'POST':
139
+					$body_type = $multipart ? 'multipart' : 'form_params';
140
+
141
+					if (isset($this->requestHeader['Content-Type'])
142
+						&& $this->requestHeader['Content-Type'] === 'application/json'
143
+					) {
144
+						$body_type = 'json';
145
+					}
146
+
147
+					$body_content = $parameters;
148
+					if ($multipart) {
149
+						$body_content = [];
150
+						foreach ($parameters as $key => $val) {
151
+							if ($val instanceof \CURLFile) {
152
+								$val = fopen($val->getFilename(), 'r');
153
+							}
154
+
155
+							$body_content[] = [
156
+								'name' => $key,
157
+								'contents' => $val,
158
+							];
159
+						}
160
+					}
161
+
162
+					$response = $this->client->request($method, $uri, [
163
+						$body_type => $body_content,
164
+						'headers' => $this->requestHeader,
165
+					]);
166
+					break;
167
+			}
168
+		} catch (\Exception $e) {
169
+			$response = $e->getResponse();
170
+
171
+			$this->responseClientError = $e->getMessage();
172
+		}
173
+
174
+		if (!$this->responseClientError) {
175
+			$this->responseBody = $response->getBody();
176
+			$this->responseHttpCode = $response->getStatusCode();
177
+			$this->responseHeader = $response->getHeaders();
178
+		}
179
+
180
+		if ($this->logger) {
181
+			// phpcs:ignore
182
+			$this->logger->debug(sprintf('%s::request( %s, %s ), response:', get_class($this), $uri, $method), $this->getResponse());
183
+
184
+			if ($this->responseClientError) {
185
+				// phpcs:ignore
186
+				$this->logger->error(sprintf('%s::request( %s, %s ), error:', get_class($this), $uri, $method), [$this->responseClientError]);
187
+			}
188
+		}
189
+
190
+		return $this->responseBody;
191
+	}
192
+
193
+	/**
194
+	 * Get response details
195
+	 *
196
+	 * @return array Map structure of details
197
+	 */
198
+	public function getResponse()
199
+	{
200
+		return [
201
+			'request' => $this->getRequestArguments(),
202
+			'response' => [
203
+				'code' => $this->getResponseHttpCode(),
204
+				'headers' => $this->getResponseHeader(),
205
+				'body' => $this->getResponseBody(),
206
+			],
207
+			'client' => [
208
+				'error' => $this->getResponseClientError(),
209
+				'info' => $this->getResponseClientInfo(),
210
+				'opts' => null,
211
+			],
212
+		];
213
+	}
214
+
215
+	/**
216
+	 * Set logger instance
217
+	 *
218
+	 * @param object $logger
219
+	 */
220
+	public function setLogger($logger)
221
+	{
222
+		$this->logger = $logger;
223
+	}
224
+
225
+	/**
226
+	 * {@inheritdoc}
227
+	 */
228
+	public function getResponseBody()
229
+	{
230
+		return $this->responseBody;
231
+	}
232
+
233
+	/**
234
+	 * {@inheritdoc}
235
+	 */
236
+	public function getResponseHeader()
237
+	{
238
+		return $this->responseHeader;
239
+	}
240
+
241
+	/**
242
+	 * {@inheritdoc}
243
+	 */
244
+	public function getResponseHttpCode()
245
+	{
246
+		return $this->responseHttpCode;
247
+	}
248
+
249
+	/**
250
+	 * {@inheritdoc}
251
+	 */
252
+	public function getResponseClientError()
253
+	{
254
+		return $this->responseClientError;
255
+	}
256
+
257
+	/**
258
+	 * @return array
259
+	 */
260
+	protected function getResponseClientInfo()
261
+	{
262
+		return $this->responseClientInfo;
263
+	}
264
+
265
+	/**
266
+	 * Returns method request() arguments
267
+	 *
268
+	 * This is used for debugging.
269
+	 *
270
+	 * @return array
271
+	 */
272
+	protected function getRequestArguments()
273
+	{
274
+		return $this->requestArguments;
275
+	}
276 276
 }
Please login to merge, or discard this patch.
src/Provider/Amazon.php 1 patch
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -17,65 +17,65 @@
 block discarded – undo
17 17
  */
18 18
 class Amazon extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'profile';
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'profile';
24 24
 
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $apiBaseUrl = 'https://api.amazon.com/';
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $apiBaseUrl = 'https://api.amazon.com/';
29 29
 
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $authorizeUrl = 'https://www.amazon.com/ap/oa';
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $authorizeUrl = 'https://www.amazon.com/ap/oa';
34 34
 
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://api.amazon.com/auth/o2/token';
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://api.amazon.com/auth/o2/token';
39 39
 
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    protected $apiDocumentation = 'https://developer.amazon.com/docs/login-with-amazon/documentation-overview.html';
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	protected $apiDocumentation = 'https://developer.amazon.com/docs/login-with-amazon/documentation-overview.html';
44 44
 
45
-    /**
46
-     * {@inheritdoc}
47
-     */
48
-    protected function initialize()
49
-    {
50
-        parent::initialize();
45
+	/**
46
+	 * {@inheritdoc}
47
+	 */
48
+	protected function initialize()
49
+	{
50
+		parent::initialize();
51 51
 
52
-        if ($this->isRefreshTokenAvailable()) {
53
-            $this->tokenRefreshParameters += [
54
-                'client_id' => $this->clientId,
55
-                'client_secret' => $this->clientSecret,
56
-            ];
57
-        }
58
-    }
52
+		if ($this->isRefreshTokenAvailable()) {
53
+			$this->tokenRefreshParameters += [
54
+				'client_id' => $this->clientId,
55
+				'client_secret' => $this->clientSecret,
56
+			];
57
+		}
58
+	}
59 59
 
60
-    /**
61
-     * {@inheritdoc}
62
-     */
63
-    public function getUserProfile()
64
-    {
65
-        $response = $this->apiRequest('user/profile');
60
+	/**
61
+	 * {@inheritdoc}
62
+	 */
63
+	public function getUserProfile()
64
+	{
65
+		$response = $this->apiRequest('user/profile');
66 66
 
67
-        $data = new Data\Collection($response);
67
+		$data = new Data\Collection($response);
68 68
 
69
-        if (!$data->exists('user_id')) {
70
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
71
-        }
69
+		if (!$data->exists('user_id')) {
70
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
71
+		}
72 72
 
73
-        $userProfile = new User\Profile();
73
+		$userProfile = new User\Profile();
74 74
 
75
-        $userProfile->identifier = $data->get('user_id');
76
-        $userProfile->displayName = $data->get('name');
77
-        $userProfile->email = $data->get('email');
75
+		$userProfile->identifier = $data->get('user_id');
76
+		$userProfile->displayName = $data->get('name');
77
+		$userProfile->email = $data->get('email');
78 78
 
79
-        return $userProfile;
80
-    }
79
+		return $userProfile;
80
+	}
81 81
 }
Please login to merge, or discard this patch.
src/Provider/Spotify.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -17,77 +17,77 @@
 block discarded – undo
17 17
  */
18 18
 class Spotify extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $scope = 'user-read-email';
24
-
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    public $apiBaseUrl = 'https://api.spotify.com/v1/';
29
-
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    public $authorizeUrl = 'https://accounts.spotify.com/authorize';
34
-
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $accessTokenUrl = 'https://accounts.spotify.com/api/token';
39
-
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    protected $apiDocumentation = 'https://developer.spotify.com/documentation/general/guides/authorization-guide/';
44
-
45
-    /**
46
-     * {@inheritdoc}
47
-     */
48
-    public function getUserProfile()
49
-    {
50
-        $response = $this->apiRequest('me');
51
-
52
-        $data = new Data\Collection($response);
53
-
54
-        if (!$data->exists('id')) {
55
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
56
-        }
57
-
58
-        $userProfile = new User\Profile();
59
-
60
-        $userProfile->identifier = $data->get('id');
61
-        $userProfile->displayName = $data->get('display_name');
62
-        $userProfile->email = $data->get('email');
63
-        $userProfile->emailVerified = $data->get('email');
64
-        $userProfile->profileURL = $data->filter('external_urls')->get('spotify');
65
-        $userProfile->photoURL = $data->filter('images')->get('url');
66
-        $userProfile->country = $data->get('country');
67
-
68
-        if ($data->exists('birthdate')) {
69
-            $this->fetchBirthday($userProfile, $data->get('birthdate'));
70
-        }
71
-
72
-        return $userProfile;
73
-    }
74
-
75
-    /**
76
-     * Fetch use birthday
77
-     *
78
-     * @param User\Profile $userProfile
79
-     * @param              $birthday
80
-     *
81
-     * @return User\Profile
82
-     */
83
-    protected function fetchBirthday(User\Profile $userProfile, $birthday)
84
-    {
85
-        $result = (new Data\Parser())->parseBirthday($birthday);
86
-
87
-        $userProfile->birthDay = (int)$result[0];
88
-        $userProfile->birthMonth = (int)$result[1];
89
-        $userProfile->birthYear = (int)$result[2];
90
-
91
-        return $userProfile;
92
-    }
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $scope = 'user-read-email';
24
+
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	public $apiBaseUrl = 'https://api.spotify.com/v1/';
29
+
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	public $authorizeUrl = 'https://accounts.spotify.com/authorize';
34
+
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $accessTokenUrl = 'https://accounts.spotify.com/api/token';
39
+
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	protected $apiDocumentation = 'https://developer.spotify.com/documentation/general/guides/authorization-guide/';
44
+
45
+	/**
46
+	 * {@inheritdoc}
47
+	 */
48
+	public function getUserProfile()
49
+	{
50
+		$response = $this->apiRequest('me');
51
+
52
+		$data = new Data\Collection($response);
53
+
54
+		if (!$data->exists('id')) {
55
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
56
+		}
57
+
58
+		$userProfile = new User\Profile();
59
+
60
+		$userProfile->identifier = $data->get('id');
61
+		$userProfile->displayName = $data->get('display_name');
62
+		$userProfile->email = $data->get('email');
63
+		$userProfile->emailVerified = $data->get('email');
64
+		$userProfile->profileURL = $data->filter('external_urls')->get('spotify');
65
+		$userProfile->photoURL = $data->filter('images')->get('url');
66
+		$userProfile->country = $data->get('country');
67
+
68
+		if ($data->exists('birthdate')) {
69
+			$this->fetchBirthday($userProfile, $data->get('birthdate'));
70
+		}
71
+
72
+		return $userProfile;
73
+	}
74
+
75
+	/**
76
+	 * Fetch use birthday
77
+	 *
78
+	 * @param User\Profile $userProfile
79
+	 * @param              $birthday
80
+	 *
81
+	 * @return User\Profile
82
+	 */
83
+	protected function fetchBirthday(User\Profile $userProfile, $birthday)
84
+	{
85
+		$result = (new Data\Parser())->parseBirthday($birthday);
86
+
87
+		$userProfile->birthDay = (int)$result[0];
88
+		$userProfile->birthMonth = (int)$result[1];
89
+		$userProfile->birthYear = (int)$result[2];
90
+
91
+		return $userProfile;
92
+	}
93 93
 }
Please login to merge, or discard this patch.
src/Provider/Seznam.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -17,47 +17,47 @@
 block discarded – undo
17 17
  */
18 18
 class Seznam extends OAuth2
19 19
 {
20
-    /**
21
-     * {@inheritdoc}
22
-     */
23
-    protected $apiBaseUrl = 'https://login.szn.cz/';
24
-
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    protected $authorizeUrl = 'https://login.szn.cz/api/v1/oauth/auth';
29
-
30
-    /**
31
-     * {@inheritdoc}
32
-     */
33
-    protected $accessTokenUrl = 'https://login.szn.cz/api/v1/oauth/token';
34
-
35
-    /**
36
-     * {@inheritdoc}
37
-     */
38
-    protected $apiDocumentation = 'https://vyvojari.seznam.cz/oauth/doc';
39
-
40
-    /**
41
-     * {@inheritdoc}
42
-     */
43
-    public function getUserProfile()
44
-    {
45
-        $response = $this->apiRequest('api/v1/user', 'GET', ['format' => 'json']);
46
-
47
-        $data = new Data\Collection($response);
48
-
49
-        if (!$data->exists('oauth_user_id')) {
50
-            throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
51
-        }
52
-
53
-        $userProfile = new User\Profile();
54
-
55
-        $userProfile->identifier = $data->get('oauth_user_id');
56
-        $userProfile->email = $data->get('account_name');
57
-        $userProfile->firstName = $data->get('firstname');
58
-        $userProfile->lastName = $data->get('lastname');
59
-        $userProfile->photoURL = $data->get('avatar_url');
60
-
61
-        return $userProfile;
62
-    }
20
+	/**
21
+	 * {@inheritdoc}
22
+	 */
23
+	protected $apiBaseUrl = 'https://login.szn.cz/';
24
+
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	protected $authorizeUrl = 'https://login.szn.cz/api/v1/oauth/auth';
29
+
30
+	/**
31
+	 * {@inheritdoc}
32
+	 */
33
+	protected $accessTokenUrl = 'https://login.szn.cz/api/v1/oauth/token';
34
+
35
+	/**
36
+	 * {@inheritdoc}
37
+	 */
38
+	protected $apiDocumentation = 'https://vyvojari.seznam.cz/oauth/doc';
39
+
40
+	/**
41
+	 * {@inheritdoc}
42
+	 */
43
+	public function getUserProfile()
44
+	{
45
+		$response = $this->apiRequest('api/v1/user', 'GET', ['format' => 'json']);
46
+
47
+		$data = new Data\Collection($response);
48
+
49
+		if (!$data->exists('oauth_user_id')) {
50
+			throw new UnexpectedApiResponseException('Provider API returned an unexpected response.');
51
+		}
52
+
53
+		$userProfile = new User\Profile();
54
+
55
+		$userProfile->identifier = $data->get('oauth_user_id');
56
+		$userProfile->email = $data->get('account_name');
57
+		$userProfile->firstName = $data->get('firstname');
58
+		$userProfile->lastName = $data->get('lastname');
59
+		$userProfile->photoURL = $data->get('avatar_url');
60
+
61
+		return $userProfile;
62
+	}
63 63
 }
Please login to merge, or discard this patch.