diff --git a/composer.json b/composer.json index c938240..70e6b54 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "require-dev": { "phpunit/phpunit": "^10.5.9", "phpstan/phpstan": "^1.10.57", - "friendsofphp/php-cs-fixer": "^v3.48.0" + "friendsofphp/php-cs-fixer": "^v3.68.3" }, "autoload": { "psr-4": { diff --git a/src/Encryption.php b/src/Encryption.php index 89fc8e8..03d1093 100644 --- a/src/Encryption.php +++ b/src/Encryption.php @@ -267,9 +267,9 @@ private static function getIKM(string $userAuthToken, string $userPublicKey, str if (empty($userAuthToken)) { return $sharedSecret; } - if($contentEncoding === "aesgcm") { + if ($contentEncoding === "aesgcm") { $info = 'Content-Encoding: auth'.chr(0); - } elseif($contentEncoding === "aes128gcm") { + } elseif ($contentEncoding === "aes128gcm") { $info = "WebPush: info".chr(0).$userPublicKey.$localPublicKey; } else { throw new \ValueError("This content encoding is not supported."); diff --git a/src/Subscription.php b/src/Subscription.php index bad3061..571731a 100644 --- a/src/Subscription.php +++ b/src/Subscription.php @@ -25,7 +25,7 @@ public function __construct( private ?string $authToken = null, private ?string $contentEncoding = null ) { - if($publicKey || $authToken || $contentEncoding) { + if ($publicKey || $authToken || $contentEncoding) { $supportedContentEncodings = ['aesgcm', 'aes128gcm']; if ($contentEncoding && !in_array($contentEncoding, $supportedContentEncodings, true)) { throw new \ErrorException('This content encoding ('.$contentEncoding.') is not supported.'); diff --git a/src/Utils.php b/src/Utils.php index 887acb0..ecd33ab 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -75,14 +75,14 @@ public static function checkRequirementExtension(): void '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.', '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.', ]; - foreach($requiredExtensions as $extension => $message) { - if(!extension_loaded($extension)) { + foreach ($requiredExtensions as $extension => $message) { + if (!extension_loaded($extension)) { trigger_error($message, E_USER_WARNING); } } // Check optional extensions. - if(!extension_loaded("bcmath") && !extension_loaded("gmp")) { + if (!extension_loaded("bcmath") && !extension_loaded("gmp")) { 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); } } @@ -95,11 +95,11 @@ public static function checkRequirementKeyCipherHash(): void 'prime256v1' => '[WebPush] Openssl does not support required curve prime256v1.', ]; $availableCurves = openssl_get_curve_names(); - if($availableCurves === false) { + if ($availableCurves === false) { trigger_error('[WebPush] Openssl does not support curves.', E_USER_WARNING); } else { - foreach($requiredCurves as $curve => $message) { - if(!in_array($curve, $availableCurves, true)) { + foreach ($requiredCurves as $curve => $message) { + if (!in_array($curve, $availableCurves, true)) { trigger_error($message, E_USER_WARNING); } } @@ -110,8 +110,8 @@ public static function checkRequirementKeyCipherHash(): void 'aes-128-gcm' => '[WebPush] Openssl does not support required cipher aes-128-gcm.', ]; $availableCiphers = openssl_get_cipher_methods(); - foreach($requiredCiphers as $cipher => $message) { - if(!in_array($cipher, $availableCiphers, true)) { + foreach ($requiredCiphers as $cipher => $message) { + if (!in_array($cipher, $availableCiphers, true)) { trigger_error($message, E_USER_WARNING); } } @@ -121,8 +121,8 @@ public static function checkRequirementKeyCipherHash(): void 'sha256' => '[WebPush] Php does not support required hmac hash sha256.', ]; $availableHash = hash_hmac_algos(); - foreach($requiredHash as $hash => $message) { - if(!in_array($hash, $availableHash, true)) { + foreach ($requiredHash as $hash => $message) { + if (!in_array($hash, $availableHash, true)) { trigger_error($message, E_USER_WARNING); } } diff --git a/src/WebPush.php b/src/WebPush.php index 5d6aebe..e470b6e 100644 --- a/src/WebPush.php +++ b/src/WebPush.php @@ -235,7 +235,8 @@ protected function createRejectedReport($reason): MessageSentReport } /** - * @throws \ErrorException|\Random\RandomException + * @throws \ErrorException + * add back @throws \Random\RandomException when we drop PHP 8.1 support */ protected function prepare(array $notifications): array { @@ -341,10 +342,10 @@ public function setAutomaticPadding(bool|int $automaticPadding): WebPush $automaticPadding = 0; } - if($automaticPadding > Encryption::MAX_PAYLOAD_LENGTH) { + if ($automaticPadding > Encryption::MAX_PAYLOAD_LENGTH) { 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).'); } - if($automaticPadding < 0) { + if ($automaticPadding < 0) { throw new \ValueError('Padding length should be positive or zero.'); }