Total Complexity | 10 |
Total Lines | 96 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
13 | class Token extends Github\Sanity |
||
14 | { |
||
15 | /** @var string */ |
||
16 | private $value; |
||
17 | |||
18 | /** @var string */ |
||
19 | private $type; |
||
20 | |||
21 | /** @var string[] */ |
||
22 | private $scopes; |
||
23 | |||
24 | |||
25 | /** |
||
26 | * @param string |
||
27 | * @param string |
||
28 | * @param string[] |
||
29 | */ |
||
30 | public function __construct($value, $type = '', array $scopes = []) |
||
31 | { |
||
32 | $this->value = $value; |
||
33 | $this->type = $type; |
||
34 | $this->scopes = $scopes; |
||
35 | } |
||
36 | |||
37 | |||
38 | /** |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getValue() |
||
42 | { |
||
43 | return $this->value; |
||
44 | } |
||
45 | |||
46 | |||
47 | /** |
||
48 | * @return string |
||
49 | */ |
||
50 | public function getType() |
||
51 | { |
||
52 | return $this->type; |
||
53 | } |
||
54 | |||
55 | |||
56 | /** |
||
57 | * @return string[] |
||
58 | */ |
||
59 | public function getScopes() |
||
60 | { |
||
61 | return $this->scopes; |
||
62 | } |
||
63 | |||
64 | |||
65 | /** |
||
66 | * @see https://developer.github.com/v3/oauth/#scopes |
||
67 | * |
||
68 | * @param string |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function hasScope($scope) |
||
72 | { |
||
73 | if (\in_array($scope, $this->scopes, TRUE)) { |
||
74 | return TRUE; |
||
75 | } |
||
76 | |||
77 | static $superiors = [ |
||
78 | 'user:email' => 'user', |
||
79 | 'user:follow' => 'user', |
||
80 | 'notifications' => 'repo', |
||
81 | ]; |
||
82 | |||
83 | if (\array_key_exists($scope, $superiors) && \in_array($superiors[$scope], $this->scopes, TRUE)) { |
||
84 | return TRUE; |
||
85 | } |
||
86 | |||
87 | return FALSE; |
||
88 | } |
||
89 | |||
90 | |||
91 | /** @internal */ |
||
92 | public function toArray() |
||
98 | ]; |
||
99 | } |
||
100 | |||
101 | |||
102 | /** @internal |
||
103 | * @param array $data |
||
104 | * @return Token |
||
105 | */ |
||
106 | public static function createFromArray(array $data) |
||
112 |