Skip to content

Commit 0ac5041

Browse files
authored
chore: styles for short array and single quotes (#423)
1 parent c297139 commit 0ac5041

File tree

4 files changed

+50
-50
lines changed

4 files changed

+50
-50
lines changed

README.md

+25-25
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ Example
2929
use Firebase\JWT\JWT;
3030
use Firebase\JWT\Key;
3131

32-
$key = "example_key";
33-
$payload = array(
34-
"iss" => "http://example.org",
35-
"aud" => "http://example.com",
36-
"iat" => 1356999524,
37-
"nbf" => 1357000000
38-
);
32+
$key = 'example_key';
33+
$payload = [
34+
'iss' => 'http://example.org',
35+
'aud' => 'http://example.com',
36+
'iat' => 1356999524,
37+
'nbf' => 1357000000
38+
];
3939

4040
/**
4141
* IMPORTANT:
@@ -98,12 +98,12 @@ ehde/zUxo6UvS7UrBQIDAQAB
9898
-----END PUBLIC KEY-----
9999
EOD;
100100

101-
$payload = array(
102-
"iss" => "example.org",
103-
"aud" => "example.com",
104-
"iat" => 1356999524,
105-
"nbf" => 1357000000
106-
);
101+
$payload = [
102+
'iss' => 'example.org',
103+
'aud' => 'example.com',
104+
'iat' => 1356999524,
105+
'nbf' => 1357000000
106+
];
107107

108108
$jwt = JWT::encode($payload, $privateKey, 'RS256');
109109
echo "Encode:\n" . print_r($jwt, true) . "\n";
@@ -139,12 +139,12 @@ $privateKey = openssl_pkey_get_private(
139139
$passphrase
140140
);
141141

142-
$payload = array(
143-
"iss" => "example.org",
144-
"aud" => "example.com",
145-
"iat" => 1356999524,
146-
"nbf" => 1357000000
147-
);
142+
$payload = [
143+
'iss' => 'example.org',
144+
'aud' => 'example.com',
145+
'iat' => 1356999524,
146+
'nbf' => 1357000000
147+
];
148148

149149
$jwt = JWT::encode($payload, $privateKey, 'RS256');
150150
echo "Encode:\n" . print_r($jwt, true) . "\n";
@@ -173,12 +173,12 @@ $privateKey = base64_encode(sodium_crypto_sign_secretkey($keyPair));
173173

174174
$publicKey = base64_encode(sodium_crypto_sign_publickey($keyPair));
175175

176-
$payload = array(
177-
"iss" => "example.org",
178-
"aud" => "example.com",
179-
"iat" => 1356999524,
180-
"nbf" => 1357000000
181-
);
176+
$payload = [
177+
'iss' => 'example.org',
178+
'aud' => 'example.com',
179+
'iat' => 1356999524,
180+
'nbf' => 1357000000
181+
];
182182

183183
$jwt = JWT::encode($payload, $privateKey, 'EdDSA');
184184
echo "Encode:\n" . print_r($jwt, true) . "\n";

src/JWT.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public static function sign(
237237
$signature = '';
238238
$success = \openssl_sign($msg, $signature, $key, $algorithm); // @phpstan-ignore-line
239239
if (!$success) {
240-
throw new DomainException("OpenSSL unable to sign data");
240+
throw new DomainException('OpenSSL unable to sign data');
241241
}
242242
if ($alg === 'ES256') {
243243
$signature = self::signatureFromDER($signature, 256);

tests/JWKTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function testDecodeByJwkKeySet()
125125

126126
$result = JWT::decode($msg, self::$keys);
127127

128-
$this->assertEquals("foo", $result->sub);
128+
$this->assertEquals('foo', $result->sub);
129129
}
130130

131131
/**
@@ -139,6 +139,6 @@ public function testDecodeByMultiJwkKeySet()
139139

140140
$result = JWT::decode($msg, self::$keys);
141141

142-
$this->assertEquals("bar", $result->sub);
142+
$this->assertEquals('bar', $result->sub);
143143
}
144144
}

tests/JWTTest.php

+22-22
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public function testExpiredToken()
3636
{
3737
$this->expectException(ExpiredException::class);
3838
$payload = [
39-
"message" => "abc",
40-
"exp" => time() - 20]; // time in the past
39+
'message' => 'abc',
40+
'exp' => time() - 20]; // time in the past
4141
$encoded = JWT::encode($payload, 'my_key', 'HS256');
4242
JWT::decode($encoded, new Key('my_key', 'HS256'));
4343
}
@@ -46,7 +46,7 @@ public function testBeforeValidTokenWithNbf()
4646
{
4747
$this->expectException(BeforeValidException::class);
4848
$payload = [
49-
"message" => "abc",
49+
'message' => 'abc',
5050
"nbf" => time() + 20]; // time in the future
5151
$encoded = JWT::encode($payload, 'my_key', 'HS256');
5252
JWT::decode($encoded, new Key('my_key', 'HS256'));
@@ -56,7 +56,7 @@ public function testBeforeValidTokenWithIat()
5656
{
5757
$this->expectException(BeforeValidException::class);
5858
$payload = [
59-
"message" => "abc",
59+
'message' => 'abc',
6060
"iat" => time() + 20]; // time in the future
6161
$encoded = JWT::encode($payload, 'my_key', 'HS256');
6262
JWT::decode($encoded, new Key('my_key', 'HS256'));
@@ -65,8 +65,8 @@ public function testBeforeValidTokenWithIat()
6565
public function testValidToken()
6666
{
6767
$payload = [
68-
"message" => "abc",
69-
"exp" => time() + JWT::$leeway + 20]; // time in the future
68+
'message' => 'abc',
69+
'exp' => time() + JWT::$leeway + 20]; // time in the future
7070
$encoded = JWT::encode($payload, 'my_key', 'HS256');
7171
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
7272
$this->assertEquals($decoded->message, 'abc');
@@ -76,8 +76,8 @@ public function testValidTokenWithLeeway()
7676
{
7777
JWT::$leeway = 60;
7878
$payload = [
79-
"message" => "abc",
80-
"exp" => time() - 20]; // time in the past
79+
'message' => 'abc',
80+
'exp' => time() - 20]; // time in the past
8181
$encoded = JWT::encode($payload, 'my_key', 'HS256');
8282
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
8383
$this->assertEquals($decoded->message, 'abc');
@@ -88,8 +88,8 @@ public function testExpiredTokenWithLeeway()
8888
{
8989
JWT::$leeway = 60;
9090
$payload = [
91-
"message" => "abc",
92-
"exp" => time() - 70]; // time far in the past
91+
'message' => 'abc',
92+
'exp' => time() - 70]; // time far in the past
9393
$this->expectException(ExpiredException::class);
9494
$encoded = JWT::encode($payload, 'my_key', 'HS256');
9595
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
@@ -100,9 +100,9 @@ public function testExpiredTokenWithLeeway()
100100
public function testValidTokenWithNbf()
101101
{
102102
$payload = [
103-
"message" => "abc",
103+
'message' => 'abc',
104104
"iat" => time(),
105-
"exp" => time() + 20, // time in the future
105+
'exp' => time() + 20, // time in the future
106106
"nbf" => time() - 20];
107107
$encoded = JWT::encode($payload, 'my_key', 'HS256');
108108
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
@@ -113,7 +113,7 @@ public function testValidTokenWithNbfLeeway()
113113
{
114114
JWT::$leeway = 60;
115115
$payload = [
116-
"message" => "abc",
116+
'message' => 'abc',
117117
"nbf" => time() + 20]; // not before in near (leeway) future
118118
$encoded = JWT::encode($payload, 'my_key', 'HS256');
119119
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
@@ -125,7 +125,7 @@ public function testInvalidTokenWithNbfLeeway()
125125
{
126126
JWT::$leeway = 60;
127127
$payload = [
128-
"message" => "abc",
128+
'message' => 'abc',
129129
"nbf" => time() + 65]; // not before too far in future
130130
$encoded = JWT::encode($payload, 'my_key', 'HS256');
131131
$this->expectException(BeforeValidException::class);
@@ -137,7 +137,7 @@ public function testValidTokenWithIatLeeway()
137137
{
138138
JWT::$leeway = 60;
139139
$payload = [
140-
"message" => "abc",
140+
'message' => 'abc',
141141
"iat" => time() + 20]; // issued in near (leeway) future
142142
$encoded = JWT::encode($payload, 'my_key', 'HS256');
143143
$decoded = JWT::decode($encoded, new Key('my_key', 'HS256'));
@@ -149,7 +149,7 @@ public function testInvalidTokenWithIatLeeway()
149149
{
150150
JWT::$leeway = 60;
151151
$payload = [
152-
"message" => "abc",
152+
'message' => 'abc',
153153
"iat" => time() + 65]; // issued too far in future
154154
$encoded = JWT::encode($payload, 'my_key', 'HS256');
155155
$this->expectException(BeforeValidException::class);
@@ -160,8 +160,8 @@ public function testInvalidTokenWithIatLeeway()
160160
public function testInvalidToken()
161161
{
162162
$payload = [
163-
"message" => "abc",
164-
"exp" => time() + 20]; // time in the future
163+
'message' => 'abc',
164+
'exp' => time() + 20]; // time in the future
165165
$encoded = JWT::encode($payload, 'my_key', 'HS256');
166166
$this->expectException(SignatureInvalidException::class);
167167
JWT::decode($encoded, new Key('my_key2', 'HS256'));
@@ -170,8 +170,8 @@ public function testInvalidToken()
170170
public function testNullKeyFails()
171171
{
172172
$payload = [
173-
"message" => "abc",
174-
"exp" => time() + JWT::$leeway + 20]; // time in the future
173+
'message' => 'abc',
174+
'exp' => time() + JWT::$leeway + 20]; // time in the future
175175
$encoded = JWT::encode($payload, 'my_key', 'HS256');
176176
$this->expectException(TypeError::class);
177177
JWT::decode($encoded, new Key(null, 'HS256'));
@@ -180,8 +180,8 @@ public function testNullKeyFails()
180180
public function testEmptyKeyFails()
181181
{
182182
$payload = [
183-
"message" => "abc",
184-
"exp" => time() + JWT::$leeway + 20]; // time in the future
183+
'message' => 'abc',
184+
'exp' => time() + JWT::$leeway + 20]; // time in the future
185185
$encoded = JWT::encode($payload, 'my_key', 'HS256');
186186
$this->expectException(InvalidArgumentException::class);
187187
JWT::decode($encoded, new Key('', 'HS256'));

0 commit comments

Comments
 (0)