Passed
Push — master ( a4eab4...2d0f29 )
by Francis
06:19
created
libraries/JWT.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
    * @date  2020-03-28
70 70
    * @param [type]     $params [description]
71 71
    */
72
-  public function __construct(?array $params=null)
72
+  public function __construct(?array $params = null)
73 73
   {
74 74
     if ($params != null) $this->init($params);
75 75
     get_instance()->load->splint("francis94c/ci-jwt", "%base64");
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
    * @param  string     $key   Key of the item. e.g "alg", "typ".
91 91
    * @param  string|int $value Value of the item.
92 92
    */
93
-  public function header(string $key, $value=null) {
93
+  public function header(string $key, $value = null) {
94 94
     if ($value === null) return $this->header[$key];
95 95
     $this->header[$key] = $value;
96 96
   }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
    * @return mixed|none         Value of $key if $value == null, else
109 109
    *                            returns none[NOTHING].
110 110
    */
111
-  public function payload(string $key, $value=null) {
111
+  public function payload(string $key, $value = null) {
112 112
     if ($value === null) return $this->payload[$key];
113 113
     $this->payload[$key] = $value;
114 114
   }
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
    * @return mixed|none      Value of the 'iss' claim, if the $iss argument wasn't
119 119
    *                         supplied. Otherwise, null.
120 120
    */
121
-  public function iss(string $iss=null) {
121
+  public function iss(string $iss = null) {
122 122
     if ($iss === null) return $this->payload['iss'];
123 123
     $this->payload['iss'] = $iss;
124 124
   }
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
    * @param  [type] $secret [description]
143 143
    * @return [type]         [description]
144 144
    */
145
-  public function sign(string $secret=null):?string {
145
+  public function sign(string $secret = null): ?string {
146 146
     // Checks.
147
-    if  (count($this->payload) == 0) return null;
147
+    if (count($this->payload) == 0) return null;
148 148
     // $key is $secret.
149 149
     $key = $secret ?? $this->secret;
150 150
     $this->header["alg"] = $this->header["alg"] ?? ($this->algorithm ?? self::HS512);
@@ -165,9 +165,9 @@  discard block
 block discarded – undo
165 165
    * [token description]
166 166
    * @return string [description]
167 167
    */
168
-  public function token():?string {
168
+  public function token(): ?string {
169 169
     // Checks.
170
-    if  (count($this->payload) == 0) return null;
170
+    if (count($this->payload) == 0) return null;
171 171
     // Begin.
172 172
     $this->header["alg"] = self::NONE;
173 173
     if ($this->set_iat) $this->payload["iat"] = $this->payload["iat"] ?? time();
@@ -181,14 +181,14 @@  discard block
 block discarded – undo
181 181
    * @param  string $secret [description]
182 182
    * @return bool           [description]
183 183
    */
184
-  public function verify(string $jwt, string $secret=null):bool {
184
+  public function verify(string $jwt, string $secret = null):bool {
185 185
     if (substr_count($jwt, ".") != 2) return false; // Invalid JWT.
186 186
     $key = $secret ?? $this->secret;
187 187
     $parts = explode(".", $jwt);
188
-    $header = json_decode(base64url_decode($parts[0]) ,true);
188
+    $header = json_decode(base64url_decode($parts[0]), true);
189 189
     if ($header == null) return false;
190 190
     $alg = $this->algorithm ?? $header["alg"] ?? self::HS256;
191
-    $payload = json_decode(base64url_decode($parts[1]) ,true);
191
+    $payload = json_decode(base64url_decode($parts[1]), true);
192 192
     if ($payload == null) return false;
193 193
     if ($parts[2] == "") {
194 194
       return $this->allow_unsigned;
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
    * @param  string $jwt [description]
226 226
    * @return bool        [description]
227 227
    */
228
-  public function expired(string $jwt=null):bool {
228
+  public function expired(string $jwt = null):bool {
229 229
     $exp = $jwt == null ? ($this->payload["exp"] ?? time()) : $this->get_expired($jwt);
230 230
     return time() >= $exp;
231 231
   }
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
    */
248 248
   private function get_expired(string $jwt):int {
249 249
     $parts = explode(".", $jwt);
250
-    return json_decode(base64url_decode($parts[1]) ,true)["exp"] ?? time();
250
+    return json_decode(base64url_decode($parts[1]), true)["exp"] ?? time();
251 251
   }
252 252
   /**
253 253
    * [sign_token Sign JWT]
Please login to merge, or discard this patch.