Skip to content
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
7 changes: 5 additions & 2 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

$config = new PhpCsFixer\Config();
$rules = [
'@PSR12' => true, // The default rule.
'@PER-CS3x0' => true, // The default rule.
'@autoPHPMigration' => true, // Uses min PHP version for regular migrations.
'blank_line_after_opening_tag' => false, // Do not waste space between <?php and declare.
'declare_strict_types' => true,
'concat_space' => ['spacing' => 'none'], // Custom library style.
'declare_strict_types' => true, // Enforce strict code.
'global_namespace_import' => ['import_classes' => false, 'import_constants' => false, 'import_functions' => false],
'php_unit_attributes' => true,
'php_unit_construct' => true,
Expand All @@ -20,5 +21,7 @@
$config->setRules($rules);
$config->setHideProgress(true);
$config->setRiskyAllowed(true);
$config->setUsingCache(false);
$config->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect());

return $config;
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
}
],
"scripts": {
"fix:syntax": "./vendor/bin/php-cs-fixer fix ./src --using-cache=no",
"fix:syntax_tests": "./vendor/bin/php-cs-fixer fix ./tests --using-cache=no",
"fix:syntax": "./vendor/bin/php-cs-fixer fix ./src",
"fix:syntax_tests": "./vendor/bin/php-cs-fixer fix ./tests",
"test:unit": "./vendor/bin/phpunit",
"test:unit_offline": "./vendor/bin/phpunit --exclude-group=online",
"test:typing": "./vendor/bin/phpstan analyse",
"test:syntax": "./vendor/bin/php-cs-fixer fix ./src --dry-run --stop-on-violation --using-cache=no",
"test:syntax_tests": "./vendor/bin/php-cs-fixer fix ./tests --dry-run --stop-on-violation --using-cache=no"
"test:syntax": "./vendor/bin/php-cs-fixer fix ./src --dry-run --stop-on-violation",
"test:syntax_tests": "./vendor/bin/php-cs-fixer fix ./tests --dry-run --stop-on-violation"
},
"require": {
"php": ">=8.2",
Expand All @@ -44,7 +44,7 @@
"require-dev": {
"phpunit/phpunit": "^11.5.46|^12.5.2",
"phpstan/phpstan": "^2.1.33",
"friendsofphp/php-cs-fixer": "^v3.91.3",
"friendsofphp/php-cs-fixer": "^v3.92.2",
"symfony/polyfill-iconv": "^1.33",
"phpstan/phpstan-strict-rules": "^2.0"
},
Expand Down
10 changes: 8 additions & 2 deletions src/ContentEncoding.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
<?php declare(strict_types=1);
/*
* This file is part of the WebPush library.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Minishlink\WebPush;

enum ContentEncoding: string
{
/** Not recommended. Outdated historic encoding. Was used by some browsers before rfc standard. */
case aesgcm = "aesgcm";
case aesgcm = 'aesgcm';
/** Defined in rfc8291. */
case aes128gcm = "aes128gcm";
case aes128gcm = 'aes128gcm';
}
11 changes: 5 additions & 6 deletions src/Encryption.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php declare(strict_types=1);

