Completed
Push — fix/videopress-flash-rss ( 410f56...198f69 )
by
unknown
19:49 queued 09:08
created

sal/class.json-api-token.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * So that we have a real class instead of just passing around an array
5
 */
6
class SAL_Token {
7
8
	public $blog_id;
9
	public $user_id;
10
	public $scope;
11
	public $client_id;
12
	public $external_user_id;
13
	public $external_user_code;
14
	public $auth_type;
15
16
	function __construct( $blog_id, $user_id, $scope, $client_id, $external_user_id, $external_user_code, $auth_type ) {
17
		$this->blog_id = $blog_id; // if blog_id is set and scope is not global, limit to that blog
18
		$this->user_id = $user_id;
19
		$this->client_id = $client_id;
20
		$this->scope = $scope; 
21
		$this->external_user_id = $external_user_id;
22
		$this->external_user_code = $external_user_code;
23
		$this->auth_type = $auth_type;
24
	}
25
26
	public function is_global() {
27
		return $scope === 'global';
0 ignored issues
show
The variable $scope does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
28
	}
29
30
	static function for_anonymous_user() {
31
		return new SAL_Token( 
32
			null, 
33
			get_current_user_id(), 
34
			null, // there's only ever one scope in our current API implementation, auth or global
35
			null,
36
			null, 
37
			null, 
38
			null
39
		);
40
	}
41
42
	static function from_rest_token( $token ) {
43
		return new SAL_Token( 
44
			$token['blog_id'], 
45
			$token['user_id'], 
46
			$token['scope'][0], // there's only ever one scope in our current API implementation, auth or global
47
			$token['client_id'],
48
			$token['external_user_id'], 
49
			$token['external_user_code'], 
50
			$token['auth']
51
		);
52
	}
53
}