@@ -38,7 +38,7 @@ class JWT
3838 *
3939 * @var int
4040 */
41- public static $ leeway = 0 ;
41+ public static int $ leeway = 0 ;
4242
4343 /**
4444 * Allow the current timestamp to be specified.
@@ -47,12 +47,12 @@ class JWT
4747 *
4848 * @var ?int
4949 */
50- public static $ timestamp = null ;
50+ public static ? int $ timestamp = null ;
5151
5252 /**
5353 * @var array<string, string[]>
5454 */
55- public static $ supported_algs = [
55+ public static array $ supported_algs = [
5656 'ES256 ' => ['openssl ' , 'SHA256 ' ],
5757 'ES256K ' => ['openssl ' , 'SHA256 ' ],
5858 'ES384 ' => ['openssl ' , 'SHA384 ' ],
@@ -70,7 +70,7 @@ class JWT
7070 * Decodes a JWT string into a PHP object.
7171 *
7272 * @param string $jwt The JWT
73- * @param Key| ArrayAccess<string,Key>|array<string,Key> $keyOrKeyArray The Key or associative array of key IDs
73+ * @param ArrayAccess<string,Key>|Key |array<string,Key> $keyOrKeyArray The Key or associative array of key IDs
7474 * (kid) to Key objects.
7575 * If the algorithm used is asymmetric, this is
7676 * the public key.
@@ -79,7 +79,7 @@ class JWT
7979 * Supported algorithms are 'ES256', 'ES256K', 'ES384', 'ES512',
8080 * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384'
8181 * and 'RS512'.
82- * @param stdClass $headers Optional. Populates stdClass with headers.
82+ * @param stdClass|null $headers Optional. Populates stdClass with headers.
8383 *
8484 * @return stdClass The JWT's payload as a PHP object
8585 *
@@ -95,9 +95,9 @@ class JWT
9595 * @uses urlsafeB64Decode
9696 */
9797 public static function decode (
98- string $ jwt ,
99- $ keyOrKeyArray ,
100- stdClass &$ headers = null
98+ string $ jwt ,
99+ array | Key | ArrayAccess $ keyOrKeyArray ,
100+ stdClass &$ headers = null
101101 ): stdClass {
102102 // Validate JWT
103103 $ timestamp = \is_null (static ::$ timestamp ) ? \time () : static ::$ timestamp ;
@@ -185,11 +185,11 @@ public static function decode(
185185 /**
186186 * Converts and signs a PHP array into a JWT string.
187187 *
188- * @param array<mixed> $payload PHP array
189- * @param string|resource |OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
188+ * @param array $payload PHP array
189+ * @param string|array |OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
190190 * @param string $alg Supported algorithms are 'ES256', 'ES256K', 'ES384', 'ES512',
191191 * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
192- * @param string $keyId
192+ * @param string|null $keyId
193193 * @param array<string, string> $head An array with header elements to attach
194194 *
195195 * @return string A signed JWT
@@ -199,7 +199,7 @@ public static function decode(
199199 */
200200 public static function encode (
201201 array $ payload ,
202- $ key ,
202+ string | array | OpenSSLAsymmetricKey | OpenSSLCertificate $ key ,
203203 string $ alg ,
204204 string $ keyId = null ,
205205 array $ head = null
@@ -227,7 +227,7 @@ public static function encode(
227227 * Sign a string with a given key and algorithm.
228228 *
229229 * @param string $msg The message to sign
230- * @param string|resource |OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
230+ * @param string|array |OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
231231 * @param string $alg Supported algorithms are 'EdDSA', 'ES256', 'ES256K', 'ES384', 'ES512',
232232 * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
233233 *
@@ -237,7 +237,7 @@ public static function encode(
237237 */
238238 public static function sign (
239239 string $ msg ,
240- $ key ,
240+ string | array | OpenSSLAsymmetricKey | OpenSSLCertificate $ key ,
241241 string $ alg
242242 ): string {
243243 if (empty (static ::$ supported_algs [$ alg ])) {
@@ -296,7 +296,7 @@ public static function sign(
296296 *
297297 * @param string $msg The original message (header and body)
298298 * @param string $signature The original signature
299- * @param string|resource |OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial For Ed*, ES*, HS*, a string key works. for RS*, must be an instance of OpenSSLAsymmetricKey
299+ * @param string|array |OpenSSLAsymmetricKey|OpenSSLCertificate $keyMaterial For Ed*, ES*, HS*, a string key works. for RS*, must be an instance of OpenSSLAsymmetricKey
300300 * @param string $alg The algorithm
301301 *
302302 * @return bool
@@ -306,7 +306,7 @@ public static function sign(
306306 private static function verify (
307307 string $ msg ,
308308 string $ signature ,
309- $ keyMaterial ,
309+ string | array | OpenSSLAsymmetricKey | OpenSSLCertificate $ keyMaterial ,
310310 string $ alg
311311 ): bool {
312312 if (empty (static ::$ supported_algs [$ alg ])) {
@@ -367,7 +367,7 @@ private static function verify(
367367 *
368368 * @throws DomainException Provided string was invalid JSON
369369 */
370- public static function jsonDecode (string $ input )
370+ public static function jsonDecode (string $ input ): mixed
371371 {
372372 $ obj = \json_decode ($ input , false , 512 , JSON_BIGINT_AS_STRING );
373373
@@ -382,7 +382,7 @@ public static function jsonDecode(string $input)
382382 /**
383383 * Encode a PHP array into a JSON string.
384384 *
385- * @param array<mixed> $input A PHP array
385+ * @param array $input A PHP array
386386 *
387387 * @return string JSON representation of the PHP array
388388 *
@@ -465,7 +465,7 @@ public static function urlsafeB64Encode(string $input): string
465465 * @return Key
466466 */
467467 private static function getKey (
468- $ keyOrKeyArray ,
468+ array | Key | ArrayAccess $ keyOrKeyArray ,
469469 ?string $ kid
470470 ): Key {
471471 if ($ keyOrKeyArray instanceof Key) {
@@ -527,11 +527,7 @@ private static function handleJsonError(int $errno): void
527527 JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON ' ,
528528 JSON_ERROR_UTF8 => 'Malformed UTF-8 characters ' //PHP >= 5.3.3
529529 ];
530- throw new DomainException (
531- isset ($ messages [$ errno ])
532- ? $ messages [$ errno ]
533- : 'Unknown JSON error: ' . $ errno
534- );
530+ throw new DomainException ($ messages [$ errno ] ?? 'Unknown JSON error: ' . $ errno );
535531 }
536532
537533 /**
0 commit comments