@@ -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 ' ],
@@ -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 *
@@ -96,7 +96,7 @@ class JWT
9696 */
9797 public static function decode (
9898 string $ jwt ,
99- $ keyOrKeyArray ,
99+ Key | ArrayAccess | array $ keyOrKeyArray ,
100100 ?stdClass &$ headers = null
101101 ): stdClass {
102102 // Validate JWT
@@ -185,12 +185,12 @@ 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.
190- * @param string $alg Supported algorithms are 'ES256', 'ES256K', 'ES384', 'ES512',
191- * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
192- * @param string $keyId
193- * @param array<string, string> $head An array with header elements to attach
188+ * @param array $payload PHP array
189+ * @param string|array |OpenSSLAsymmetricKey|OpenSSLCertificate $key The secret key.
190+ * @param string $alg Supported algorithms are 'ES256', 'ES256K', 'ES384', 'ES512',
191+ * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
192+ * @param string|null $keyId
193+ * @param array<string, string>|null $head An array with header elements to attach
194194 *
195195 * @return string A signed JWT
196196 *
@@ -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,17 +227,17 @@ 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',
232- * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
232+ * 'HS256', 'HS384', 'HS512', 'RS256', 'RS384', and 'RS512'
233233 *
234234 * @return string An encrypted message
235235 *
236236 * @throws DomainException Unsupported algorithm or bad key was specified
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 *
@@ -460,7 +460,7 @@ public static function urlsafeB64Encode(string $input): string
460460 * @return Key
461461 */
462462 private static function getKey (
463- $ keyOrKeyArray ,
463+ Key | ArrayAccess | array $ keyOrKeyArray ,
464464 ?string $ kid
465465 ): Key {
466466 if ($ keyOrKeyArray instanceof Key) {
@@ -522,11 +522,7 @@ private static function handleJsonError(int $errno): void
522522 JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON ' ,
523523 JSON_ERROR_UTF8 => 'Malformed UTF-8 characters ' //PHP >= 5.3.3
524524 ];
525- throw new DomainException (
526- isset ($ messages [$ errno ])
527- ? $ messages [$ errno ]
528- : 'Unknown JSON error: ' . $ errno
529- );
525+ throw new DomainException ($ messages [$ errno ] ?? 'Unknown JSON error: ' . $ errno );
530526 }
531527
532528 /**
0 commit comments