Skip to content

Commit f8550f8

Browse files
authored
feat: add typing, require PHP 8.0 (#385)
1 parent 8bcbcf8 commit f8550f8

File tree

7 files changed

+239
-277
lines changed

7 files changed

+239
-277
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
php: [ "5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1"]
13+
php: [ "8.0", "8.1"]
1414
name: PHP ${{matrix.php }} Unit Test
1515
steps:
1616
- uses: actions/checkout@v2
@@ -24,45 +24,9 @@ jobs:
2424
timeout_minutes: 10
2525
max_attempts: 3
2626
command: composer install
27-
- if: ${{ matrix.php == '5.6' }}
28-
run: composer require --dev --with-dependencies paragonie/sodium_compat
2927
- name: Run Script
3028
run: vendor/bin/phpunit
3129

32-
# use dockerfiles for old versions of php (setup-php times out for those).
33-
test_php55:
34-
name: "PHP 5.5 Unit Test"
35-
runs-on: ubuntu-latest
36-
steps:
37-
- name: Checkout
38-
uses: actions/checkout@v2
39-
- name: Run Unit Tests
40-
uses: docker://php:5.5-cli
41-
with:
42-
entrypoint: ./.github/actions/entrypoint.sh
43-
44-
test_php54:
45-
name: "PHP 5.4 Unit Test"
46-
runs-on: ubuntu-latest
47-
steps:
48-
- name: Checkout
49-
uses: actions/checkout@v2
50-
- name: Run Unit Tests
51-
uses: docker://php:5.4-cli
52-
with:
53-
entrypoint: ./.github/actions/entrypoint.sh
54-
55-
test_php53:
56-
name: "PHP 5.3 Unit Test"
57-
runs-on: ubuntu-latest
58-
steps:
59-
- name: Checkout
60-
uses: actions/checkout@v2
61-
- name: Run Unit Tests
62-
uses: docker://tomsowerby/php-5.3:cli
63-
with:
64-
entrypoint: ./.github/actions/entrypoint.sh
65-
6630
style:
6731
runs-on: ubuntu-latest
6832
name: PHP Style Check
@@ -71,7 +35,7 @@ jobs:
7135
- name: Setup PHP
7236
uses: shivammathur/setup-php@v2
7337
with:
74-
php-version: "7.0"
38+
php-version: "8.0"
7539
- name: Run Script
7640
run: |
7741
composer require friendsofphp/php-cs-fixer

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"license": "BSD-3-Clause",
2222
"require": {
23-
"php": ">=5.3.0"
23+
"php": "^8.0"
2424
},
2525
"suggest": {
2626
"paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present"
@@ -31,6 +31,6 @@
3131
}
3232
},
3333
"require-dev": {
34-
"phpunit/phpunit": ">=4.8 <=9"
34+
"phpunit/phpunit": "^9.5"
3535
}
3636
}

src/JWK.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ class JWK
3333
*
3434
* @uses parseKey
3535
*/
36-
public static function parseKeySet(array $jwks)
36+
public static function parseKeySet(array $jwks): array
3737
{
38-
$keys = array();
38+
$keys = [];
3939

4040
if (!isset($jwks['keys'])) {
4141
throw new UnexpectedValueException('"keys" member must exist in the JWK Set');
4242
}
43+
4344
if (empty($jwks['keys'])) {
4445
throw new InvalidArgumentException('JWK Set did not contain any keys');
4546
}
@@ -71,14 +72,16 @@ public static function parseKeySet(array $jwks)
7172
*
7273
* @uses createPemFromModulusAndExponent
7374
*/
74-
public static function parseKey(array $jwk)
75+
public static function parseKey(array $jwk): ?Key
7576
{
7677
if (empty($jwk)) {
7778
throw new InvalidArgumentException('JWK must not be empty');
7879
}
80+
7981
if (!isset($jwk['kty'])) {
8082
throw new UnexpectedValueException('JWK must contain a "kty" parameter');
8183
}
84+
8285
if (!isset($jwk['alg'])) {
8386
// The "alg" parameter is optional in a KTY, but is required for parsing in
8487
// this library. Add it manually to your JWK array if it doesn't already exist.
@@ -107,6 +110,8 @@ public static function parseKey(array $jwk)
107110
// Currently only RSA is supported
108111
break;
109112
}
113+
114+
return null;
110115
}
111116

112117
/**
@@ -124,10 +129,10 @@ private static function createPemFromModulusAndExponent($n, $e)
124129
$modulus = JWT::urlsafeB64Decode($n);
125130
$publicExponent = JWT::urlsafeB64Decode($e);
126131

127-
$components = array(
132+
$components = [
128133
'modulus' => \pack('Ca*a*', 2, self::encodeLength(\strlen($modulus)), $modulus),
129134
'publicExponent' => \pack('Ca*a*', 2, self::encodeLength(\strlen($publicExponent)), $publicExponent)
130-
);
135+
];
131136

132137
$rsaPublicKey = \pack(
133138
'Ca*a*a*',

0 commit comments

Comments
 (0)