Skip to content

Commit bce586a

Browse files
authored
Fix typing and syntax tests (#415)
* Update PHP CS Fixer * Remove \Random\RandomException since it doesn't exist in PHP 8.1 We will add it back when we drop support for 8.1
1 parent 761adf3 commit bce586a

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"require-dev": {
4545
"phpunit/phpunit": "^10.5.9",
4646
"phpstan/phpstan": "^1.10.57",
47-
"friendsofphp/php-cs-fixer": "^v3.48.0"
47+
"friendsofphp/php-cs-fixer": "^v3.68.3"
4848
},
4949
"autoload": {
5050
"psr-4": {

src/Encryption.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ private static function getIKM(string $userAuthToken, string $userPublicKey, str
267267
if (empty($userAuthToken)) {
268268
return $sharedSecret;
269269
}
270-
if($contentEncoding === "aesgcm") {
270+
if ($contentEncoding === "aesgcm") {
271271
$info = 'Content-Encoding: auth'.chr(0);
272-
} elseif($contentEncoding === "aes128gcm") {
272+
} elseif ($contentEncoding === "aes128gcm") {
273273
$info = "WebPush: info".chr(0).$userPublicKey.$localPublicKey;
274274
} else {
275275
throw new \ValueError("This content encoding is not supported.");

src/Subscription.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
private ?string $authToken = null,
2626
private ?string $contentEncoding = null
2727
) {
28-
if($publicKey || $authToken || $contentEncoding) {
28+
if ($publicKey || $authToken || $contentEncoding) {
2929
$supportedContentEncodings = ['aesgcm', 'aes128gcm'];
3030
if ($contentEncoding && !in_array($contentEncoding, $supportedContentEncodings, true)) {
3131
throw new \ErrorException('This content encoding ('.$contentEncoding.') is not supported.');

src/Utils.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public static function checkRequirementExtension(): void
7575
'mbstring' => '[WebPush] mbstring extension is not loaded but is required for sending push notifications with payload or for VAPID authentication. You can fix this in your php.ini.',
7676
'openssl' => '[WebPush] openssl extension is not loaded but is required for sending push notifications with payload or for VAPID authentication. You can fix this in your php.ini.',
7777
];
78-
foreach($requiredExtensions as $extension => $message) {
79-
if(!extension_loaded($extension)) {
78+
foreach ($requiredExtensions as $extension => $message) {
79+
if (!extension_loaded($extension)) {
8080
trigger_error($message, E_USER_WARNING);
8181
}
8282
}
8383

8484
// Check optional extensions.
85-
if(!extension_loaded("bcmath") && !extension_loaded("gmp")) {
85+
if (!extension_loaded("bcmath") && !extension_loaded("gmp")) {
8686
trigger_error("It is highly recommended to install the GMP or BCMath extension to speed up calculations. The fastest available calculator implementation will be automatically selected at runtime.", E_USER_NOTICE);
8787
}
8888
}
@@ -95,11 +95,11 @@ public static function checkRequirementKeyCipherHash(): void
9595
'prime256v1' => '[WebPush] Openssl does not support required curve prime256v1.',
9696
];
9797
$availableCurves = openssl_get_curve_names();
98-
if($availableCurves === false) {
98+
if ($availableCurves === false) {
9999
trigger_error('[WebPush] Openssl does not support curves.', E_USER_WARNING);
100100
} else {
101-
foreach($requiredCurves as $curve => $message) {
102-
if(!in_array($curve, $availableCurves, true)) {
101+
foreach ($requiredCurves as $curve => $message) {
102+
if (!in_array($curve, $availableCurves, true)) {
103103
trigger_error($message, E_USER_WARNING);
104104
}
105105
}
@@ -110,8 +110,8 @@ public static function checkRequirementKeyCipherHash(): void
110110
'aes-128-gcm' => '[WebPush] Openssl does not support required cipher aes-128-gcm.',
111111
];
112112
$availableCiphers = openssl_get_cipher_methods();
113-
foreach($requiredCiphers as $cipher => $message) {
114-
if(!in_array($cipher, $availableCiphers, true)) {
113+
foreach ($requiredCiphers as $cipher => $message) {
114+
if (!in_array($cipher, $availableCiphers, true)) {
115115
trigger_error($message, E_USER_WARNING);
116116
}
117117
}
@@ -121,8 +121,8 @@ public static function checkRequirementKeyCipherHash(): void
121121
'sha256' => '[WebPush] Php does not support required hmac hash sha256.',
122122
];
123123
$availableHash = hash_hmac_algos();
124-
foreach($requiredHash as $hash => $message) {
125-
if(!in_array($hash, $availableHash, true)) {
124+
foreach ($requiredHash as $hash => $message) {
125+
if (!in_array($hash, $availableHash, true)) {
126126
trigger_error($message, E_USER_WARNING);
127127
}
128128
}

src/WebPush.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ protected function createRejectedReport($reason): MessageSentReport
235235
}
236236

237237
/**
238-
* @throws \ErrorException|\Random\RandomException
238+
* @throws \ErrorException
239+
* add back @throws \Random\RandomException when we drop PHP 8.1 support
239240
*/
240241
protected function prepare(array $notifications): array
241242
{
@@ -341,10 +342,10 @@ public function setAutomaticPadding(bool|int $automaticPadding): WebPush
341342
$automaticPadding = 0;
342343
}
343344

344-
if($automaticPadding > Encryption::MAX_PAYLOAD_LENGTH) {
345+
if ($automaticPadding > Encryption::MAX_PAYLOAD_LENGTH) {
345346
throw new \ValueError('Automatic padding is too large. Max is '.Encryption::MAX_PAYLOAD_LENGTH.'. Recommended max is '.Encryption::MAX_COMPATIBILITY_PAYLOAD_LENGTH.' for compatibility reasons (see README).');
346347
}
347-
if($automaticPadding < 0) {
348+
if ($automaticPadding < 0) {
348349
throw new \ValueError('Padding length should be positive or zero.');
349350
}
350351

0 commit comments

Comments
 (0)