Skip to content

Commit 85e43e6

Browse files
authored
Add '?' to nullable method parameters (#229)
From PHP 8.4, a parameter that has null as a default value has to be typed as a nullable type.
2 parents ffa311c + ab1286b commit 85e43e6

7 files changed

Lines changed: 9 additions & 8 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
- 8.1
1414
- 8.2
1515
- 8.3
16+
- 8.4
1617
steps:
1718
- name: Checkout
1819
uses: actions/checkout@v4
@@ -51,7 +52,7 @@ jobs:
5152
- name: Setup PHP
5253
uses: shivammathur/setup-php@v2
5354
with:
54-
php-version: 8.1
55+
php-version: 8.4
5556
tools: composer
5657

5758
- name: Get Composer cache directory

src/SimpleJWT/InvalidTokenException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class InvalidTokenException extends \RuntimeException {
8787
* @param int $time for TOO_EARLY_ERROR or TOO_LATE_ERROR, the required time specified
8888
* in the token
8989
*/
90-
public function __construct(string $message = "", int $code = 0, \Exception $previous = NULL, int $time = 0) {
90+
public function __construct(string $message = "", int $code = 0, ?\Exception $previous = NULL, int $time = 0) {
9191
parent::__construct($message, $code, $previous);
9292
$this->time = $time;
9393
}

src/SimpleJWT/JWT.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function __construct(array $headers, array $claims) {
9696
* @return JWT the decoded JWT
9797
* @throws InvalidTokenException if the token is invalid for any reason
9898
*/
99-
public static function decode(string $token, KeySet $keys, string $expected_alg, string $kid = null, $skip_validation = []) {
99+
public static function decode(string $token, KeySet $keys, string $expected_alg, ?string $kid = null, $skip_validation = []) {
100100
if ($skip_validation === false) $skip_validation = [];
101101

102102
$headers = [];
@@ -204,7 +204,7 @@ public function getClaim(string $claim) {
204204
* to sign the JWT
205205
* @throws \SimpleJWT\Crypt\CryptException if there is a cryptographic error
206206
*/
207-
public function encode(KeySet $keys, ?string $kid = null, $auto_complete = ['iat', 'kid'], string $alg = null, string $format = self::COMPACT_FORMAT): string {
207+
public function encode(KeySet $keys, ?string $kid = null, $auto_complete = ['iat', 'kid'], ?string $alg = null, string $format = self::COMPACT_FORMAT): string {
208208
if ($auto_complete === false) $auto_complete = [];
209209
if ($alg != null) $this->headers['alg'] = $alg;
210210
if (in_array('iat', $auto_complete) && !isset($this->claims['iat'])) $this->claims['iat'] = time();

src/SimpleJWT/Keys/Key.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public function getKeyData(): array {
234234
* @return string the JSON web key
235235
* @throws KeyException if the key cannot be converted
236236
*/
237-
public function toJWK(string $password = null, string $format = JWE::COMPACT_FORMAT): string {
237+
public function toJWK(?string $password = null, string $format = JWE::COMPACT_FORMAT): string {
238238
$json = json_encode($this->data);
239239
if ($json == false) throw new KeyException('Cannot encode key', KeyException::INVALID_KEY_ERROR);
240240
if (($password == null) || $this->isPublic()) return $json;

src/SimpleJWT/Keys/KeyFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class KeyFactory {
103103
* @return KeyInterface the key object
104104
* @throws KeyException if an error occurs in reading the data
105105
*/
106-
static public function create($data, string $format = null, ?string $password = null, ?string $alg = 'PBES2-HS256+A128KW') {
106+
static public function create($data, ?string $format = null, ?string $password = null, ?string $alg = 'PBES2-HS256+A128KW') {
107107
$cbor = new CBOR();
108108
$cbor_item = null;
109109

src/SimpleJWT/Keys/KeySet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ function load(string $jwk, ?string $password = null, string $alg = 'PBES2-HS256+
9292
* @param string $format the serialisation format for the JWE
9393
* @return string the key set
9494
*/
95-
function toJWKS(string $password = null, string $format = JWE::COMPACT_FORMAT): string {
95+
function toJWKS(?string $password = null, string $format = JWE::COMPACT_FORMAT): string {
9696
$result = array_map(function($key) {
9797
return $key->getKeyData();
9898
}, $this->keys);

src/SimpleJWT/Util/CBOR/DataItem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class DataItem {
124124
* @param mixed $value the native PHP value
125125
* @param int $tag the tag number (i.e. excluding the class and constructed bit masks)
126126
*/
127-
function __construct(int $type, $value, int $tag = null) {
127+
function __construct(int $type, $value, ?int $tag = null) {
128128
$this->type = $type;
129129
$this->value = $value;
130130
$this->tag = $tag;

0 commit comments

Comments
 (0)