Skip to content

Fix typing and syntax tests #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions src/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
2 changes: 1 addition & 1 deletion src/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
20 changes: 10 additions & 10 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/WebPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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.');
}

Expand Down