Bitbucket   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 13
c 0
b 0
f 0
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A me() 0 15 3
1
<?php
2
/**
3
 * Class Bitbucket
4
 *
5
 * @created      29.07.2019
6
 * @author       smiley <[email protected]>
7
 * @copyright    2019 smiley
8
 * @license      MIT
9
 */
10
11
namespace chillerlan\OAuth\Providers;
12
13
use chillerlan\HTTP\Utils\MessageUtil;
14
use chillerlan\OAuth\Core\{ClientCredentials, CSRFToken, OAuth2Provider, ProviderException, TokenRefresh};
15
use Psr\Http\Message\ResponseInterface;
16
use function sprintf;
17
18
/**
19
 * @see https://developer.atlassian.com/cloud/bitbucket/oauth-2/
20
 */
21
class Bitbucket extends OAuth2Provider implements ClientCredentials, CSRFToken, TokenRefresh{
22
23
	protected string  $authURL        = 'https://bitbucket.org/site/oauth2/authorize';
24
	protected string  $accessTokenURL = 'https://bitbucket.org/site/oauth2/access_token';
25
	protected string  $apiURL         = 'https://api.bitbucket.org/2.0';
26
	protected ?string $apiDocs        = 'https://developer.atlassian.com/bitbucket/api/2/reference/';
27
	protected ?string $applicationURL = 'https://developer.atlassian.com/apps/';
28
29
	/**
30
	 * @inheritDoc
31
	 */
32
	public function me():ResponseInterface{
33
		$response = $this->request('/user');
34
		$status   = $response->getStatusCode();
35
36
		if($status === 200){
37
			return $response;
38
		}
39
40
		$json = MessageUtil::decodeJSON($response);
41
42
		if(isset($json->error, $json->error->message)){
43
			throw new ProviderException($json->error->message);
44
		}
45
46
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
47
	}
48
49
}
50