/*
* This file is part of the WebPush library.
*
Expand Down Expand Up @@ -38,7 +37,7 @@ public static function padPayload(string $payload, int $maxLengthToPad, ContentE
}

// @phpstan-ignore deadCode.unreachable
throw new \ErrorException("This content encoding is not implemented.");
throw new \ErrorException('This content encoding is not implemented.');
}

/**
Expand Down Expand Up @@ -146,7 +145,7 @@ public static function deterministicEncrypt(
public static function getContentCodingHeader(string $salt, string $localPublicKey, ContentEncoding $contentEncoding): string
{
if ($contentEncoding === ContentEncoding::aesgcm) {
return "";
return '';
}
if ($contentEncoding === ContentEncoding::aes128gcm) {
return $salt
Expand All @@ -156,7 +155,7 @@ public static function getContentCodingHeader(string $salt, string $localPublicK
}

// @phpstan-ignore deadCode.unreachable
throw new \ValueError("This content encoding is not implemented.");
throw new \ValueError('This content encoding is not implemented.');
}

/**
Expand Down Expand Up @@ -286,9 +285,9 @@ private static function getIKM(string $userAuthToken, string $userPublicKey, str
if ($contentEncoding === ContentEncoding::aesgcm) {
$info = 'Content-Encoding: auth'.chr(0);
} elseif ($contentEncoding === ContentEncoding::aes128gcm) {
$info = "WebPush: info".chr(0).$userPublicKey.$localPublicKey;
$info = 'WebPush: info'.chr(0).$userPublicKey.$localPublicKey;
} else {
throw new \ValueError("This content encoding is not implemented.");
throw new \ValueError('This content encoding is not implemented.');
}

return self::hkdf($userAuthToken, $sharedSecret, $info, 32);
Expand Down
11 changes: 7 additions & 4 deletions src/MessageSentReport.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php declare(strict_types=1);
/**
/*
* This file is part of the WebPush library.
*
* @author Igor Timoshenkov [it@campoint.net]
* @started: 03.09.2018 9:21
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Minishlink\WebPush;
Expand All @@ -19,8 +23,7 @@ public function __construct(
protected ?ResponseInterface $response = null,
protected bool $success = true,
protected string $reason = 'OK'
) {
}
) {}

public function isSuccess(): bool
{
Expand Down
8 changes: 2 additions & 6 deletions src/Notification.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php

declare(strict_types=1);

<?php declare(strict_types=1);
/*
* This file is part of the WebPush library.
*
Expand All @@ -24,8 +21,7 @@ public function __construct(
private ?string $payload,
private array $options,
private array $auth
) {
}
) {}

public function getSubscription(): SubscriptionInterface
{
Expand Down
5 changes: 1 addition & 4 deletions src/Subscription.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php

declare(strict_types=1);

<?php declare(strict_types=1);
/*
* This file is part of the WebPush library.
*
Expand Down
5 changes: 1 addition & 4 deletions src/SubscriptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php

declare(strict_types=1);

<?php declare(strict_types=1);
/*
* This file is part of the WebPush library.
*
Expand Down
9 changes: 3 additions & 6 deletions src/Utils.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php

declare(strict_types=1);

<?php declare(strict_types=1);
/*
* This file is part of the WebPush library.
*
Expand Down Expand Up @@ -82,8 +79,8 @@ public static function checkRequirementExtension(): void
}

// Check optional extensions.
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);
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 Down
5 changes: 1 addition & 4 deletions src/VAPID.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php

declare(strict_types=1);

<?php declare(strict_types=1);
/*
* This file is part of the WebPush library.
*
Expand Down
7 changes: 2 additions & 5 deletions src/WebPush.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
<?php

declare(strict_types=1);

<?php declare(strict_types=1);
/*
* This file is part of the WebPush library.
*
Expand Down Expand Up @@ -158,7 +155,7 @@ public function flush(?int $batchSize = null): \Generator
/** @var ResponseInterface $response **/
return new MessageSentReport($request, $response);
})
->otherwise(fn ($reason) => $this->createRejectedReport($reason));
->otherwise(fn($reason) => $this->createRejectedReport($reason));
}

foreach ($promises as $promise) {
Expand Down
8 changes: 6 additions & 2 deletions tests/MessageSentReportTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php declare(strict_types=1);
/**
/*
* This file is part of the WebPush library.
*
* @author Igor Timoshenkov [it@campoint.net]
* @started: 2018-12-03 11:31
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use GuzzleHttp\Psr7\Request;
Expand Down
4 changes: 2 additions & 2 deletions tests/PushServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ protected function createClosureTest($browserId, $options): callable
$this->assertTrue($report->isSuccess());

$dataString = json_encode([
'clientHash' => $clientHash,
], JSON_THROW_ON_ERROR);
'clientHash' => $clientHash,
], JSON_THROW_ON_ERROR);

$getNotificationCurl = curl_init(self::$testServiceUrl.'/get-notifications');
curl_setopt_array($getNotificationCurl, [
Expand Down
Loading