Passed
Push — main ( e868ec...9f95cc )
by smiley
12:00
created

Twitter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 15
c 1
b 0
f 0
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A me() 0 15 3
1
<?php
2
/**
3
 * Class Twitter
4
 *
5
 *
6
 * @created      08.04.2018
7
 * @author       Smiley <[email protected]>
8
 * @copyright    2018 Smiley
9
 * @license      MIT
10
 */
11
12
namespace chillerlan\OAuth\Providers;
13
14
use chillerlan\HTTP\Utils\MessageUtil;
15
use chillerlan\OAuth\Core\OAuth1Provider;
16
use chillerlan\OAuth\Core\ProviderException;
17
use Psr\Http\Message\ResponseInterface;
18
use function sprintf;
19
20
/**
21
 * @see https://developer.twitter.com/en/docs/basics/authentication/overview/oauth
22
 */
23
class Twitter extends OAuth1Provider{
24
25
	// choose your fighter
26
	/** @see https://developer.twitter.com/en/docs/basics/authentication/api-reference/authorize */
27
	protected string $authURL          = 'https://api.twitter.com/oauth/authorize';
28
	/** @see https://developer.twitter.com/en/docs/basics/authentication/api-reference/authenticate */
29
#	protected string $authURL          = 'https://api.twitter.com/oauth/authenticate';
30
31
	protected string  $requestTokenURL = 'https://api.twitter.com/oauth/request_token';
32
	protected string  $accessTokenURL  = 'https://api.twitter.com/oauth/access_token';
33
	protected string  $apiURL          = 'https://api.twitter.com';
34
	protected ?string $userRevokeURL   = 'https://twitter.com/settings/applications';
35
	protected ?string $apiDocs         = 'https://developer.twitter.com/docs';
36
	protected ?string $applicationURL  = 'https://developer.twitter.com/apps';
37
38
	/**
39
	 * @inheritDoc
40
	 */
41
	public function me():ResponseInterface{
42
		$response = $this->request('/1.1/account/verify_credentials.json');
43
		$status   = $response->getStatusCode();
44
45
		if($status === 200){
46
			return $response;
47
		}
48
49
		$json = MessageUtil::decodeJSON($response);
50
51
		if(isset($json->errors, $json->errors[0]->message)){
52
			throw new ProviderException($json->errors[0]->message);
53
		}
54
55
		throw new ProviderException(sprintf('user info error error HTTP/%s', $status));
56
	}
57
58
}
59