@@ -20,7 +20,7 @@ |
||
20 | 20 | * @covers JWT::__construct |
21 | 21 | */ |
22 | 22 | public static function setUpBeforeClass(): void { |
23 | - self::$ci =& get_instance(); |
|
23 | + self::$ci = & get_instance(); |
|
24 | 24 | } |
25 | 25 | /** |
26 | 26 | * [testLoadPackage description] |
@@ -10,12 +10,12 @@ |
||
10 | 10 | private $method; |
11 | 11 | private $userAgent; |
12 | 12 | |
13 | - function __construct(string $method, string $userAgent='CodeIgniter GMail API') { |
|
13 | + function __construct(string $method, string $userAgent = 'CodeIgniter GMail API') { |
|
14 | 14 | $this->method = $method; |
15 | 15 | $this->userAgent = $userAgent; |
16 | 16 | } |
17 | 17 | |
18 | - function __invoke(string $url, array $header=[], mixed $body=null):array { |
|
18 | + function __invoke(string $url, array $header = [], mixed $body = null):array { |
|
19 | 19 | if ($body != null) $body = json_encode($body); |
20 | 20 | |
21 | 21 | $ch = curl_init($url); |
@@ -16,7 +16,9 @@ discard block |
||
16 | 16 | } |
17 | 17 | |
18 | 18 | function __invoke(string $url, array $header=[], mixed $body=null):array { |
19 | - if ($body != null) $body = json_encode($body); |
|
19 | + if ($body != null) { |
|
20 | + $body = json_encode($body); |
|
21 | + } |
|
20 | 22 | |
21 | 23 | $ch = curl_init($url); |
22 | 24 | |
@@ -29,7 +31,9 @@ discard block |
||
29 | 31 | // Header. |
30 | 32 | $header[] = 'Content-Type: application/json'; |
31 | 33 | $header[] = 'Content-Length: 0'; |
32 | - if ($body != null) $header[] = 'Content-Length: '.strlen($body); |
|
34 | + if ($body != null) { |
|
35 | + $header[] = 'Content-Length: '.strlen($body); |
|
36 | + } |
|
33 | 37 | curl_setopt($ch, CURLOPT_HTTPHEADER, $header); |
34 | 38 | curl_setopt(CURLOPT_USERAGENT, $this->userAgent); |
35 | 39 | // Request Method and Body. |
@@ -9,10 +9,10 @@ |
||
9 | 9 | * @param boolean $urlEncode [description] |
10 | 10 | * @return string [description] |
11 | 11 | */ |
12 | - function build_url_query(array $params, bool $urlEncode=true):?string { |
|
12 | + function build_url_query(array $params, bool $urlEncode = true): ?string { |
|
13 | 13 | if ($params == null) return null; |
14 | 14 | $queryString = '?'; |
15 | - foreach($params as $key => $val) { |
|
15 | + foreach ($params as $key => $val) { |
|
16 | 16 | $queryString .= $key."=".($urlEncode ? rawurlencode($val) : $val)."&"; |
17 | 17 | } |
18 | 18 | return substr($queryString, 0, strlen($queryString) - 1); |
@@ -10,7 +10,9 @@ |
||
10 | 10 | * @return string [description] |
11 | 11 | */ |
12 | 12 | function build_url_query(array $params, bool $urlEncode=true):?string { |
13 | - if ($params == null) return null; |
|
13 | + if ($params == null) { |
|
14 | + return null; |
|
15 | + } |
|
14 | 16 | $queryString = '?'; |
15 | 17 | foreach($params as $key => $val) { |
16 | 18 | $queryString .= $key."=".($urlEncode ? rawurlencode($val) : $val)."&"; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | private $redirectUri = 'urn:ietf:wg:oauth:2.0:oob'; |
17 | 17 | private $token; |
18 | 18 | |
19 | - function __construct($params=null) { |
|
19 | + function __construct($params = null) { |
|
20 | 20 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
21 | 21 | if ($params != null) $this->init($params); |
22 | 22 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * [getClientId Get Client ID.] |
43 | 43 | * @return null|string Client ID. |
44 | 44 | */ |
45 | - public function getClientId():?string { |
|
45 | + public function getClientId(): ?string { |
|
46 | 46 | return $this->clientId; |
47 | 47 | } |
48 | 48 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @param bool $prompt Add the prompt=consent query to the URL. |
56 | 56 | * @return string Authorize URL |
57 | 57 | */ |
58 | - public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string { |
|
58 | + public function getAuthorizeUrl(string $scope, string $redirectUri = null, string $responseType = 'code', string $accessType = 'offline', bool $prompt = false):string { |
|
59 | 59 | $redirectUri = $redirectUri ?? $this->redirectUri; |
60 | 60 | if ($scope == null) throw new Exception("GMail scope cannot be null"); |
61 | 61 | $params = [ |
@@ -66,17 +66,17 @@ discard block |
||
66 | 66 | 'access_type' => $accessType |
67 | 67 | ]; |
68 | 68 | if ($prompt) $params['prompt'] = 'consent'; |
69 | - return self::AUTH_URL . build_url_query($params, false); |
|
69 | + return self::AUTH_URL.build_url_query($params, false); |
|
70 | 70 | } |
71 | 71 | /** |
72 | 72 | * [getToken description] |
73 | 73 | * @param string $code [description] |
74 | 74 | * @return [type] [description] |
75 | 75 | */ |
76 | - public function getToken(string $code, string $redirectUri=null):?array { |
|
76 | + public function getToken(string $code, string $redirectUri = null): ?array { |
|
77 | 77 | $redirectUri = $redirectUri ?? $this->redirectUri; |
78 | 78 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
79 | - self::TOKEN_URL . build_url_query([ |
|
79 | + self::TOKEN_URL.build_url_query([ |
|
80 | 80 | 'code' => $code, |
81 | 81 | 'client_id' => $this->clientId, |
82 | 82 | 'client_secret' => $this->clientSecret, |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | * @param string $user [description] |
93 | 93 | * @return [type] [description] |
94 | 94 | */ |
95 | - public function getProfile(string $user='me'):?array { |
|
95 | + public function getProfile(string $user = 'me'): ?array { |
|
96 | 96 | list($code, $response) = (new GMailCURL(GMailCURL::GET))( |
97 | - self::API . "$user/profile", |
|
97 | + self::API."$user/profile", |
|
98 | 98 | ["Authorization: Bearer $this->token"] |
99 | 99 | ); |
100 | 100 | if ($response !== false) return $this->process_response($code, $response); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string $labelFilterAction [description] |
113 | 113 | * @return [type] [description] |
114 | 114 | */ |
115 | - public function watch(string $topic, string $userId='me', mixed $labelIds=null, string $labelFilterAction='include'):?array { |
|
115 | + public function watch(string $topic, string $userId = 'me', mixed $labelIds = null, string $labelFilterAction = 'include'): ?array { |
|
116 | 116 | $body = [ |
117 | 117 | 'topicName' => $topic, |
118 | 118 | 'labelFilterAction' => $labelFilterAction |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | } |
128 | 128 | |
129 | 129 | list($code, $response) = (new GMailCURL(GMailCURL::POST))( |
130 | - self::API . "$userId/watch", |
|
130 | + self::API."$userId/watch", |
|
131 | 131 | ["Authorization: Bearer $this->token"], |
132 | 132 | $body |
133 | 133 | ); |
@@ -18,7 +18,9 @@ discard block |
||
18 | 18 | |
19 | 19 | function __construct($params=null) { |
20 | 20 | get_instance()->load->splint('francis94c/ci-gmail', '%curl'); |
21 | - if ($params != null) $this->init($params); |
|
21 | + if ($params != null) { |
|
22 | + $this->init($params); |
|
23 | + } |
|
22 | 24 | } |
23 | 25 | |
24 | 26 | /** |
@@ -57,7 +59,9 @@ discard block |
||
57 | 59 | */ |
58 | 60 | public function getAuthorizeUrl(string $scope, string $redirectUri=null, string $responseType='code', string $accessType='offline', bool $prompt=false):string { |
59 | 61 | $redirectUri = $redirectUri ?? $this->redirectUri; |
60 | - if ($scope == null) throw new Exception("GMail scope cannot be null"); |
|
62 | + if ($scope == null) { |
|
63 | + throw new Exception("GMail scope cannot be null"); |
|
64 | + } |
|
61 | 65 | $params = [ |
62 | 66 | 'client_id' => $this->clientId, |
63 | 67 | 'redirect_uri' => $redirectUri, |
@@ -65,7 +69,9 @@ discard block |
||
65 | 69 | 'response_type' => $responseType, |
66 | 70 | 'access_type' => $accessType |
67 | 71 | ]; |
68 | - if ($prompt) $params['prompt'] = 'consent'; |
|
72 | + if ($prompt) { |
|
73 | + $params['prompt'] = 'consent'; |
|
74 | + } |
|
69 | 75 | return self::AUTH_URL . build_url_query($params, false); |
70 | 76 | } |
71 | 77 | /** |
@@ -84,7 +90,9 @@ discard block |
||
84 | 90 | 'grant_type' => 'authorization_code' |
85 | 91 | ], false) |
86 | 92 | ); |
87 | - if ($response !== false)$this->process_response($code, $response); |
|
93 | + if ($response !== false) { |
|
94 | + $this->process_response($code, $response); |
|
95 | + } |
|
88 | 96 | return null; |
89 | 97 | } |
90 | 98 | /** |
@@ -97,7 +105,9 @@ discard block |
||
97 | 105 | self::API . "$user/profile", |
98 | 106 | ["Authorization: Bearer $this->token"] |
99 | 107 | ); |
100 | - if ($response !== false) return $this->process_response($code, $response); |
|
108 | + if ($response !== false) { |
|
109 | + return $this->process_response($code, $response); |
|
110 | + } |
|
101 | 111 | return null; |
102 | 112 | } |
103 | 113 | /** |
@@ -131,7 +141,9 @@ discard block |
||
131 | 141 | ["Authorization: Bearer $this->token"], |
132 | 142 | $body |
133 | 143 | ); |
134 | - if ($response !== false)$this->process_response($code, $response); |
|
144 | + if ($response !== false) { |
|
145 | + $this->process_response($code, $response); |
|
146 | + } |
|
135 | 147 | return null; |
136 | 148 | } |
137 | 149 | /** |