Passed
Branch main (d68b9c)
by smiley
09:54
created

Foursquare   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 14
c 1
b 0
f 0
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A request() 0 14 1
1
<?php
2
/**
3
 * Class Foursquare
4
 *
5
 * @link https://developer.foursquare.com/docs/
6
 * @link https://developer.foursquare.com/overview/auth
7
 *
8
 * @filesource   Foursquare.php
9
 * @created      10.08.2018
10
 * @package      chillerlan\OAuth\Providers\Foursquare
11
 * @author       Smiley <[email protected]>
12
 * @copyright    2018 Smiley
13
 * @license      MIT
14
 */
15
16
namespace chillerlan\OAuth\Providers\Foursquare;
17
18
use chillerlan\OAuth\Core\OAuth2Provider;
19
use Psr\Http\Message\ResponseInterface;
20
21
use function array_merge, explode, parse_str, parse_url;
22
23
use const PHP_URL_QUERY;
24
25
/**
26
 * @method \Psr\Http\Message\ResponseInterface me()
27
 */
28
class Foursquare extends OAuth2Provider{
29
30
	protected const API_VERSIONDATE = '20190225';
31
32
	protected string $authURL         = 'https://foursquare.com/oauth2/authenticate';
33
	protected string $accessTokenURL  = 'https://foursquare.com/oauth2/access_token';
34
	protected ?string $apiURL         = 'https://api.foursquare.com/v2';
35
	protected ?string $userRevokeURL  = 'https://foursquare.com/settings/connections';
36
	protected ?string $endpointMap    = FoursquareEndpoints::class;
37
	protected ?string $apiDocs        = 'https://developer.foursquare.com/docs';
38
	protected ?string $applicationURL = 'https://foursquare.com/developers/apps';
39
	protected string $authMethodQuery = 'oauth_token';
40
	protected int $authMethod         = self::AUTH_METHOD_QUERY;
41
42
	/**
43
	 * @inheritDoc
44
	 */
45
	public function request(
46
		string $path,
47
		array $params = null,
48
		string $method = null,
49
		$body = null,
50
		array $headers = null
51
	):ResponseInterface{
52
53
		parse_str(parse_url($this->apiURL.$path, PHP_URL_QUERY), $query);
54
55
		$query['v'] = $this::API_VERSIONDATE;
56
		$query['m'] = 'foursquare';
57
58
		return parent::request(explode('?', $path)[0], array_merge($params ?? [], $query), $method, $body, $headers);
59
	}
60
61
}
62