Passed
Push — master ( 89ee1b...86c30b )
by Francis
01:21
created
helpers/base64_helper.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@
 block discarded – undo
27 27
    *
28 28
    * @return string|bool          Decoded String.
29 29
    */
30
-  function base64url_decode(string $data, bool $strict=false) {
30
+  function base64url_decode(string $data, bool $strict = false) {
31 31
     $b64 = strtr($data, '-_', '+/');
32 32
     return base64_decode($b64, $strict);
33 33
   }
Please login to merge, or discard this patch.
phpunit/JWTTest.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
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
      * [$params Config Items.]
26 26
      *
Please login to merge, or discard this patch.
libraries/JWT.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
    */
56 56
   private $algorithm;
57 57
 
58
-  function __construct($params=null) {
58
+  function __construct($params = null) {
59 59
     if ($params != null) $this->init($params);
60 60
     get_instance()->load->splint("francis94c/ci-jwt", "%base64");
61 61
   }
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
    * @param  string     $key   Key of the item. e.g "alg", "typ".
76 76
    * @param  string|int $value Value of the item.
77 77
    */
78
-  public function header(string $key, $value=null) {
78
+  public function header(string $key, $value = null) {
79 79
     if ($value === null) return $this->header[$key];
80 80
     $this->header[$key] = $value;
81 81
   }
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
    * @param  string|int      $value JWT Claim Value.
93 93
    * @return string|int|null Value of $key if $value == null, else returns null.
94 94
    */
95
-  public function payload(string $key, $value=null) {
95
+  public function payload(string $key, $value = null) {
96 96
     if ($value === null) return $this->payload[$key];
97 97
     $this->payload[$key] = $value;
98 98
   }
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
    * @param  [type] $secret [description]
117 117
    * @return [type]         [description]
118 118
    */
119
-  public function sign(string $secret=null):?string {
119
+  public function sign(string $secret = null): ?string {
120 120
     // Checks.
121
-    if  (count($this->payload) == 0) return null;
121
+    if (count($this->payload) == 0) return null;
122 122
     // $key is $secret.
123 123
     $key = $secret ?? $this->secret;
124 124
     $this->header["alg"] = $this->header["alg"] ?? ($this->algorithm ?? self::HS512);
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
    * [token description]
140 140
    * @return string [description]
141 141
    */
142
-  public function token():?string {
142
+  public function token(): ?string {
143 143
     // Checks.
144
-    if  (count($this->payload) == 0) return null;
144
+    if (count($this->payload) == 0) return null;
145 145
     // Begin.
146 146
     $this->header["alg"] = self::NONE;
147 147
     if ($this->set_iat) $this->payload["iat"] = $this->payload["iat"] ?? time();
@@ -154,14 +154,14 @@  discard block
 block discarded – undo
154 154
    * @param  string $secret [description]
155 155
    * @return bool           [description]
156 156
    */
157
-  public function verify(string $jwt, string $secret=null):bool {
157
+  public function verify(string $jwt, string $secret = null):bool {
158 158
     if (substr_count($jwt, ".") != 2) return false; // Invalid JWT.
159 159
     $key = $secret ?? $this->secret;
160 160
     $parts = explode(".", $jwt);
161
-    $header = json_decode(base64url_decode($parts[0]) ,true);
161
+    $header = json_decode(base64url_decode($parts[0]), true);
162 162
     if ($header == null) return false;
163 163
     $alg = $header["alg"] ?? self::HS256;
164
-    $payload = json_decode(base64url_decode($parts[1]) ,true);
164
+    $payload = json_decode(base64url_decode($parts[1]), true);
165 165
     if ($payload == null) return false;
166 166
     if ($parts[2] == "") {
167 167
       return $this->allow_unsigned;
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
    * @param  string $jwt [description]
199 199
    * @return bool        [description]
200 200
    */
201
-  public function expired(string $jwt=null):bool {
201
+  public function expired(string $jwt = null):bool {
202 202
     $exp = $jwt == null ? ($this->payload["exp"] ?? time()) : $this->get_expired($jwt);
203 203
     return time() >= $exp;
204 204
   }
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
    */
221 221
   private function get_expired(string $jwt):int {
222 222
     $parts = explode(".", $jwt);
223
-    return json_decode(base64url_decode($parts[1]) ,true)["exp"] ?? time();
223
+    return json_decode(base64url_decode($parts[1]), true)["exp"] ?? time();
224 224
   }
225 225
   /**
226 226
    * [sign_token Sign JWT]
Please login to merge, or discard this patch.